Skip to content

Commit 0e0e088

Browse files
i2c: Fix a potential use after free
jira VULN-28 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 a5f217e commit 0e0e088

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
@@ -2328,8 +2328,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
23282328
if (!adap)
23292329
return;
23302330

2331-
put_device(&adap->dev);
23322331
module_put(adap->owner);
2332+
/* Should be last, otherwise we risk use-after-free with 'adap' */
2333+
put_device(&adap->dev);
23332334
}
23342335
EXPORT_SYMBOL(i2c_put_adapter);
23352336

0 commit comments

Comments
 (0)