Re: [PATCH v2] hw_random/core: fix rng list on registration error

From: Herbert Xu

Date: Sun Jul 05 2026 - 01:31:59 EST


On Fri, Jun 05, 2026 at 02:23:51PM +0300, Manos Pitsidianakis wrote:
> hwrng_register(rng) does the following:
>
> 1. Checks if rng has name and read methods set
> 2. Checks if the name already exists
> 3. Adds rng to global rng_list
> 4. May try to set rng to current_rng
>
> If step 4 fails, it returns an error. However, it does not remove the
> rng from rng_list, causing a dangling reference which can result in
> use-after-free if the caller frees rng, since registration failed.
>
> Add a list_del_init() cleanup step.
>
> Fixes: 2bbb6983887f ("hwrng: use rng source with best quality")
> Signed-off-by: Manos Pitsidianakis <manos@xxxxxxxxxxxxxx>
> ---
> Changes in v2:
> - Add Fixes: trailer
> - Link to v1: https://lore.kernel.org/r/20260525-hw_random_registration_rng_list-v1-1-ee1c215d544d@xxxxxxxxxxxxxx
> ---
> drivers/char/hw_random/core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt