NFS: Clean-up: Refactor IP address sanity checks in NFS client
Subsystems (2)
PATCH 7/21 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]>
---
fs/nfs/super.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-)
fs/nfs/super.c +20 -4
@@ -448,6 +448,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 */
@@ -502,7 +519,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 ;
@@ -870,13 +887,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 );
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs