Skip to contentSkip to conversation

NFSD: prevent integer overflow on 32 bit systems

PATCH In review Dan Carpenter 3 participants 4 messages Mar 15, 2022

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

PATCH v2 1/1 NFSD: prevent integer overflow on 32 bit systems

On a 32 bit system, the "len * sizeof(*p)" operation can have an integer overflow.

c: [email protected]

---
v2: add stable to the CC. Use SIZE_MAX.

 include/linux/sunrpc/xdr.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/sunrpc/xdr.h +2 -0
index b519609af1d0..4417f667c757 100644
@@ -731,6 +731,8 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr,
 
 	if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
 		return -EBADMSG;
+	if (len > SIZE_MAX / sizeof(*p))
+		return -EBADMSG;
 	p = xdr_inline_decode(xdr, len * sizeof(*p));
 	if (unlikely(!p))
 		return -EBADMSG;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Dan Carpenter

On a 32 bit system, the "len * sizeof(*p)" operation can have an integer overflow.

c: [email protected]

Trond, this patch was To: me, but either you or I can take this. Please let me know your preference.

Quoted 22 lines

---
v2: add stable to the CC. Use SIZE_MAX.

include/linux/sunrpc/xdr.h | 2 ++

1 file changed, 2 insertions(+)
include/linux/sunrpc/xdr.h +2 -0
index b519609af1d0..4417f667c757 100644
@@ -731,6 +731,8 @@ xdr_stream_decode_uint32_array(struct xdr_stream *xdr,
 
 	if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
 		return -EBADMSG;
+	if (len > SIZE_MAX / sizeof(*p))
+		return -EBADMSG;
 	p = xdr_inline_decode(xdr, len * sizeof(*p));
 	if (unlikely(!p))
 		return -EBADMSG;
Signature · 1 line
2.20.1

--
Chuck Lever

#2 lore raw
Quoted 5 lines · Chuck Lever III
Quoted 5 lines

On Mar 15, 2022, at 11:34 AM, Dan Carpenter
<[email protected]> wrote:

Quoted 9 lines
Quoted 5 lines

On a 32 bit system, the "len * sizeof(*p)" operation can have an integer overflow.

c: [email protected]

Trond, this patch was To: me, but either you or I can take this. Please let me know your preference.

I don't mind either way. If you've got it applied already, then let's send it through your tree.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#3 lore raw
Quoted 16 lines · Trond Myklebust
Quoted 11 lines · Chuck Lever III
Quoted 10 lines

On Mar 15, 2022, at 11:34 AM, Dan Carpenter
<[email protected]> wrote:

On a 32 bit system, the "len * sizeof(*p)" operation can have an integer overflow.

c: [email protected]

Quoted 6 lines
Quoted 3 lines

Trond, this patch was To: me, but either you or I can take this. Please let me know your preference.

I don't mind either way. If you've got it applied already, then let's send it through your tree.

I've applied this one and "prevent underflow in nfssvc_decode_writeargs". Thanks, Trond and Dan!

--
Chuck Lever