[PATCH] ipmi:msghandler: Put the interface on the BMC changed retry

From: Anh Nguyen Hoang via B4 Relay

Date: Thu Dec 03 2026 - 21:53:46 EST


From: Anh Nguyen Hoang <anhnh.4work@xxxxxxxxx>

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@xxxxxxxxx>
---
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@xxxxxxxxx>