Subject: [PATCH] nfs: Avoid overrun when copying client IP address string

From: Ben Hutchings <[email-masked]>
Date: Sun, 04 Oct 2009 14:25:49 +0100

As seen in <http://bugs.debian.org/549002>, nfs4_init_client() can
overrun the source string when copying the client IP address from
nfs_parsed_mount_data::client_address to nfs_client::cl_ipaddr.  Since
these are both treated as null-terminated strings elsewhere, the copy
should be done with strlcpy() not memcpy().

Signed-off-by: Ben Hutchings <[email-masked]>
---
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 75c9cd2..f525a2f 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1073,7 +1073,7 @@ static int nfs4_init_client(struct nfs_client *clp,
 				      1, flags & NFS_MOUNT_NORESVPORT);
 	if (error < 0)
 		goto error;
-	memcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
+	strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
 
 	error = nfs_idmap_new(clp);
 	if (error < 0) {

-- 
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.

---

From: Trond Myklebust <[email-masked]>
Date: Sun, 04 Oct 2009 18:33:16 -0400

>  	error = nfs_idmap_new(clp);

It looks good, so I'll push it upstream. I assume the bug report also
applies to [email-masked]?

Thanks!

  Trond
-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
[email-masked]
www.netapp.com

---

From: Ben Hutchings <[email-masked]>
Date: Mon, 05 Oct 2009 00:24:48 +0100

> applies to [email-masked]?

This bug appears to have been present "forever", though I think it has
become a practical problem since nfs_client::cl_ipaddr was enlarged to
48 bytes in v2.6.25.  So yes, the bug and fix are applicable to every
stable series.

Ben.