* [PATCH] ipmi: ipmb: Limit received direct messages to the rsp buffer
@ 2026-12-06 4:43 Weidong Wang via B4 Relay
2026-12-06 13:42 ` Corey Minyard
0 siblings, 1 reply; 2+ messages in thread
From: Weidong Wang via B4 Relay @ 2026-12-06 4:43 UTC (permalink / raw)
To: Corey Minyard
Cc: Andrew Manley, openipmi-developer, linux-kernel, Weidong Wang
From: Weidong Wang <weidongw@illinois.edu>
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@illinois.edu>
---
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@illinois.edu>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ipmi: ipmb: Limit received direct messages to the rsp buffer
2026-12-06 4:43 [PATCH] ipmi: ipmb: Limit received direct messages to the rsp buffer Weidong Wang via B4 Relay
@ 2026-12-06 13:42 ` Corey Minyard
0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2026-12-06 13:42 UTC (permalink / raw)
To: weidongw; +Cc: Andrew Manley, openipmi-developer, linux-kernel
On Sat, Dec 05, 2026 at 10:43:00PM -0600, Weidong Wang via B4 Relay wrote:
> From: Weidong Wang <weidongw@illinois.edu>
>
> 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.
This looks correct. Queued for next release.
Thanks,
-corey
>
> Found by a static analysis tool.
>
> Fixes: 63c4eb347164 ("ipmi:ipmb: Add initial support for IPMI over IPMB")
> Signed-off-by: Weidong Wang <weidongw@illinois.edu>
> ---
> 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@illinois.edu>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 13:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 4:43 [PATCH] ipmi: ipmb: Limit received direct messages to the rsp buffer Weidong Wang via B4 Relay
2026-12-06 13:42 ` Corey Minyard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®