* [patch] i2c: dev: use after free in detach
@ 2016-05-28 5:01 Dan Carpenter
2016-05-28 8:57 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-05-28 5:01 UTC (permalink / raw)
To: Wolfram Sang, Erico Nunes; +Cc: linux-i2c, kernel-janitors
The call to return_i2c_dev() frees "i2c_dev" so there is a use after
free when we call cdev_del(&i2c_dev->cdev).
Fixes: d6760b14d4a1 ('i2c: dev: switch from register_chrdev to cdev API')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 2562a45..3bf4f0d 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -592,9 +592,9 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
if (!i2c_dev) /* attach_adapter must have failed */
return 0;
+ cdev_del(&i2c_dev->cdev);
return_i2c_dev(i2c_dev);
device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
- cdev_del(&i2c_dev->cdev);
pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
return 0;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] i2c: dev: use after free in detach
2016-05-28 5:01 [patch] i2c: dev: use after free in detach Dan Carpenter
@ 2016-05-28 8:57 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2016-05-28 8:57 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Erico Nunes, linux-i2c, kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]
On Sat, May 28, 2016 at 08:01:46AM +0300, Dan Carpenter wrote:
> The call to return_i2c_dev() frees "i2c_dev" so there is a use after
> free when we call cdev_del(&i2c_dev->cdev).
>
> Fixes: d6760b14d4a1 ('i2c: dev: switch from register_chrdev to cdev API')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks! I'll revert the offending commit nonetheless because I still
want to understand first why it slipped through my test system. And then
we will try again with a better patch.
>
> diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
> index 2562a45..3bf4f0d 100644
> --- a/drivers/i2c/i2c-dev.c
> +++ b/drivers/i2c/i2c-dev.c
> @@ -592,9 +592,9 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
> if (!i2c_dev) /* attach_adapter must have failed */
> return 0;
>
> + cdev_del(&i2c_dev->cdev);
> return_i2c_dev(i2c_dev);
> device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
> - cdev_del(&i2c_dev->cdev);
>
> pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
> return 0;
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-28 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-28 5:01 [patch] i2c: dev: use after free in detach Dan Carpenter
2016-05-28 8:57 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).