crypto: nx - validate 'ignore' before subtracting in decompress
Subsystems (4)
PATCH 1/1 crypto: nx - validate 'ignore' before subtracting in decompress
The decompress() function subtracts the header-supplied ignore value (a u16 from the compressed stream) from dlen (the number of bytes produced by the decompressor) without checking that ignore <= dlen.
If a caller decompresses a crafted buffer where hdr->ignore exceeds the actual decompressed length, the subtraction wraps around to a near-UINT_MAX value. The subsequent memcpy() then copies gigabytes of data past the destination buffer, causing an out-of-bounds kernel write.
Add a bounds check before the subtraction and return -EINVAL if the value is inconsistent.
--- drivers/crypto/nx/nx-842.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/crypto/nx/nx-842.c +2 -0
@@ -421,6 +421,8 @@ slen -= spadding; +if (ignore > dlen) +return -EINVAL ; dlen -= ignore;if (ignore)pr_debug ("ignoring last %x bytes\n" , ignore);
Signature · 1 line
2.43.0
Herbert Xu
maintainerQuoted 9 lines · Aldo Ariel Panzardo
The
decompress()function subtracts the header-suppliedignorevalue (a u16 from the compressed stream) fromdlen(the number of bytes produced by the decompressor) without checking that ignore <= dlen.If a caller decompresses a crafted buffer where
hdr->ignoreexceeds the actual decompressed length, the subtraction wraps around to a near-UINT_MAX value. The subsequentmemcpy()then copies gigabytes of data past the destination buffer, causing an out-of-bounds kernel write.
Quoted 8 lines
Add a bounds check before the subtraction and return
-EINVALif the value is inconsistent.Signed-off-by Aldo Ariel Panzardo <[email protected]>--- drivers/crypto/nx/nx-842.c | 3 +++ 1 file changed, 3 insertions(+)
Thanks for the fix!
I think a bigger problem is that this hardware is accepting input that cannot be processed by the software fallback since it has no handling of NX842_CRYPTO_MAGIC.
The whole point of having the software implementation is to be able to decompress the output of the hardware.
I'm not sure who is maintaining this currently. Vishal, do we still need the 842 algorithm? Could we fix the software fallback so that it can handle the same input as the hardware driver?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerQuoted 9 lines · Aldo Ariel Panzardo
The
decompress()function subtracts the header-suppliedignorevalue (a u16 from the compressed stream) fromdlen(the number of bytes produced by the decompressor) without checking that ignore <= dlen.If a caller decompresses a crafted buffer where
hdr->ignoreexceeds the actual decompressed length, the subtraction wraps around to a near-UINT_MAX value. The subsequentmemcpy()then copies gigabytes of data past the destination buffer, causing an out-of-bounds kernel write.
Quoted 8 lines
Add a bounds check before the subtraction and return
-EINVALif the value is inconsistent.Signed-off-by Aldo Ariel Panzardo <[email protected]>--- drivers/crypto/nx/nx-842.c | 3 +++ 1 file changed, 3 insertions(+)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt