* [PATCH] crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path
@ 2026-02-21 19:04 Thorsten Blum
2026-03-14 4:17 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-02-21 19:04 UTC (permalink / raw)
To: Lothar Rubusch, Herbert Xu, David S. Miller, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Linus Walleij, Ard Biesheuvel
Cc: Thorsten Blum, stable, linux-crypto, linux-arm-kernel,
linux-kernel
Do not return early from atmel_sha204a_remove() when the device is busy.
Instead, flush the I2C workqueue before teardown to prevent a potential
UAF if a queued callback runs while the device is being removed.
Also ensure sysfs entries are removed and ->hwrng.priv is freed, to
prevent a memory leak during removal. Change the log level from emerg
to warn because the system is still usable.
Fixes: da001fb651b0 ("crypto: atmel-i2c - add support for SHA204A random number generator")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Compile-tested only.
---
drivers/crypto/atmel-sha204a.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
index 0fcf4a39de27..3afad915aae3 100644
--- a/drivers/crypto/atmel-sha204a.c
+++ b/drivers/crypto/atmel-sha204a.c
@@ -190,10 +190,10 @@ static void atmel_sha204a_remove(struct i2c_client *client)
{
struct atmel_i2c_client_priv *i2c_priv = i2c_get_clientdata(client);
- if (atomic_read(&i2c_priv->tfm_count)) {
- dev_emerg(&client->dev, "Device is busy, will remove it anyhow\n");
- return;
- }
+ if (atomic_read(&i2c_priv->tfm_count))
+ dev_warn(&client->dev, "Device is busy, will remove it anyhow\n");
+
+ atmel_i2c_flush_queue();
sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path
2026-02-21 19:04 [PATCH] crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path Thorsten Blum
@ 2026-03-14 4:17 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-03-14 4:17 UTC (permalink / raw)
To: Thorsten Blum
Cc: Lothar Rubusch, David S. Miller, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Linus Walleij, Ard Biesheuvel, stable,
linux-crypto, linux-arm-kernel, linux-kernel
On Sat, Feb 21, 2026 at 08:04:25PM +0100, Thorsten Blum wrote:
>
> diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
> index 0fcf4a39de27..3afad915aae3 100644
> --- a/drivers/crypto/atmel-sha204a.c
> +++ b/drivers/crypto/atmel-sha204a.c
> @@ -190,10 +190,10 @@ static void atmel_sha204a_remove(struct i2c_client *client)
> {
> struct atmel_i2c_client_priv *i2c_priv = i2c_get_clientdata(client);
>
> - if (atomic_read(&i2c_priv->tfm_count)) {
> - dev_emerg(&client->dev, "Device is busy, will remove it anyhow\n");
> - return;
> - }
> + if (atomic_read(&i2c_priv->tfm_count))
> + dev_warn(&client->dev, "Device is busy, will remove it anyhow\n");
> +
> + atmel_i2c_flush_queue();
How about only checking tfm_count after flushing the queue?
Removing a device that's in use isn't really something that should
trigger a kernel warning, unless it leads to an unrecovereable
problem.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-14 4:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-21 19:04 [PATCH] crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path Thorsten Blum
2026-03-14 4:17 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox