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

From: Manos Pitsidianakis

Date: Fri Jun 05 2026 - 05:32:21 EST


Hi Herbert,

On Fri, 05 Jun 2026 11:34, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
On Mon, May 25, 2026 at 10:25:39AM +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.

Signed-off-by: Manos Pitsidianakis <manos@xxxxxxxxxxxxxx>
---
drivers/char/hw_random/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Good catch!

Please add a Fixes header for this:

Fixes: 2bbb6983887f ("hwrng: use rng source with best quality")

Would this patch go through your maintainer tree?

If yes, you could add it along with your r-b directly, otherwise I can send a new revision when it gets a review.

Thanks,
Manos