[PATCH] ipmi: ipmb: Limit received direct messages to the rsp buffer

From: Weidong Wang via B4 Relay

Date: Sat Dec 05 2026 - 23:43:05 EST


From: Weidong Wang <weidongw@xxxxxxxxxxxx>

ipmi_ipmb_check_msg_done() copies a received IPMB_DIRECT message, a
command or a response to a direct request, into imsg->rsp + 1 with
length rcvlen - 4, and rcvlen can be up to IPMI_MAX_MSG_LENGTH + 5. A
checksum-valid frame of 276 or more bytes writes past the end of the
272-byte rsp[], into the done callback pointer that follows it, and
sets rsp_size beyond the array. Ignore such frames.

Found by a static analysis tool.

Fixes: 63c4eb347164 ("ipmi:ipmb: Add initial support for IPMI over IPMB")
Signed-off-by: Weidong Wang <weidongw@xxxxxxxxxxxx>
---
The fix and the changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/char/ipmi/ipmi_ipmb.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/char/ipmi/ipmi_ipmb.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ipmb.c b/drivers/char/ipmi/ipmi_ipmb.c
index 1f1e5718f082..421b9f9f2981 100644
--- a/drivers/char/ipmi/ipmi_ipmb.c
+++ b/drivers/char/ipmi/ipmi_ipmb.c
@@ -97,6 +97,12 @@ static bool valid_ipmb(struct ipmi_ipmb_dev *iidev)
return true;
}

+/* A direct message stores rcvlen - 3 bytes in rsp. */
+static bool direct_msg_fits(struct ipmi_ipmb_dev *iidev)
+{
+ return iidev->rcvlen - 3 <= IPMI_MAX_MSG_LENGTH;
+}
+
static void ipmi_ipmb_check_msg_done(struct ipmi_ipmb_dev *iidev)
{
struct ipmi_smi_msg *imsg = NULL;
@@ -115,6 +121,8 @@ static void ipmi_ipmb_check_msg_done(struct ipmi_ipmb_dev *iidev)
/* Ignore commands until we are up. */
if (!iidev->ready)
goto done;
+ if (!direct_msg_fits(iidev))
+ goto done;

/* It's a command, allocate a message for it. */
imsg = ipmi_alloc_smi_msg();
@@ -132,9 +140,13 @@ static void ipmi_ipmb_check_msg_done(struct ipmi_ipmb_dev *iidev)
* Responses should carry the sequence we sent
* them with. If it's a transmitted response,
* ignore it. And if the message hasn't been
- * transmitted, ignore it.
+ * transmitted, ignore it. Ignore a direct
+ * response that does not fit in rsp.
*/
- if (!xmit_rsp && seq == iidev->curr_seq) {
+ if (!xmit_rsp && seq == iidev->curr_seq &&
+ (iidev->working_msg->type !=
+ IPMI_SMI_MSG_TYPE_IPMB_DIRECT ||
+ direct_msg_fits(iidev))) {
iidev->curr_seq = (iidev->curr_seq + 1) & 0x3f;

imsg = iidev->working_msg;

---
base-commit: 551bbbed906516e04956e4de0896fb8c1317ea86
change-id: 20261205-kbug-l2241-4eb8abfe6a75

Best regards,
--
Weidong Wang <weidongw@xxxxxxxxxxxx>