summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXu Wang <vulab@iscas.ac.cn>2019-12-27 09:34:32 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-08-25 11:15:04 +0200
commit23a191b132cd87f746c62f3dc27da33683d85829 (patch)
tree33ff4e18540111e428c9192a897042b24533ebf0
parent1bd7f9784d3bbf74129756a7e90bcb4b3a7b1e89 (diff)
downloadlinux-stable-23a191b132cd87f746c62f3dc27da33683d85829.tar.gz
linux-stable-23a191b132cd87f746c62f3dc27da33683d85829.tar.bz2
linux-stable-23a191b132cd87f746c62f3dc27da33683d85829.zip
i2c: Fix a potential use after free
[ Upstream commit e4c72c06c367758a14f227c847f9d623f1994ecf ] 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 <vulab@iscas.ac.cn> [wsa: added comment to the code, added Fixes tag] Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/i2c/i2c-core-base.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 2a43f4e46af0..9079be0d51d1 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2273,8 +2273,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);