[PATCH] ipmi: ssif_bmc: keep received bytes inside the part buffer

From: Eric Yun Lin Chiang

Date: Thu Dec 03 2026 - 00:02:22 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Eric Yun Lin Chiang <ericyunlinchiang@xxxxxxxxx>
---
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