]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path
authorThorsten Blum <thorsten.blum@linux.dev>
Sat, 14 Mar 2026 19:36:29 +0000 (20:36 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 22 Mar 2026 02:17:59 +0000 (11:17 +0900)
Unregister the hwrng to prevent new ->read() calls and flush the Atmel
I2C workqueue before teardown to prevent a potential UAF if a queued
callback runs while the device is being removed.

Drop the early return to ensure sysfs entries are removed and
->hwrng.priv is freed, preventing a memory leak.

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/atmel-sha204a.c

index 691531647fd65698d39a9419b7fe739a449e3436..dbb39ed0cea114f6554833b7b77dbcc67091677f 100644 (file)
@@ -194,10 +194,8 @@ 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;
-       }
+       devm_hwrng_unregister(&client->dev, &i2c_priv->hwrng);
+       atmel_i2c_flush_queue();
 
        sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);