Skip to contentSkip to conversation

net: lwip: nfs: fix buffer overflow when using symlinks

PATCH Superseded Pranav Tilak 2 participants 2 messages Mar 18 – Mar 23 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: lwip: nfs: fix buffer overflow when using symlinks

When resolving a symlink, nfs_path points into a heap allocated buffer which is just large enough to hold the original path with no extra space. If the symlink target name is longer than the original filename, the write goes beyond the end of the buffer corrupting heap memory.

Fix this by ensuring nfs_path always points to a buffer large enough to accommodate the resolved symlink path.

Fixes 230cf3bc2776 ("net: lwip: nfs: Port the NFS code to work with lwIP")
---
 net/lwip/nfs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/lwip/nfs.c +5 -2
index c3b819a091e..b2e8fb3382d 100644
@@ -114,8 +114,11 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
 	if (!netif)
 		return -1;
 
-	nfs_filename = nfs_basename(fname);
-	nfs_path     = nfs_dirname(fname);
+	nfs_path = nfs_path_buff;
+	strlcpy(nfs_path_buff, fname, sizeof(nfs_path_buff));
+
+	nfs_filename = nfs_basename(nfs_path_buff);
+	nfs_path     = nfs_dirname(nfs_path_buff);
 
 	printf("Using %s device\n", udev->name);
 
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Pranav Tilak

When resolving a symlink, nfs_path points into a heap allocated buffer which is just large enough to hold the original path with no extra space. If the symlink target name is longer than the original filename, the write goes beyond the end of the buffer corrupting heap memory.

Fix this by ensuring nfs_path always points to a buffer large enough to accommodate the resolved symlink path.

Fixes 230cf3bc2776 ("net: lwip: nfs: Port the NFS code to work with lwIP")
---
 net/lwip/nfs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/lwip/nfs.c +0 -0
index c3b819a091e..b2e8fb3382d 100644

net/lwip/nfs.c static int nfs_loop(struct udevice *udev, ulong addr, char *fname, · line 117

Quoted 6 lines
net/lwip/nfs.c +1 -2
@@ -114,8 +114,11 @@ static int nfs_loop(struct udevice *udev, ulong addr, char *fname,
 	if (!netif)
 		return -1;
 
-	nfs_filename = nfs_basename(fname);
-	nfs_path     = nfs_dirname(fname);
+	nfs_path = nfs_path_buff;

This assignment is not needed.

net/lwip/nfs.c static int nfs_loop(struct udevice *udev, ulong addr, char *fname, · line 124

Quoted 7 lines
net/lwip/nfs.c +4 -0
+	strlcpy(nfs_path_buff, fname, sizeof(nfs_path_buff));
+
+	nfs_filename = nfs_basename(nfs_path_buff);
+	nfs_path     = nfs_dirname(nfs_path_buff);
 
 	printf("Using %s device\n", udev->name);
 

Other than that LGTM.

Thanks,

Signature · 1 line
Jerome