aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/super.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2007-07-01 12:12:46 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2007-07-10 23:40:44 -0400
commitfc50d58fd053862d6bafcf92f1ef2961296f3a1c (patch)
treefa445db9d7a61fad98c74214e62094c69816a1ea /fs/nfs/super.c
parent4d81cd16112f86dc279d90ef7a24f2b1be339c3c (diff)
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 <chuck.lever@oracle.com> Cc: Aurelien Charbon <aurelien.charbon@ext.bull.net> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/super.c')
-rw-r--r--fs/nfs/super.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 6eac5bf911e3..7f5bc28ea8d1 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)
447} 447}
448 448
449/* 449/*
450 * Sanity-check a server address provided by the mount command
451 */
452static int nfs_verify_server_address(struct sockaddr *addr)
453{
454 switch (addr->sa_family) {
455 case AF_INET: {
456 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
457 if (sa->sin_addr.s_addr != INADDR_ANY)
458 return 1;
459 break;
460 }
461 }
462
463 return 0;
464}
465
466/*
450 * Validate the NFS2/NFS3 mount data 467 * Validate the NFS2/NFS3 mount data
451 * - fills in the mount root filehandle 468 * - fills in the mount root filehandle
452 */ 469 */
@@ -501,7 +518,7 @@ static int nfs_validate_mount_data(struct nfs_mount_data *data,
501#endif /* CONFIG_NFS_V3 */ 518#endif /* CONFIG_NFS_V3 */
502 519
503 /* We now require that the mount process passes the remote address */ 520 /* We now require that the mount process passes the remote address */
504 if (data->addr.sin_addr.s_addr == INADDR_ANY) { 521 if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) {
505 dprintk("%s: mount program didn't pass remote address!\n", 522 dprintk("%s: mount program didn't pass remote address!\n",
506 __FUNCTION__); 523 __FUNCTION__);
507 return -EINVAL; 524 return -EINVAL;
@@ -819,13 +836,12 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
819 if (copy_from_user(&addr, data->host_addr, sizeof(addr))) 836 if (copy_from_user(&addr, data->host_addr, sizeof(addr)))
820 return -EFAULT; 837 return -EFAULT;
821 838
822 if (addr.sin_family != AF_INET || 839 if (!nfs_verify_server_address((struct sockaddr *) &addr)) {
823 addr.sin_addr.s_addr == INADDR_ANY
824 ) {
825 dprintk("%s: mount program didn't pass remote IP address!\n", 840 dprintk("%s: mount program didn't pass remote IP address!\n",
826 __FUNCTION__); 841 __FUNCTION__);
827 return -EINVAL; 842 return -EINVAL;
828 } 843 }
844
829 /* RFC3530: The default port for NFS is 2049 */ 845 /* RFC3530: The default port for NFS is 2049 */
830 if (addr.sin_port == 0) 846 if (addr.sin_port == 0)
831 addr.sin_port = htons(NFS_PORT); 847 addr.sin_port = htons(NFS_PORT);