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=1796381157; b=eA0u2ejPewA79jgRtZvqPTYM3dPwUTpOmc2yvphtYSoAvVeJqBYWUL5f/zs6xuop3tbt Im0feGz6V5oBGY3uEXrd7WQyeL+JMOuymb3WjYYJdXFwopr8aDHDrYJj5j0U86r93K+OM 6OKybAoL/UilBKvfolVinfo8FtQUSEAo1JO3fXol2/9Wx2wbx2t36FcjE3LMK2TQuNMPe A1yvk6My/fYd8KrLdyi71qXqxE3+M0MiNIgT4eIvJZ6irjM7pCkMcUPNtOwvK6hH/YeDU kuzh7QzfQiDvoH4zN/wqviEjqkvTaMlWJ3M0zEnrWWb9NDXGYkWEGLzwNjuRoDL6/jQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381157; 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=JyUgzo874rlbLlFkXntwm/VLY+g32VSeVBhwKtdMZc8=; b=VJ2CojGW2NeaotQIaVAH7XSn+9uFonJVE7n+CU5gcSvj/hjFsw4L8LZuBX0rRLLNotZe yVar4y7WKAVTf7U+Ipa3kI3Hscl/Y1rfKIIMw7oinwGxt7PKf2GaOrcQMWoFXImmOuNVe gG6eVDbX705SzbnwWt54ArH5H38dB74Gv3g1Y2xfpz3gunq9fwQXPWco06h+ZOz8/oaWh vd+ydIL8CYsGWb2Ml4j06uwJHStTLcQgrtiI+A+2HcEvNmq47/oPxW8pM1sWokFCF93XE iz/5dbzp9wA4Omqr8jZ/LoAOnYbQaLvBU7A3SOxJe7Fh2PUzWZBW/o97N5hwFDBgeOg== 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=VHT6wwy1; 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 2AC3C606A32F; Fri, 4 Dec 2026 10:45:56 +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=VHT6wwy1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE5D1F000C2; Fri, 4 Dec 2026 10:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381156; bh=JyUgzo874rlbLlFkXntwm/VLY+g32VSeVBhwKtdMZc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VHT6wwy1w+wfpEARgH35yZd2HeylJg5YzticU6URnjHCtWhp82qSAQ4G4qKhLX/FU zoJXv3M5YUROY9R0n8Dl/+0gCZifTbUKvkHJbhoMY96nnDhf7I+mcmywlymapw0g3R TK9Hrbyzgq4xmJPb77tNXsX5K9N7+zo+i0VicogU= 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 7.3 584/742] scsi: mpi3mr: Validate reply frame size bounds Date: Fri, 4 Dec 2026 19:07:28 +0900 Message-ID: <20261204100650.643597371@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 @@ -3160,6 +3160,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); @@ -3217,6 +3218,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;