mirror of
https://github.com/torvalds/linux.git
synced 2026-06-06 21:45:45 +02:00
i2c: Fix a potential use after free
[ Upstream commite4c72c06c3] Free the adap structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free. Fixes:611e12ea0f("i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter") Signed-off-by: Xu Wang <vulab@iscas.ac.cn> [wsa: added comment to the code, added Fixes tag] Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
d0412d8f69
commit
81cb317568
|
|
@ -2405,8 +2405,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
|
||||||
if (!adap)
|
if (!adap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
put_device(&adap->dev);
|
|
||||||
module_put(adap->owner);
|
module_put(adap->owner);
|
||||||
|
/* Should be last, otherwise we risk use-after-free with 'adap' */
|
||||||
|
put_device(&adap->dev);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(i2c_put_adapter);
|
EXPORT_SYMBOL(i2c_put_adapter);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user