From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796564907; b=atgOMpC3tBrjJahsRLWMaQNEOZ9uh8SLb/3R5nC0a6ndFTYg7abpRPhVd5tjgpeZw2PO /FK211mSR2narWC6vSwwJ1mR5843qN6IYSIbdQsQU3Xj26fjUaqxdq2HIjQzAweTQrfbZ VBc+H7fYb3fMKVl+gfeoGrChVrwDXdVXyM9Kc7hi4XutJRzu/mYFwakWWJrLjF+YJ2ZSW 7ZzWIOtDd/Y1qpyk1flVPEz3+rMDw1oZCwp77WqG4NgUQk8ftIRdroCZjYkxZbbmIadl/ EYxFzhiGgJJSPbG940YhzPwCULjS792ken0t64teaZ+n96rTjC4CQeoyS6U7DGWXB/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796564907; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:Reply-To:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=azy560duWpvH4N23x/8DfEoLQM+GAXi3rOXmWJ981w0=; b=QlEKDDrsiyK5+4L0uF2vRrI7W8OGpDCFQ3mbIgBhXSvRJcEDgUH6zntCHvYQAwitwVex AyrKja2CLvOkN6AV37NVIfGvabDox23wCkLGknzj/CrlILAaZZWEtJbr0qtO0LfSP7CxP NNFgHbDBkTitJOglm9jA8GwsxuRlVLvc6Z2JKo04WywO9zd7FuWcJ6kDq5wMrx/7sfS/3 dlfyt+yxfeynjEjXpQfrzoeOfIJRWu5PTZ7qFnQgft/4wMwpQQrMcqBnf80loIxHYZahz VXttivpT601vyA2j0UH9EidbhZD3nypBeVZuuC6gypBlUjpy3Wm1voDqg7gbC4Z06Gw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=minyard.net; spf=pass smtp.mailfrom=minyard.net; dkim=pass header.d=minyard.net header.i=@minyard.net header.a=rsa-sha256 header.s=google header.b=bCu1PjBx; arc=none smtp.remote-ip=209.85.160.47 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F7F6606A321 for ; Sun, 6 Dec 2026 13:48:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1F7F6606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=minyard.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=minyard.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=minyard.net header.i=@minyard.net header.a=rsa-sha256 header.s=google header.b=bCu1PjBx Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-4d3dc583029so1586720fac.0 for ; Sun, 06 Dec 2026 05:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1796564906; x=1797169706; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:reply-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=azy560duWpvH4N23x/8DfEoLQM+GAXi3rOXmWJ981w0=; b=bCu1PjBxHztRiJJb/ZjTTfO9wGgVCbvinZ0uZ1UF5fiooc9aOYo4UZ/RWKggtQvbtP Mjq/7ovHGJ8+eU0r5W2y7NM7jdXem0KqX7t+9hEIZCvqWyEIlqnmF5zw7owd/9EFV/hb Lr3Fi12DRwERE2HZBMgsNFTMagT+ereQ3sJW/WfezIn44tEUkziOp2KHr2z9Ho6fQC23 cl0toFqECQbkUJzoAluCz4X9rOTGkhpOswJzgP8g2qAwxDPa74q/oyW0DBSFLIpKht7y pqed+kFncTkFdr4QyqdBm5xuxSXyDGzcECAa20W5TntawTZC3Y7NOWOFMf48+NWkoxyj zDNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796564906; x=1797169706; h=in-reply-to:content-disposition:content-type:mime-version :references:reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=azy560duWpvH4N23x/8DfEoLQM+GAXi3rOXmWJ981w0=; b=Hh/27CF+04Xwo+fJI10SceUfMGjPYYPp5iVC2d4ZON/Okxzg729Aqu4ozcCqo0LkaR /a1AKKXBkvCBz+7iSKz/XeZnw3jjUiSpDs8oiJiPrQ41aAI4kymzKa2jHFSHbEpfjSjG rjzEIrQZw7+Sx2YCov+LsPm3exfi1TVqZ7Wk1JmISklqv6BveEh/4ZPjZj3zUgQRXunO 5FYVD8pbDcaAQZv0Gq7Yn3Qrd8gKB37U8dUi/MYkh3MmKpfHUCR41x9iRK3MWHhxruJT u5xunqA1Pkv+Idmooz4nVw1mNFGXDdYy0nmKJp1/0xg87C/08tfQCtCK9R3DqQMjpiKp xjkQ== X-Forwarded-Encrypted: i=1; AL+hErHkqsBGReWDxlP3qBAPfr4eJLiq2v9Rr8PRCOCJs3G7daMGtvvcJX9esShoID7dWasNlwejfli2/eRa9fM=@vger.kernel.org X-Gm-Message-State: AB4q+uG8uZUs9mNq/tFeKAHJTNX+v4SOWq4WQivEgK/cljyzmst5DqAi MyxGujhVZmBCRZD9KwyryzS3RLSdZnbTahuKGQTcr8c/uwBTxCotGI8t6yJXvuuO5sM= X-Gm-Gg: AZFdTZcfF1n0hcRmoRP2eBw3NdVNy5De94DX3sA/TFhtUoPynBA+6yDsFwdFZjcB0Mf md5onGBp7/1fa5RthvaSD7G6ZrwrkSon9knrXCu/6JO/8SnyguFuOrv+EtlTZag8nQHIV4RkWuh tZ6dPYrnN9AOu+AIygHx43ZNEo1T/0bpy4AEmKsejGiCuuWU0mTwGqKYLbWc3QVLr2iB7lL356R NznXIqoYpyb3F543NykxdGB/RXnbCLpRxSEqrPIiLhmLNnMgFU/KcIocNrj9TZdPqia13gKeSVe TgzkRoneyoHaU47lso6WQqBNgMuiZzCqj4/eIGxvrvhtk91GptPTK/4sKssiztwm2RZhgq1JcRG DiiqVLqQwtqCw05pQSwaEetJK58awzX/n8lJJ7pj4ikaPnnbPG9HcEvJ3bo68SrVNbN7RT289Ws f+9Tk25vU8WTA7st8T5beKXSTZaeCiKb+eKE7yIL/MkSxmBvbpJJYuivV/gWLcltyNyMysB4Pz2 +mKcUM56ohwS+FQSEWxaUsXUlIbtlIGE25X7D4iXS7jVvtU3oKvueYuUFxOOrCfc7ucx5UR4h+Q wSJGHWNciRC8Rzd9DSvoSayHTutv+mHj2vXBTLTdfGQX/v9x4XtnKjglBdBuztRKaEU829+NGeH gou2UvglXOYR0PIRcqzWbj4q6u2Qa19y0ojPFXQLvYRjNz9N1fobZ2jAWalrdF7TZ0vn9vQ== X-Received: by 2002:a05:6870:218c:b0:4a9:5bde:8484 with SMTP id 586e51a60fabf-4e3d7db6fcdmr6520943fac.51.1796564905975; Sun, 06 Dec 2026 05:48:25 -0800 (PST) Received: from mail.minyard.net ([2001:470:b8f6:1b:e12b:df64:db65:69b3]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4e3bfdb1747sm5608972fac.7.2026.12.06.05.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 05:48:25 -0800 (PST) Date: Sun, 6 Dec 2026 07:48:19 -0600 From: Corey Minyard To: Eric Yun Lin Chiang , Quan Nguyen Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] ipmi: ssif_bmc: keep received bytes inside the part buffer Message-ID: Reply-To: corey@minyard.net References: <20261203050134.3568574-1-ericyunlinchiang@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261203050134.3568574-1-ericyunlinchiang@gmail.com> On Thu, Dec 03, 2026 at 01:01:34PM +0800, Eric Yun Lin Chiang wrote: > 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. This looks correct to me. Adding Quan for comment, but I have queued this for next release. -corey > > Fixes: dd2bc5cc9e25 ("ipmi: ssif_bmc: Add SSIF BMC driver") > Cc: stable@vger.kernel.org > Signed-off-by: Eric Yun Lin Chiang > --- > 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 >