NFSD: If port value written to /proc/fs/nfsd/portlist is invalid, return EINVAL
authorChuck Lever <chuck.lever@oracle.com>
Thu, 19 Mar 2009 00:45:51 +0000 (20:45 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Sat, 28 Mar 2009 19:53:42 +0000 (15:53 -0400)
Make sure port value read from user space by write_ports is valid before
passing it to svc_find_xprt().  If it wasn't, the writer would get ENOENT
instead of EINVAL.

Noticed-by: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfsd/nfsctl.c

index 3d93b2064ce5e83b4e8d8672a84684414daf9e65..5a936c14f6ff4ab4150b9a9f6696d91d85fc3387 100644 (file)
@@ -938,6 +938,8 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size)
                char transport[16];
                int port;
                if (sscanf(buf, "%15s %4d", transport, &port) == 2) {
+                       if (port < 1 || port > 65535)
+                               return -EINVAL;
                        err = nfsd_create_serv();
                        if (!err) {
                                err = svc_create_xprt(nfsd_serv,
@@ -960,7 +962,7 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size)
                char transport[16];
                int port;
                if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) {
-                       if (port == 0)
+                       if (port < 1 || port > 65535)
                                return -EINVAL;
                        if (nfsd_serv) {
                                xprt = svc_find_xprt(nfsd_serv, transport,