Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=fc50d58fd053862d6bafcf92f1ef2961296f3a1c
Commit:     fc50d58fd053862d6bafcf92f1ef2961296f3a1c
Parent:     4d81cd16112f86dc279d90ef7a24f2b1be339c3c
Author:     Chuck Lever <[EMAIL PROTECTED]>
AuthorDate: Sun Jul 1 12:12:46 2007 -0400
Committer:  Trond Myklebust <[EMAIL PROTECTED]>
CommitDate: Tue Jul 10 23:40:44 2007 -0400

    NFS: Clean-up: Refactor IP address sanity checks in NFS client
    
    NFS and NFSv4 mounts can now share server address sanity checking.  And, it
    provides an easy mechanism for adding IPv6 address checking at some later
    point.
    
    Signed-off-by: Chuck Lever <[EMAIL PROTECTED]>
    Cc: Aurelien Charbon <[EMAIL PROTECTED]>
    Signed-off-by: Trond Myklebust <[EMAIL PROTECTED]>
---
 fs/nfs/super.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 6eac5bf..7f5bc28 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -447,6 +447,23 @@ static void nfs_umount_begin(struct vfsmount *vfsmnt, int 
flags)
 }
 
 /*
+ * Sanity-check a server address provided by the mount command
+ */
+static int nfs_verify_server_address(struct sockaddr *addr)
+{
+       switch (addr->sa_family) {
+       case AF_INET: {
+               struct sockaddr_in *sa = (struct sockaddr_in *) addr;
+               if (sa->sin_addr.s_addr != INADDR_ANY)
+                       return 1;
+               break;
+       }
+       }
+
+       return 0;
+}
+
+/*
  * Validate the NFS2/NFS3 mount data
  * - fills in the mount root filehandle
  */
@@ -501,7 +518,7 @@ static int nfs_validate_mount_data(struct nfs_mount_data 
*data,
 #endif /* CONFIG_NFS_V3 */
 
        /* We now require that the mount process passes the remote address */
-       if (data->addr.sin_addr.s_addr == INADDR_ANY) {
+       if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) {
                dprintk("%s: mount program didn't pass remote address!\n",
                        __FUNCTION__);
                return -EINVAL;
@@ -819,13 +836,12 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
        if (copy_from_user(&addr, data->host_addr, sizeof(addr)))
                return -EFAULT;
 
-       if (addr.sin_family != AF_INET ||
-           addr.sin_addr.s_addr == INADDR_ANY
-           ) {
+       if (!nfs_verify_server_address((struct sockaddr *) &addr)) {
                dprintk("%s: mount program didn't pass remote IP address!\n",
                                __FUNCTION__);
                return -EINVAL;
        }
+
        /* RFC3530: The default port for NFS is 2049 */
        if (addr.sin_port == 0)
                addr.sin_port = htons(NFS_PORT);
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to