Skip to content

Commit e4c72c0

Browse files
ISCAS-Vulabwsakernel
authored andcommitted
i2c: Fix a potential use after free
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: 611e12e ("i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter") Signed-off-by: Xu Wang <[email protected]> [wsa: added comment to the code, added Fixes tag] Signed-off-by: Wolfram Sang <[email protected]>
1 parent 4dc1372 commit e4c72c0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2461,8 +2461,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
24612461
if (!adap)
24622462
return;
24632463

2464-
put_device(&adap->dev);
24652464
module_put(adap->owner);
2465+
/* Should be last, otherwise we risk use-after-free with 'adap' */
2466+
put_device(&adap->dev);
24662467
}
24672468
EXPORT_SYMBOL(i2c_put_adapter);
24682469

0 commit comments

Comments
 (0)