Skip to contentSkip to conversation

crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path

PATCH Superseded Thorsten Blum 2 participants 2 messages Feb 21 – Mar 14

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: atmel-sha204a - Fix potential UAF and memory leak in remove path

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")

---
Compile-tested only.

---
 drivers/crypto/atmel-sha204a.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/atmel-sha204a.c +4 -4
index 0fcf4a39de27..3afad915aae3 100644
@@ -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);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer
#1 lore raw
Quoted 7 lines · Thorsten Blum
drivers/crypto/atmel-sha204a.c +0 -0
index 0fcf4a39de27..3afad915aae3 100644
@@ -190,10 +190,10 @@ static void atmel_sha204a_remove(struct i2c_client *client)
 {

drivers/crypto/atmel-sha204a.c static void atmel_sha204a_remove(struct i2c_client *client) · line 196

Quoted 10 lines
drivers/crypto/atmel-sha204a.c +4 -4
 	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,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt