crypto: drbg: check blocklen is non zero
PATCH 1/1 crypto: drbg: check blocklen is non zero
From: Tom Rix <[email protected]>
Clang static analysis reports this error
crypto/drbg.c:441:40: warning: Division by zero
padlen = (inputlen + sizeof(L_N) + 1) % (drbg_blocklen(drbg));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~When drbg_bocklen fails it returns 0.
if (drbg && drbg->core) return drbg->core->blocklen_bytes; return 0;
In many places in drbg_ctr_df drbg_bocklen is assumed to be non zero. So turn the assumption into a check.
--- crypto/drbg.c | 3 +++ 1 file changed, 3 insertions(+)
crypto/drbg.c +3 -0
@@ -420,6 +420,9 @@ static int drbg_ctr_df(struct drbg_state *drbg,size_t inputlen =0 ;struct drbg_string *seed =NULL ; +if (!drbg_blocklen (drbg)) +return -EINVAL ; +memset (pad,0 ,drbg_blocklen (drbg));memset (iv,0 ,drbg_blocklen (drbg));
Signature · 1 line
2.18.1
Am Sonntag, 2. August 2020, 19:12:47 CEST schrieb [email protected]:
Hi Tom,
Quoted 14 lines
From: Tom Rix <[email protected]>
Clang static analysis reports this error
crypto/drbg.c:441:40: warning: Division by zeropadlen = (inputlen + sizeof(L_N) + 1) % (drbg_blocklen(drbg)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~When
drbg_bocklenfails it returns 0.if (drbg && drbg->core) return drbg->core->blocklen_bytes; return 0;
Quoted 7 lines
In many places in
drbg_ctr_dfdrbg_bocklenis assumed to be non zero. So turn the assumption into a check.Fixes 541af946fe13 ("crypto: drbg - SP800-90A Deterministic Random BitGenerator")
Signed-off-by Tom Rix <[email protected]>
Thank you.
Ciao
Stephan
Herbert Xu
maintainerQuoted 5 lines · On Sun, Aug 02, 2020 at 10:12:47AM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang static analysis reports this error
crypto/drbg.c:441:40: warning: Division by zero
Quoted 8 lines
padlen = (inputlen + sizeof(L_N) + 1) % (drbg_blocklen(drbg)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~When
drbg_bocklenfails it returns 0.if (drbg && drbg->core) return drbg->core->blocklen_bytes; return 0;
Yes but it can only fail if the drbg is not instantiated. If you're hitting the generate path with an uninstantiated drbg you've got bigger problems than a divide by zero.
So how is this even possible?
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
There are many divide by 0 reports. This one got attention because it is in crypto, where i believe problems, even false positives, should be fixed.
Tom
Quoted 21 lines · Herbert Xu
Quoted 5 lines · On Sun, Aug 02, 2020 at 10:12:47AM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
Clang static analysis reports this error
crypto/drbg.c:441:40: warning: Division by zeroQuoted 8 lines
padlen = (inputlen + sizeof(L_N) + 1) % (drbg_blocklen(drbg)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~When
drbg_bocklenfails it returns 0.if (drbg && drbg->core) return drbg->core->blocklen_bytes; return 0;Yes but it can only fail if the drbg is not instantiated. If you're hitting the generate path with an uninstantiated drbg you've got bigger problems than a divide by zero.
So how is this even possible?
Cheers,
Herbert Xu
maintainerQuoted 1 line · Tom Rix
There are many divide by 0 reports. This one got attention because it is in crypto, where i believe problems, even false positives, should be fixed.
Please don't top post.
AS your bug report is a false positive I'm rejecting your patch.
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