Skip to contentSkip to conversation

net: nfs: fix buffer overflow in nfs_readlink_reply()

PATCH In review Sebastian Alba Vives 2 participants 3 messages Apr 9 – Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: nfs: fix buffer overflow in nfs_readlink_reply()

From: Sebastian Josue Alba Vives <[email protected]>

nfs_readlink_reply() validates rlen only against the incoming packet length (inherited from CVE-2019-14195), but not against the destination buffer nfs_path_buff[2048]. A malicious NFS server can send a valid READLINK reply where pathlen + rlen exceeds sizeof(nfs_path_buff), overflowing the BSS buffer into adjacent memory.

The recent fix in fd6e3d34097f addressed the same overflow class in net/lwip/nfs.c but left the legacy path in net/nfs-common.c unpatched.

Add bounds checks before both memcpy calls in nfs_readlink_reply():
- relative path branch: reject if pathlen + rlen >= sizeof(nfs_path_buff)
- absolute path branch: reject if rlen >= sizeof(nfs_path_buff)

Fixes cf3a4f1e86 ("net: nfs: Fix CVE-2019-14195")
---
 net/nfs-common.c | 4 ++++
 1 file changed, 4 insertions(+)
net/nfs-common.c +4 -0
index 4fbde67a..72d8fd82 100644
@@ -674,11 +674,15 @@ static int nfs_readlink_reply(uchar *pkt, unsigned int len)
 
 		strcat(nfs_path, "/");
 		pathlen = strlen(nfs_path);
+		if (pathlen + rlen >= sizeof(nfs_path_buff))
+			return -NFS_RPC_DROP;
 		memcpy(nfs_path + pathlen,
 		       (uchar *)&rpc_pkt.u.reply.data[2 + nfsv3_data_offset],
 		       rlen);
 		nfs_path[pathlen + rlen] = 0;
 	} else {
+		if (rlen >= sizeof(nfs_path_buff))
+			return -NFS_RPC_DROP;
 		memcpy(nfs_path,
 		       (uchar *)&rpc_pkt.u.reply.data[2 + nfsv3_data_offset],
 		       rlen);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Sebastian Alba Vives

From: Sebastian Josue Alba Vives <[email protected]>

nfs_readlink_reply() validates rlen only against the incoming packet length (inherited from CVE-2019-14195), but not against the destination buffer nfs_path_buff[2048]. A malicious NFS server can send a valid READLINK reply where pathlen + rlen exceeds sizeof(nfs_path_buff), overflowing the BSS buffer into adjacent memory.

The recent fix in fd6e3d34097f addressed the same overflow class in net/lwip/nfs.c but left the legacy path in net/nfs-common.c unpatched.

Add bounds checks before both memcpy calls in nfs_readlink_reply():
- relative path branch: reject if pathlen + rlen >= sizeof(nfs_path_buff)
- absolute path branch: reject if rlen >= sizeof(nfs_path_buff)

Fixes cf3a4f1e86 ("net: nfs: Fix CVE-2019-14195")
---
 net/nfs-common.c | 4 ++++
 1 file changed, 4 insertions(+)
net/nfs-common.c +2 -0
index 4fbde67a..72d8fd82 100644
@@ -674,11 +674,15 @@ static int nfs_readlink_reply(uchar *pkt, unsigned int len)
 
 		strcat(nfs_path, "/");
 		pathlen = strlen(nfs_path);
+		if (pathlen + rlen >= sizeof(nfs_path_buff))
+			return -NFS_RPC_DROP;

net/nfs-common.c static int nfs_readlink_reply(uchar *pkt, unsigned int len) · line 688

Quoted 10 lines
net/nfs-common.c +2 -0
 		memcpy(nfs_path + pathlen,
 		       (uchar *)&rpc_pkt.u.reply.data[2 + nfsv3_data_offset],
 		       rlen);
 		nfs_path[pathlen + rlen] = 0;
 	} else {
+		if (rlen >= sizeof(nfs_path_buff))
+			return -NFS_RPC_DROP;
 		memcpy(nfs_path,
 		       (uchar *)&rpc_pkt.u.reply.data[2 + nfsv3_data_offset],
 		       rlen);

Added to my net queue, thanks!

Signature · 1 line
Jerome
#2 lore raw

Hi Jerome,

Thank you for the review and for adding the patch to your net queue!

Regarding CVE assignment: the GitHub mirror does not have Security Advisories enabled, and Tom indicated the submitter should request one. Would it be possible for you or the U-Boot project to request a CVE through your CNA channel (ARM/Linaro or otherwise)?

Thanks again.

Best regards,
Sebastián Alba Vives

Quoted 54 lines · Jerome Forissier

net/nfs-common.c static int nfs_readlink_reply(uchar *pkt, unsigned

Quoted 27 lines · Sebastian Alba Vives

From: Sebastian Josue Alba Vives <[email protected]>

nfs_readlink_reply() validates rlen only against the incoming packet length (inherited from CVE-2019-14195), but not against the destination buffer nfs_path_buff[2048]. A malicious NFS server can send a valid READLINK reply where pathlen + rlen exceeds sizeof(nfs_path_buff), overflowing the BSS buffer into adjacent memory.

The recent fix in fd6e3d34097f addressed the same overflow class in net/lwip/nfs.c but left the legacy path in net/nfs-common.c unpatched.

Add bounds checks before both memcpy calls in nfs_readlink_reply():
- relative path branch: reject if pathlen + rlen >= sizeof(nfs_path_buff)
- absolute path branch: reject if rlen >= sizeof(nfs_path_buff)

Fixes cf3a4f1e86 ("net: nfs: Fix CVE-2019-14195")
---
 net/nfs-common.c | 4 ++++
 1 file changed, 4 insertions(+)
net/nfs-common.c +0 -0
index 4fbde67a..72d8fd82 100644
@@ -674,11 +674,15 @@ static int nfs_readlink_reply(uchar *pkt, unsigned

int len)

net/nfs-common.c static int nfs_readlink_reply(uchar *pkt, unsigned int len)

Quoted 7 lines
net/nfs-common.c +2 -0
              strcat(nfs_path, "/");
              pathlen = strlen(nfs_path);
+             if (pathlen + rlen >= sizeof(nfs_path_buff))
+                     return -NFS_RPC_DROP;
              memcpy(nfs_path + pathlen,
                     (uchar *)&rpc_pkt.u.reply.data[2 +

nfsv3_data_offset],

net/nfs-common.c static int nfs_readlink_reply(uchar *pkt, unsigned int len)

Quoted 7 lines
net/nfs-common.c +2 -0
                     rlen);
              nfs_path[pathlen + rlen] = 0;
      } else {
+             if (rlen >= sizeof(nfs_path_buff))
+                     return -NFS_RPC_DROP;
              memcpy(nfs_path,
                     (uchar *)&rpc_pkt.u.reply.data[2 +

nfsv3_data_offset],

net/nfs-common.c static int nfs_readlink_reply(uchar *pkt, unsigned · line 687

Quoted 1 line
net/nfs-common.c +0 -0
                     rlen);

Added to my net queue, thanks!

--
Jerome

Signature · 1 line
Sebastián Alba