On 2026-10-06T11:09:17, Prasad Kummari <[email protected]> wrote:
> rsa: reject zero-bit modulus in rsa_gen_key_prop()
>
> rsa_get_n() only rejects a zero-length INTEGER, so an all-zero
> modulus (e.g. a single 0x00 byte) is accepted and leaves num_bits
> at 0 after the leading-zero-stripping loop. With num_bits == 0, n
> is allocated as a single header word, so br_i32_ninv32(n[1]) reads
> one word past the end of n, and modulus is allocated via malloc(0).
>
> Reject num_bits == 0 with -EINVAL right after stripping the leading
> zeroes, before any of the buffers sized from it are allocated.
>
> Fixes: e0d310b098b1 ("lib: rsa: generate additional parameters for public 
> key")
> Suggested-by: Simon Glass <[email protected]>
> Signed-off-by: Prasad Kummari <[email protected]>
>
> lib/rsa/rsa-keyprop.c | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Simon Glass <[email protected]>

Reply via email to