Skip to content

Commit d93daad

Browse files
i2c: Fix a potential use after free
jira VULN-1497 cve CVE-2019-25162 commit-author Xu Wang <[email protected]> commit e4c72c0 upstream-diff There was a merge conflict because the file drivers/i2c/i2c-core.c was renamed to drivers/i2c/i2c-core-base.c in 91ed534 ("i2c: rename core source file to allow refactorization"). 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 0b3fae6 commit d93daad

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/i2c/i2c-core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,8 +2775,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
27752775
if (!adap)
27762776
return;
27772777

2778-
put_device(&adap->dev);
27792778
module_put(adap->owner);
2779+
/* Should be last, otherwise we risk use-after-free with 'adap' */
2780+
put_device(&adap->dev);
27802781
}
27812782
EXPORT_SYMBOL(i2c_put_adapter);
27822783

0 commit comments

Comments
 (0)