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=1796389514; b=DKyPCS1P4V+HkwN36jAOY17UzWEoC3typfIyEapBqNsyqJOSV4yiQPi+X2GRnoboTXAL tV6vAZNfQPQF6XR7CkHVFeYfV7XZqZcQzEf7T/O9xFCUauXgFNmP5rX7z61NakRSl/Nw4 lmmMb43Fs8Kfh5aJbG0S8p+vgx0Grhpq5PL3MsCfZA3VdjPXX91V13idCGBQbaTV73udH SLYVfwrqJHThQiffDqrebNfWMznocKMRqTQHeGF5B3tESZm5aFvHNsiEpvdFQTd6+cJl/ Sx8vjEPt7NpHN0DqI5lWSighMtu/BZDKHeWbXJTmW9HJU7pYuxDjoTL4uHtKKFNaHKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389514; 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=WxsnLRnn6KenxlE2d7pToJzIlMwzknNUIdpt66gXXN8=; b=dZ7xgPBNg3Sj6ANrEa/zzI7ytVUc/8FJzT8yBmu0wGYFtjkgeBM6ZcQsx8hzUSlcDkeF PK9iF5zmX0xSco1BzJNUOnstpabnGD1vzzXcjTyW2AJ0aLjb04prcxJYeOtAanRzW9f2K d2K6YnWhFfiyAIwa62YFueHgokBfsZtGI3PqruvMrVyi0T4sP0Pwbju/0oWhl6rmbbQTG 6cRZvSzvOHSPfFWgjNeZwO3O5e3J3rbx86+t83mSLGW/KfRNR+QIKv2xkJKIF7MD0dMg2 Z+hAC/2boXKeC6te6xaPD4MGpI60G39tO/UmKE0KRzszxizWhNOvFKALM7GQY2ctuOQ== 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=blWWzJO0; 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 B055F606A322; Fri, 4 Dec 2026 13:05:14 +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=blWWzJO0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD3521F000C2; Fri, 4 Dec 2026 13:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389514; bh=WxsnLRnn6KenxlE2d7pToJzIlMwzknNUIdpt66gXXN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=blWWzJO0lipxL5Ef5D0vkq951GoryvSs5DgPUg4ofFiJOXy6042cKXA2WGdEm88p7 m8JSI2pNxg+hkEhyKjMO6P7sLoo24EInkobYvws1VMieoML5/g8cVLF4edS/oMmSqa OoFTb5Ao+jxwPX3mmuOCR3/u3zWWcSoC87eqTjXI= 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.1 0980/1059] scsi: mpi3mr: Validate reply frame size bounds Date: Fri, 4 Dec 2026 19:08:31 +0900 Message-ID: <20261204100709.389887751@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 @@ -82,6 +82,7 @@ extern atomic64_t event_counter; #define MPI3MR_ADMIN_REPLY_Q_SIZE (4 * 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 @@ -2730,6 +2730,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); @@ -2787,6 +2788,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;