* [PATCH] ipmi:msghandler: Put the interface on the BMC changed retry
@ 2026-12-04 2:53 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang @ 2026-12-04 2:53 UTC (permalink / raw)
To: Corey Minyard; +Cc: openipmi-developer, linux-kernel, Anh Nguyen Hoang
When __bmc_get_device_id() is called without an interface, it takes a
reference on the first interface of the BMC. If the BMC's device id or
GUID has changed, it re-registers the BMC and jumps back to
retry_bmc_lock without dropping that reference, so the interface is
never freed. Drop the reference before retrying, as the other retry in
this function does.
Found by a static analysis tool.
Fixes: b2cfd8ab4add ("ipmi: Rework device id and guid handling to catch changing BMCs")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Runtime test: QEMU, x86_64 defconfig + IPMI_HANDLER + IPMI_SI +
KPROBE_EVENTS, on next-20261202 (its ipmi_msghandler.c is the same as
the one in ipmi for-next). A scripted BMC behind ipmi-bmc-extern changes
its product id while the guest runs. A read of ipmi_bmc.0/product_id by
uid 1000 then takes this retry. The interface is then removed through
the ipmi_si hotmod parameter, with kprobes on ipmi_unregister_smi() and
intf_free().
Before the patch: the refcount is 2 when entering ipmi_unregister_smi()
and intf_free() is never called.
After the patch: the refcount is 1 and intf_free() is called.
Same result with two KCS interfaces on one BMC. With an unchanged BMC,
both kernels free the interface.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/char/ipmi/ipmi_msghandler.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/char/ipmi/ipmi_msghandler.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 52e95e1949b9..f80d16dce449 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2770,6 +2770,7 @@ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
* the next interface for the BMC.
*/
mutex_unlock(&intf->bmc_reg_mutex);
+ kref_put(&intf->refcount, intf_free);
mutex_lock(&bmc->dyn_mutex);
goto retry_bmc_lock;
}
---
base-commit: 551bbbed906516e04956e4de0896fb8c1317ea86
change-id: 20261203-kbug-l1316-6fcc56d75287
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH] ipmi:msghandler: Put the interface on the BMC changed retry
@ 2026-12-04 2:53 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang via B4 Relay @ 2026-12-04 2:53 UTC (permalink / raw)
To: Corey Minyard; +Cc: openipmi-developer, linux-kernel, Anh Nguyen Hoang
From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
When __bmc_get_device_id() is called without an interface, it takes a
reference on the first interface of the BMC. If the BMC's device id or
GUID has changed, it re-registers the BMC and jumps back to
retry_bmc_lock without dropping that reference, so the interface is
never freed. Drop the reference before retrying, as the other retry in
this function does.
Found by a static analysis tool.
Fixes: b2cfd8ab4add ("ipmi: Rework device id and guid handling to catch changing BMCs")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Runtime test: QEMU, x86_64 defconfig + IPMI_HANDLER + IPMI_SI +
KPROBE_EVENTS, on next-20261202 (its ipmi_msghandler.c is the same as
the one in ipmi for-next). A scripted BMC behind ipmi-bmc-extern changes
its product id while the guest runs. A read of ipmi_bmc.0/product_id by
uid 1000 then takes this retry. The interface is then removed through
the ipmi_si hotmod parameter, with kprobes on ipmi_unregister_smi() and
intf_free().
Before the patch: the refcount is 2 when entering ipmi_unregister_smi()
and intf_free() is never called.
After the patch: the refcount is 1 and intf_free() is called.
Same result with two KCS interfaces on one BMC. With an unchanged BMC,
both kernels free the interface.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/char/ipmi/ipmi_msghandler.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/char/ipmi/ipmi_msghandler.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 52e95e1949b9..f80d16dce449 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2770,6 +2770,7 @@ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
* the next interface for the BMC.
*/
mutex_unlock(&intf->bmc_reg_mutex);
+ kref_put(&intf->refcount, intf_free);
mutex_lock(&bmc->dyn_mutex);
goto retry_bmc_lock;
}
---
base-commit: 551bbbed906516e04956e4de0896fb8c1317ea86
change-id: 20261203-kbug-l1316-6fcc56d75287
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ipmi:msghandler: Put the interface on the BMC changed retry
2026-12-04 2:53 ` Anh Nguyen Hoang via B4 Relay
(?)
@ 2026-12-04 12:18 ` Corey Minyard
-1 siblings, 0 replies; 3+ messages in thread
From: Corey Minyard @ 2026-12-04 12:18 UTC (permalink / raw)
To: anhnh.4work; +Cc: openipmi-developer, linux-kernel
On Thu, Dec 03, 2026 at 08:53:38PM -0600, Anh Nguyen Hoang via B4 Relay wrote:
> From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
>
> When __bmc_get_device_id() is called without an interface, it takes a
> reference on the first interface of the BMC. If the BMC's device id or
> GUID has changed, it re-registers the BMC and jumps back to
> retry_bmc_lock without dropping that reference, so the interface is
> never freed. Drop the reference before retrying, as the other retry in
> this function does.
Correct, this is in my for-next tree for next release.
Thank you,
-corey
>
> Found by a static analysis tool.
>
> Fixes: b2cfd8ab4add ("ipmi: Rework device id and guid handling to catch changing BMCs")
> Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
> ---
> Runtime test: QEMU, x86_64 defconfig + IPMI_HANDLER + IPMI_SI +
> KPROBE_EVENTS, on next-20261202 (its ipmi_msghandler.c is the same as
> the one in ipmi for-next). A scripted BMC behind ipmi-bmc-extern changes
> its product id while the guest runs. A read of ipmi_bmc.0/product_id by
> uid 1000 then takes this retry. The interface is then removed through
> the ipmi_si hotmod parameter, with kprobes on ipmi_unregister_smi() and
> intf_free().
> Before the patch: the refcount is 2 when entering ipmi_unregister_smi()
> and intf_free() is never called.
> After the patch: the refcount is 1 and intf_free() is called.
> Same result with two KCS interfaces on one BMC. With an unchanged BMC,
> both kernels free the interface.
>
> This patch was drafted with AI assistance (Claude, claude-fable-5-2).
>
> Testing:
> - Compile-tested on x86_64 (allmodconfig, W=1):
> drivers/char/ipmi/ipmi_msghandler.o; no new warnings.
> - checkpatch.pl --strict: no errors or warnings.
> ---
> drivers/char/ipmi/ipmi_msghandler.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 52e95e1949b9..f80d16dce449 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -2770,6 +2770,7 @@ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
> * the next interface for the BMC.
> */
> mutex_unlock(&intf->bmc_reg_mutex);
> + kref_put(&intf->refcount, intf_free);
> mutex_lock(&bmc->dyn_mutex);
> goto retry_bmc_lock;
> }
>
> ---
> base-commit: 551bbbed906516e04956e4de0896fb8c1317ea86
> change-id: 20261203-kbug-l1316-6fcc56d75287
>
> Best regards,
> --
> Anh Nguyen Hoang <anhnh.4work@gmail.com>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 12:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 2:53 [PATCH] ipmi:msghandler: Put the interface on the BMC changed retry Anh Nguyen Hoang
2026-12-04 2:53 ` Anh Nguyen Hoang via B4 Relay
2026-12-04 12:18 ` Corey Minyard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.