From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FFFE3FB04E; Fri, 4 Sep 2026 05:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788498600; cv=none; b=U8/OXrW73CQEH3V85/2EUMl5V2NlZrkKBq3N0bcc9x8jP2AzHqF+NY9K+Ytq6TKxaOZNkL3RBPs7sZ89C3nAOHLLqkimCVQlrAG9u+oBJXKd1KwFrSuohEKRILvaKm4fiLqC4M+zRSRX4uCLmYgzc6AKb9NaHSvlSCneQ8zL/Kg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788498600; c=relaxed/simple; bh=wDEUEB1KUKWzFh83TJ4hwcyPNkuqxcJvRotWZL2Wd+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jSx+3G8nb6f72fi2zKjSzYu4usx2OBWsu3P86XJ6NhEJzLJ5rIBtxsVIJUpZUPxFZuMiND5MyTJ8CqFF7ezbMhinrg1+rCmOJpLMz12F5m+WSdVjThSFo/92xHb2lBOVCPekl+7/mjO7Hob3rcjTlggRb5SXIDbgODlaG8mIP88= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=edFRXo7j; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="edFRXo7j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 358341F00A3D; Fri, 4 Sep 2026 05:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788498598; bh=6JVLlKv/Au3btGyaft5sBSHACGdQnPC2JTKrFtxqv+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=edFRXo7j9MzeJNPz86pveJqa99Hm1B4bT5hLPRgBhYKMs6HjHLZxRiN3e0m8bQ2Jd 9f+2df/htgiPc2M8ryB8voGlX3j1o5UKXeEJyZcK1Wa84yINB0caIhmLG1XXsCcIe7 +RUlLroA/E7zJHzQGErMAroZ55Ln2ZjLYT4vA8fw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Terry Bowman , Alison Schofield , Dave Jiang Subject: [PATCH 7.2 118/713] cxl/ras: Fix cxl_rch_get_aer_info() out-of-bounds AER register read Date: Fri, 4 Sep 2026 06:51:26 +0200 Message-ID: <20260904045806.482384070@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045803.810145556@linuxfoundation.org> References: <20260904045803.810145556@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Terry Bowman commit 29458e62d0829cbc99435f3e44fd560f9bbf1da7 upstream. cxl_rch_get_aer_info() copies the RCH Downstream Port AER capability from the RCRB MMIO block using a readl() loop bounded by sizeof(struct aer_capability_regs). This struct is a software layout and its embedded struct pcie_tlp_log is larger than the on-wire AER capability. As a result the loop reads past the mapped AER register block. The over-read also populates the software-only tail fields including header_log.header_len. An out-of-range header_len passed to pcie_print_tlp_log() can then loop past the header log buffer and cause a second out-of-bounds read. The read was correct when introduced, but struct pcie_tlp_log has since grown (Header Log and TLP Prefix Log sizes, header_len and flit fields), so sizeof(struct aer_capability_regs) no longer matches the physical AER capability. Bound the read to the physical AER registers, header through the 16 byte Header Log. Zero the destination first so the software-only fields are deterministic. Fixes: 6ac07883dbb5 ("cxl/pci: Add RCH downstream port error logging") Reported-by: Sashiko Cc: stable@vger.kernel.org Signed-off-by: Terry Bowman Reviewed-by: Alison Schofield Link: https://patch.msgid.link/20260803221810.3685703-2-terry.bowman@amd.com Signed-off-by: Dave Jiang Signed-off-by: Greg Kroah-Hartman --- drivers/cxl/core/ras_rch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- a/drivers/cxl/core/ras_rch.c +++ b/drivers/cxl/core/ras_rch.c @@ -58,13 +58,28 @@ void cxl_disable_rch_root_ints(struct cx static bool cxl_rch_get_aer_info(void __iomem *aer_base, struct aer_capability_regs *aer_regs) { - int read_cnt = sizeof(struct aer_capability_regs) / sizeof(u32); + /* + * Bound the copy to the physically-defined AER registers (header + * through the 16-byte Header Log). struct aer_capability_regs is a + * software layout whose embedded struct pcie_tlp_log is larger than + * the on-wire AER capability; copying sizeof(*aer_regs) would + * over-read the RCRB-mapped MMIO block. + */ + int read_cnt = (PCI_ERR_HEADER_LOG + 16) / sizeof(u32); u32 *aer_regs_buf = (u32 *)aer_regs; int n; if (!aer_base) return false; + /* + * Zero the destination so the software-only tail fields + * (e.g. header_log.header_len) are deterministic rather than + * left as uninitialized stack, which could drive a bogus loop + * length in pcie_print_tlp_log(). + */ + memset(aer_regs, 0, sizeof(*aer_regs)); + /* Use readl() to guarantee 32-bit accesses */ for (n = 0; n < read_cnt; n++) aer_regs_buf[n] = readl(aer_base + n * sizeof(u32));