Skip to contentSkip to conversation

nfs: Avoid overrun when copying client IP address string

PATCH Trond Myklebust 2 participants 2 messages Oct 4, 2009 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 13 lines · Ben Hutchings

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().

---

fs/nfs/client.c +0 -0
index 75c9cd2..f525a2f 100644

fs/nfs/client.c static int nfs4_init_client(struct nfs_client *clp, · line 1079

Quoted 8 lines
fs/nfs/client.c +1 -1
@@ -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) {

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

Thanks!

Trond

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
#3 lore raw

Re: Bug#549002: [PATCH] nfs: Avoid overrun when copying client IP address string

In reply to a message not in the archive
Quoted 20 lines · Trond Myklebust
Quoted 19 lines · Ben Hutchings

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().

---

fs/nfs/client.c +1 -1
index 75c9cd2..f525a2f 100644
@@ -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));
 
Quoted 5 lines

fs/nfs/client.c static int nfs4_init_client(struct nfs_client *clp, · line 1079

Quoted 2 lines
fs/nfs/client.c +0 -0
 	error = nfs_idmap_new(clp);
 	if (error < 0) {

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

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.

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