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=1796382583; b=tFTp35U/2ho+/2adcHo+UwSiV25RX82zF4Dti8ozkbGGsO9etCdr8c2UbPThK9QFaZtC uHeT8+MiM+aG02La59LVqWwhkngoW5cWqfG/GWefqnjzS3UfMZCkw/VEtIuu5pXsnBxHl QH/JUI4W7BzNvxgmD/tQi+4vcmh6jhgsszBBMISIgGq5IpTkVfOMb4dxmwXFXdc25wCfb +blZDcrVtVkLr2zSC0+RJquM1x7zqYUmFxbcq+h9k+MraWEsBBiM9uGBSqSMndZEgU94I yV4SLkPnhgNXl1fvqulQLHsm3O2c7CfBgi97PD5EIf4y+pzdH+9dihHVWLnUBCd8TLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382583; 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=fc5OehYdPL0zu3JOv1T4VsAelaVS4Tsu7s9Ckcp9YyI=; b=joXYgk46CBHNvoMQUTkisgIP7ZaKWces9esnvjv8DI+Z3pB6rYCqCNTOrYMFLXj4Rue0 pP2VJGZB/UCj8UhRx4DF7AHv+ZRj5BbvyjnU1J8WsINZO32yEBmt6gZ7/z5rWmSFTiykp x/+DUsV4EDzevVvNMpsMv4TTXl5MpF5MbUnn8Lo3aHyceIea3SBgCj8XsXprLSYPWRj2f nX+ATNFkibVmK/AP4g5ezKzFUgkYl02WnFnax/2dsLpXi+REEuKmINkvvYmcjeGA0Q+Sa oI+1+X79T9ok67JcVLb0XUlfI3yesk1yzkrLca1DuFWoVG0ytg+unOHJAVZI0Hsd7Qw== 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=OkoY3+8J; 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 D6DF8606A322; Fri, 4 Dec 2026 11:09:43 +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=OkoY3+8J Received: by smtp.kernel.org (Postfix) with ESMTPSA id 027EC1F000C2; Fri, 4 Dec 2026 11:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382583; bh=fc5OehYdPL0zu3JOv1T4VsAelaVS4Tsu7s9Ckcp9YyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OkoY3+8JE59ryNBbUERUHjQd63WCLce3uSPAU484C04d3v9nsh4S5jTGlF2LG87Fm VcQDmy52BBVG2V3qEn3xFdeX44r87SbCbtiyCihM6nq8ldKt9TvJVlIr4I0q/dYAi3 ULY3BlS8SBJP3zjh8mdn7PiqPk1LLJL25Re52UKk= 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.18 516/703] scsi: mpi3mr: Validate reply frame size bounds Date: Fri, 4 Dec 2026 19:06:55 +0900 Message-ID: <20261204100641.522665400@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 @@ -3032,6 +3032,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); @@ -3089,6 +3090,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;