mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Yun Lin Chiang <ericyunlinchiang@gmail.com>
To: Corey Minyard <corey@minyard.net>
Cc: openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	Eric Yun Lin Chiang <ericyunlinchiang@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] ipmi: ssif_bmc: keep received bytes inside the part buffer
Date: Thu,  3 Dec 2026 13:01:34 +0800	[thread overview]
Message-ID: <20261203050134.3568574-1-ericyunlinchiang@gmail.com> (raw)

The handle_write_received() stores every byte after the length byte
into part_buf.payload[] for as long as msg_idx is at most
MAX_TRANSACTION (36). msg_idx is 1 on the length byte, so up to 35
bytes go into the 32-byte payload: the 33rd lands in the pec field,
the 34th in part_buf.index itself, and the next one at payload[index],
where index is now the value the SMBus master just sent. A master that
writes a few bytes more than the protocol allows can therefore place a
byte up to 255 bytes past the payload, in the response and request
buffers that follow part_buf in struct ssif_bmc_ctx.

A valid 32-byte part with a PEC relies on the same layout: the PEC is
stored in payload[32], which is the pec field, and
validate_request_part() reads it back from there.

Give the PEC its own slot in payload[]. Stop storing once the buffer
is full but keep counting, so a part longer than its length byte still
fails validation. Reject a length larger than
MAX_PAYLOAD_PER_TRANSACTION before the payload is used, since the
count alone no longer catches it.

Fixes: dd2bc5cc9e25 ("ipmi: ssif_bmc: Add SSIF BMC driver")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Yun Lin Chiang <ericyunlinchiang@gmail.com>
---
Notes (not for the changelog):

- Testing: KUnit on UML with KASAN (CONFIG_SSIF_IPMI_BMC_KUNIT_TEST),
  with three new cases that are kept out of this patch and are
  available to the maintainers on request:
  - a 32-byte part followed by four more bytes: before, the bytes after
    part_buf change and part_buf.index ends at 49; after, unchanged;
  - a length byte of 34 followed by 34 bytes: before, rejected only
    because the index had been overwritten; with the storage change
    alone it is accepted and copied out of a 33-byte buffer; with the
    length check, rejected;
  - a full 32-byte part with a valid PEC: accepted before and after.
  The nine existing cases pass. KASAN reports nothing before or after,
  since every write stays inside struct ssif_bmc_ctx.
  Built for ARM (aspeed_g5_defconfig plus SSIF_IPMI_BMC) with W=1, no
  new warnings. Not run on hardware.
- Tool use: found, and this change and its test drafted, with the help
  of an AI coding assistant (Claude).

 drivers/char/ipmi/ssif_bmc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ssif_bmc.c b/drivers/char/ipmi/ssif_bmc.c
index 545c9cb78..b21a09b5e 100644
--- a/drivers/char/ipmi/ssif_bmc.c
+++ b/drivers/char/ipmi/ssif_bmc.c
@@ -53,7 +53,8 @@ struct ssif_part_buffer {
 	u8 address;
 	u8 smbus_cmd;
 	u8 length;
-	u8 payload[MAX_PAYLOAD_PER_TRANSACTION];
+	/* room for the PEC byte that follows a full part */
+	u8 payload[MAX_PAYLOAD_PER_TRANSACTION + 1];
 	u8 pec;
 	u8 index;
 };
@@ -500,7 +501,12 @@ static void handle_write_received(struct ssif_bmc_ctx *ssif_bmc, u8 *val)
 		ssif_bmc->part_buf.length = *val;
 		ssif_bmc->part_buf.index = 0;
 	} else {
-		ssif_bmc->part_buf.payload[ssif_bmc->part_buf.index++] = *val;
+		struct ssif_part_buffer *part = &ssif_bmc->part_buf;
+
+		/* Keep counting past the buffer so validation sees the length mismatch. */
+		if (part->index < sizeof(part->payload))
+			part->payload[part->index] = *val;
+		part->index++;
 	}
 
 	ssif_bmc->msg_idx++;
@@ -513,6 +519,11 @@ static bool validate_request_part(struct ssif_bmc_ctx *ssif_bmc)
 	u8 cpec;
 	u8 addr;
 
+	if (part->length > MAX_PAYLOAD_PER_TRANSACTION) {
+		ret = false;
+		goto exit;
+	}
+
 	if (part->index == part->length) {
 		/* PEC is not included */
 		ssif_bmc->pec_support = false;
-- 
2.53.0


                 reply	other threads:[~2026-12-03  5:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203050134.3568574-1-ericyunlinchiang@gmail.com \
    --to=ericyunlinchiang@gmail.com \
    --cc=corey@minyard.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openipmi-developer@lists.sourceforge.net \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®