From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383966; b=itGKr10fPlcKfCcCahlwa0+hTQl4456l3dR6qFuWOHedNJNY/vsGMcTzDpEhy72BxWjL 0Rhg2HIpXq2v41NY2r2GbDH7/DW1JO96XScTZY9hFXefD1OSh/X4COv/rS1nr+p+yAKPI ufuBTWNElyk8HcQJB1KkSjt4UJCtSfgcir6/jbRFuQJ/u9tlr6eK1okKmBbfdLmcjhLMl ptDXinskHoy5yhv4cXy7u5LM9U4i1ysTKpIssDPJXLg3A4Y4UL03Lo1FmNnZeCA39PHRD MBR/bP+rzStf5FBz1az40vMZNOygjixFk4y9e2IQIsjAoi20hc0AS1wxz+YEHzi5HkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383966; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=3rhco+M4Di79tg5383AqMwczCGKu7bQDDLLl6S05EZs=; b=es9DNEH9o2LOzfsHnbJRbFnRyVshLCuqYsgJn4SHHNwMLx1tpn1VG08KYGpmaC0KrWC4 EAqD9+LtvNSUY6iTtEAnbuk2rYEVWi7hzMDQXTpQNf2NSUooHfBp7puDHZyajSPiyanD5 UnAi0YuiT+B6VQK1hKnW7jnCTh1XTnKCsUEYodC1wKdEZ43iGCUMr8miOJAKVDDbz30kW HNHXJVOJEpUNk9ffSUpcGk16tjIZv3IAzdV67nEeFxDKlHW85YGgUWXs1EQXywY35UFg7 SXLzi6v4TXeipeJ6lC3GPwqB9KJn85rB1Ov7LX3caiFNcT/8kbh9EOv5461C23IFSkA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="eL/0W5XR"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 701AB606A69A; Fri, 4 Dec 2026 11:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=eL/0W5XR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 309C81F00935; Fri, 4 Dec 2026 11:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383965; bh=3rhco+M4Di79tg5383AqMwczCGKu7bQDDLLl6S05EZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eL/0W5XROPcZNMwvmGJGTqq4GPFizuOKcVAo5ioVIcmc9OoUS79o+oZiL3///2Y6I TmU9B3dAY85PeLy/LWv+mp0Cap1nhRtC8BBzT0f8bxaatxagXHKmbiO0VUBjZwXWTg pTZ9pi8EiVEVp1IyEcrkJbo8gS+VJvfWND8sxHlo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Milan P. Gandhi" , "Martin K. Petersen (Oracle)" Subject: [PATCH 6.12 440/555] scsi: mpi3mr: Validate reply frame size bounds Date: Fri, 4 Dec 2026 19:08:03 +0900 Message-ID: <20261204100626.334266273@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Milan P. Gandhi commit e550f2b2b4aab4c5f12db89d04d8978ce4ed7b4e upstream. Firmware provides reply_frame_size in dwords, which the driver multiplies by 4 to compute facts.reply_sz (u16). If the reported size exceeds U16_MAX / 4, the multiplication overflows u16 before assignment, causing under-allocated DMA reply buffers. Furthermore, several paths assume a minimal reply frame size: - logdata_entry_sz calculations underflow or hit zero when reply_sz <= 20 bytes, leading to zero-size allocations and divide-by-zero crashes. - Unsolicited status descriptors and fixed replies (such as struct mpi3_iounit_control_reply, 64 bytes) require at least 16 dwords. Validate reply_frame_size in mpi3mr_issue_iocfacts() to ensure it is within [16, U16_MAX / 4] dwords before processing facts data. Fixes: 824a156633df ("scsi: mpi3mr: Base driver code") Cc: stable@vger.kernel.org Signed-off-by: Milan P. Gandhi Link: https://patch.msgid.link/20261105122401.266559-1-mgandhi@redhat.com Signed-off-by: Martin K. Petersen (Oracle) Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/mpi3mr/mpi3mr.h | 1 + drivers/scsi/mpi3mr/mpi3mr_fw.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -83,6 +83,7 @@ extern atomic64_t event_counter; #define MPI3MR_ADMIN_REPLY_Q_SIZE (8 * MPI3MR_PAGE_SIZE_4K) #define MPI3MR_ADMIN_REQ_FRAME_SZ 128 #define MPI3MR_ADMIN_REPLY_FRAME_SZ 16 +#define MPI3MR_MIN_REPLY_FRAME_SZ_DWORDS 16 /* 64 bytes */ /* Operational queue management definitions */ #define MPI3MR_OP_REQ_Q_QD 512 --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c @@ -3009,6 +3009,7 @@ static int mpi3mr_issue_iocfacts(struct struct mpi3_ioc_facts_data *facts_data) { struct mpi3_ioc_facts_request iocfacts_req; + u16 reply_frame_size; void *data = NULL; dma_addr_t data_dma; u32 data_len = sizeof(*facts_data); @@ -3066,6 +3067,23 @@ static int mpi3mr_issue_iocfacts(struct goto out_unlock; } memcpy(facts_data, (u8 *)data, data_len); + + reply_frame_size = le16_to_cpu(facts_data->reply_frame_size); + /* + * Validate reply_frame_size: + * - Must be at least 16 dwords (64 bytes) to accommodate fixed reply + * structures and avoid underflow/divide-by-zero in logdata sizing. + * - Must not exceed U16_MAX / 4 to prevent integer overflow. + */ + if (reply_frame_size < MPI3MR_MIN_REPLY_FRAME_SZ_DWORDS || + reply_frame_size > (U16_MAX / 4)) { + ioc_err(mrioc, "Invalid reply_frame_size %u (must be %u..%u dwords)\n", + reply_frame_size, MPI3MR_MIN_REPLY_FRAME_SZ_DWORDS, + (unsigned int)(U16_MAX / 4)); + retval = -EINVAL; + goto out_unlock; + } + mpi3mr_process_factsdata(mrioc, facts_data); out_unlock: mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;