From ef9855cc5548b7b8cf6ac8897307896d80d12489 Mon Sep 17 00:00:00 2001 From: Pratham Patel Date: Sun, 27 Jul 2025 13:53:03 +0530 Subject: [PATCH] i2c: Fix a potential use after free jira VULN-1497 cve CVE-2019-25162 commit-author Xu Wang commit e4c72c06c367758a14f227c847f9d623f1994ecf 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 91ed53491f4f ("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: 611e12ea0f12 ("i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter") Signed-off-by: Xu Wang [wsa: added comment to the code, added Fixes tag] Signed-off-by: Wolfram Sang (cherry picked from commit e4c72c06c367758a14f227c847f9d623f1994ecf) Signed-off-by: Pratham Patel --- drivers/i2c/i2c-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 976b7c602d364..561bb830c4a9c 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -2775,8 +2775,9 @@ void i2c_put_adapter(struct i2c_adapter *adap) if (!adap) return; - put_device(&adap->dev); module_put(adap->owner); + /* Should be last, otherwise we risk use-after-free with 'adap' */ + put_device(&adap->dev); } EXPORT_SYMBOL(i2c_put_adapter);