* [PATCH] i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource()
@ 2026-07-14 15:08 Xuanqiang Luo
2026-07-14 22:09 ` Andi Shyti
0 siblings, 1 reply; 2+ messages in thread
From: Xuanqiang Luo @ 2026-07-14 15:08 UTC (permalink / raw)
To: linux-i2c, andi.shyti
Cc: kblaiech, asmaa, vadimp, wsa, linux-kernel, Xuanqiang Luo, stable
From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
If devm_platform_get_and_ioremap_resource() returns an error,
mlxbf_i2c_init_resource() frees tmp_res before reading tmp_res->io to
get the error code. This results in a use-after-free.
Save the error code before freeing tmp_res.
Fixes: b5b5b32081cd ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
drivers/i2c/busses/i2c-mlxbf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c
index 6c1cfe9ec8ac..e33512b25353 100644
--- a/drivers/i2c/busses/i2c-mlxbf.c
+++ b/drivers/i2c/busses/i2c-mlxbf.c
@@ -1051,8 +1051,10 @@ static int mlxbf_i2c_init_resource(struct platform_device *pdev,
tmp_res->io = devm_platform_get_and_ioremap_resource(pdev, type, &tmp_res->params);
if (IS_ERR(tmp_res->io)) {
+ int ret = PTR_ERR(tmp_res->io);
+
devm_kfree(dev, tmp_res);
- return PTR_ERR(tmp_res->io);
+ return ret;
}
tmp_res->type = type;
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource()
2026-07-14 15:08 [PATCH] i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource() Xuanqiang Luo
@ 2026-07-14 22:09 ` Andi Shyti
0 siblings, 0 replies; 2+ messages in thread
From: Andi Shyti @ 2026-07-14 22:09 UTC (permalink / raw)
To: Xuanqiang Luo
Cc: linux-i2c, kblaiech, asmaa, vadimp, wsa, linux-kernel,
Xuanqiang Luo, stable
Hi Xuanqiang,
On Tue, Jul 14, 2026 at 11:08:08PM +0800, Xuanqiang Luo wrote:
> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
> If devm_platform_get_and_ioremap_resource() returns an error,
> mlxbf_i2c_init_resource() frees tmp_res before reading tmp_res->io to
> get the error code. This results in a use-after-free.
>
> Save the error code before freeing tmp_res.
>
> Fixes: b5b5b32081cd ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
merged to i2c/i2c-fixes.
Thanks,
Andi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-14 22:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-14 15:08 [PATCH] i2c: mlxbf: Fix use-after-free in mlxbf_i2c_init_resource() Xuanqiang Luo
2026-07-14 22:09 ` Andi Shyti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox