]> www.infradead.org Git - users/jedix/linux-maple.git/commit
NFSD: harden svcxdr_dupstr() and svcxdr_tmpalloc() against integer overflows
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 9 May 2024 10:48:28 +0000 (13:48 +0300)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 8 Jul 2024 18:10:01 +0000 (14:10 -0400)
commitdbc834e5db447bcc5d77fa76a46897c4f206a5a4
tree6852021d0fd8dacb1e5b5953b12a8f0ce5269a13
parent256abd8e550ce977b728be79a74e1729438b4948
NFSD: harden svcxdr_dupstr() and svcxdr_tmpalloc() against integer overflows

These lengths come from xdr_stream_decode_u32() and so we should be a
bit careful with them.  Use size_add() and struct_size() to avoid
integer overflows.  Saving size_add()/struct_size() results to a u32 is
unsafe because it truncates away the high bits.

Also generally storing sizes in longs is safer.  Most systems these days
use 64 bit CPUs.  It's harder for an addition to overflow 64 bits than
it is to overflow 32 bits.  Also functions like vmalloc() can
successfully allocate UINT_MAX bytes, but nothing can allocate ULONG_MAX
bytes.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4xdr.c