[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <90e0cc7f-1cad-bb1f-448f-673dcf25cb15@prevas.dk>
Date: Fri, 18 Nov 2022 09:49:15 +0100
From: Rasmus Villemoes <rasmus.villemoes@...vas.dk>
To: "Jason A. Donenfeld" <Jason@...c4.com>,
coverity-bot <keescook@...omium.org>
Cc: linux-kernel@...r.kernel.org, Theodore Ts'o <tytso@....edu>,
Dominik Brodowski <linux@...inikbrodowski.net>,
Olivia Mackall <olivia@...enic.com>,
linux-crypto@...r.kernel.org,
Herbert Xu <herbert@...dor.apana.org.au>,
"Gustavo A. R. Silva" <gustavo@...eddedor.com>,
linux-next@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: Coverity: add_early_randomness(): Integer handling issues
On 08/11/2022 18.31, Jason A. Donenfeld wrote:
> "If "bytes_read * 8 * rng->quality / 1024" is greater than 0x7FFFFFFF,
> the upper bits of the result will all be 1."
>
> Except "bytes_read" is an int. So false positive.
Well, the automated report could use a better wording, but just from the
types alone there's nothing preventing the "bytes_read * 8 *
rng->quality" expression from mathematically exceeding INT_MAX and thus
potentially becoming a negative value (so technically of course not
greater than 0x7FFFFFFF, but the point being that the sign bit is set),
and then the result of the division will most likely also be negative.
But what actually saves the day is that I suppose bytes_read cannot be
more than 32, so the multiplication is indeed at most 256*U16_MAX. Too
bad we don't have a __postcond(@ret < (int)size) attribute we could put
on functions like rng_get_data() to help static analysis.
Rasmus
Powered by blists - more mailing lists