Skip to content

Commit f85f16c

Browse files
i2c: Fix a potential use after free
jira VULN-33 cve CVE-2019-25162 commit-author Xu Wang <[email protected]> commit e4c72c0 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]> (cherry picked from commit e4c72c0) Signed-off-by: Pratham Patel <[email protected]>
1 parent 5808c66 commit f85f16c

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
@@ -2467,8 +2467,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
24672467
if (!adap)
24682468
return;
24692469

2470-
put_device(&adap->dev);
24712470
module_put(adap->owner);
2471+
/* Should be last, otherwise we risk use-after-free with 'adap' */
2472+
put_device(&adap->dev);
24722473
}
24732474
EXPORT_SYMBOL(i2c_put_adapter);
24742475

0 commit comments

Comments
 (0)