All of lore.kernel.org
 help / color / mirror / Atom feed
* Bug in atmel-ecc driver
@ 2022-05-13 13:59 ` Uwe Kleine-König
  0 siblings, 0 replies; 24+ messages in thread
From: Uwe Kleine-König @ 2022-05-13 13:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, linux-crypto,
	linux-arm-kernel, kernel, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 1416 bytes --]

Hello,

TL;DR: when a device bound to the drivers/crypto/atmel-ecc.c driver is
unbound while tfm_count isn't zero, this probably results in a
use-after-free.

The .remove function has:

	if (atomic_read(&i2c_priv->tfm_count)) {
                dev_err(&client->dev, "Device is busy\n");
                return -EBUSY;
        }

before actually calling the cleanup stuff. If this branch is hit the
result is likely:

 - "Device is busy" from drivers/crypto/atmel-ecc.c
 - "remove failed (EBUSY), will be ignored" from the i2c core
 - the devm cleanup callbacks are called, including the one kfreeing
   *i2c_priv
 - at a later time atmel_ecc_i2c_client_free() is called which does
   atomic_dec(&i2c_priv->tfm_count);
 - *boom*

I think to fix that you need to call get_device for the i2c device
before increasing tfm_count (and a matching put_device when decreasing
it). Having said that the architecture of this driver looks strange to
me, so there might be nicer fixes (probably with more effort).

I noticed this issue while working on my quest to make i2c-remove
callbacks return void. So if you address this, it would be great if you
did that in a way that makes atmel_ecc_remove always return 0. 

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-06-10  9:16 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 13:59 Bug in atmel-ecc driver Uwe Kleine-König
2022-05-13 13:59 ` Uwe Kleine-König
2022-05-17 10:24 ` Uwe Kleine-König
2022-05-17 10:24   ` Uwe Kleine-König
2022-05-17 13:11   ` Tudor.Ambarus
2022-05-17 13:11     ` Tudor.Ambarus
2022-05-17 14:33     ` Uwe Kleine-König
2022-05-17 14:33       ` Uwe Kleine-König
2022-05-18 10:07       ` Tudor.Ambarus
2022-05-18 10:07         ` Tudor.Ambarus
2022-05-18 21:36         ` Uwe Kleine-König
2022-05-18 21:36           ` Uwe Kleine-König
2022-05-20 17:21         ` [PATCH] crypto: atmel-ecc - Remove duplicated error reporting in .remove() Uwe Kleine-König
2022-05-20 17:21           ` Uwe Kleine-König
2022-06-07  6:48           ` Uwe Kleine-König
2022-06-07  6:48             ` Uwe Kleine-König
2022-06-08  4:33           ` Tudor.Ambarus
2022-06-08  4:33             ` Tudor.Ambarus
2022-06-08  7:04             ` Uwe Kleine-König
2022-06-08  7:04               ` Uwe Kleine-König
2022-06-08  8:35               ` Tudor.Ambarus
2022-06-08  8:35                 ` Tudor.Ambarus
2022-06-10  9:14           ` Herbert Xu
2022-06-10  9:14             ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.