* [PATCH] hwrng: core - reject unknown RNG names
@ 2026-09-24 21:21 Thorsten Blum
2026-09-25 10:00 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-09-24 21:21 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Thorsten Blum, Manos Pitsidianakis,
Andy Shevchenko, David Laight, Jonathan McDowell, Lianjie Wang,
Thomas Richard (TI),
PrasannaKumar Muralidharan
Cc: linux-crypto, linux-kernel
In rng_current_store(), err is 0 after successfully locking rng_mutex,
and if the requested RNG name cannot be found, the function reports
success even though the current RNG was not changed.
Set err = -ENODEV before searching the RNG list to reject unknown names.
Fixes: 142a27f0a731 ("hwrng: core - Reset user selected rng by writing "" to rng_current")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
drivers/char/hw_random/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 57eeefe90da9..1f9e31cdc7f0 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -376,6 +376,7 @@ static ssize_t rng_current_store(struct device *dev,
cur_rng_set_by_user = 1;
drop_current_rng();
} else {
+ err = -ENODEV;
list_for_each_entry(rng, &rng_list, list) {
if (sysfs_streq(rng->name, buf)) {
err = set_current_rng(rng);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] hwrng: core - reject unknown RNG names
2026-09-24 21:21 [PATCH] hwrng: core - reject unknown RNG names Thorsten Blum
@ 2026-09-25 10:00 ` Andy Shevchenko
2026-09-25 10:06 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-09-25 10:00 UTC (permalink / raw)
To: Thorsten Blum
Cc: Olivia Mackall, Herbert Xu, Manos Pitsidianakis, David Laight,
Jonathan McDowell, Lianjie Wang, Thomas Richard (TI),
PrasannaKumar Muralidharan, linux-crypto, linux-kernel
On Thu, Sep 24, 2026 at 11:21:13PM +0200, Thorsten Blum wrote:
> In rng_current_store(), err is 0 after successfully locking rng_mutex,
> and if the requested RNG name cannot be found, the function reports
> success even though the current RNG was not changed.
>
> Set err = -ENODEV before searching the RNG list to reject unknown names.
Yeah, from the
> Fixes: 142a27f0a731 ("hwrng: core - Reset user selected rng by writing "" to rng_current")
it looks like it was the intention, but the mutex_lock_interruptible() rewrites
an error code. That's a good example on why I often tell people to decouple
assignment from the definition and the very same issue might happen and would be
hard to debug later on. Surprisingly this happened in the same patch...
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] hwrng: core - reject unknown RNG names
2026-09-25 10:00 ` Andy Shevchenko
@ 2026-09-25 10:06 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-09-25 10:06 UTC (permalink / raw)
To: Thorsten Blum
Cc: Olivia Mackall, Herbert Xu, Manos Pitsidianakis, David Laight,
Jonathan McDowell, Lianjie Wang, Thomas Richard (TI),
PrasannaKumar Muralidharan, linux-crypto, linux-kernel
On Fri, Sep 25, 2026 at 01:00:39PM +0300, Andy Shevchenko wrote:
> On Thu, Sep 24, 2026 at 11:21:13PM +0200, Thorsten Blum wrote:
> > In rng_current_store(), err is 0 after successfully locking rng_mutex,
> > and if the requested RNG name cannot be found, the function reports
> > success even though the current RNG was not changed.
> >
> > Set err = -ENODEV before searching the RNG list to reject unknown names.
>
> Yeah, from the
>
> > Fixes: 142a27f0a731 ("hwrng: core - Reset user selected rng by writing "" to rng_current")
>
> it looks like it was the intention, but the mutex_lock_interruptible() rewrites
> an error code. That's a good example on why I often tell people to decouple
> assignment from the definition and the very same issue might happen and would be
> hard to debug later on. Surprisingly this happened in the same patch...
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Also
Fixes: cb028f1662a9 ("hwrng: core - remove redundant initialization of variable err")
as that one removed the indeed redundant assignment, but forget to fix the issue.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-25 10:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-24 21:21 [PATCH] hwrng: core - reject unknown RNG names Thorsten Blum
2026-09-25 10:00 ` Andy Shevchenko
2026-09-25 10:06 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®