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=1796384904; b=3EKt89RMTTypLvdHFVCwAyxx7xny2UKQowd+Ci7kCgFFLYp3Y+Hy+mAcynOSSUUgfo5r o5hnoegvrJa0DjBRrKPrQibRw7HomCk8A/CBQL+0zW7ZdylFOTx1OPb6iVy3ZAiUu/uic BaUS9kdTVbxR3E7eh/UDxzgIb7EKRRZyNQC7hYhRAAxZ+XuaGJESntr9+1rxySBLyPEVE 0g9kf/co0lEs4UzUC8OsVjPcuYaYrNXdAUvRrXvOR+/HnZaStaEn3kLjit/VGfcFT5wmp eMmI72J+Txdnpi8FFbDOg5M6Fl2AfCYGOM+H35v35HJfSxZxLEszCFGUKC0j18UfiiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384904; 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=VpZpAdiQBxINqVmuebGEWSODpKbcHCdhNNA6OfZQTzM=; b=UFwzZ0NXR3iXRxznrpajU6Uds7L+1q7Sfgekq382PfG0momSvqJC86oL4dag3GZycEG6 lZXsA4NuJ1Qx2kZTpH5jQRU71ScZJsYwut0epYz4OcLMDq5Wz0BDhTBidS9Ty3g9oqlPv GzfZsE0txbFASeISB73THSTcB0lGwrsOiWF1fsG5udV1nebttl6wwGsHFZ3JPG8Y4MBC2 2ldrNnVywa5ySWlMGSS9WDUy37HCH58C4U9ZzBkIuIMMv3av7xIugJ1u8k/6eFH32rrrQ TjEF5wDVAKvBHwbY7Mvfpfm4G2op8PVtGvXEmfO5ul6pGUoY5WfD8d16bbwE+o69hLQ== 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=TlUVmgTw; 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 7321A606A32D; Fri, 4 Dec 2026 11:48:24 +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=TlUVmgTw Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7BD71F00935; Fri, 4 Dec 2026 11:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384904; bh=VpZpAdiQBxINqVmuebGEWSODpKbcHCdhNNA6OfZQTzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TlUVmgTwjGIpPj6iuJOMf9SJP0b9WOeHs82KczMyhiGsgx7cNkoTn7rV9fUTIj2im u+ENAR48LLlp0rZJeoLaTFOd6rGzYlMzrLY/zhAreEXQXo+Yxc1rWB5rLI2N4ifQM0 2idOfdkUwgZ1P0QMxycaELjXnlWaoB4EAaXZPlVQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alison Schofield , Li Ming , Dave Jiang , Sasha Levin Subject: [PATCH 6.6 0325/1167] cxl/port: Bound switch decoder target array access by nr_targets Date: Fri, 4 Dec 2026 18:55:52 +0900 Message-ID: <20261204100710.469853156@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alison Schofield [ Upstream commit 4e42c398af136d62fac8c19c9f410ec83a8dd34a ] Switch decoder target lookups walk the target array using interleave ways as the bound. The array is allocated with nr_targets entries, so a decoder whose interleave ways exceeds nr_targets reads and writes past the end of it. That happens during dport activation, during decoder target population, and when userspace reads the target_list attribute. Bounding by nr_targets alone is not correct either. Commit d6488fee6647 ("cxl/port: Fix decoder initialization when nr_targets > interleave_ways") moved target population to interleave ways precisely so that targets a decoder does not use are left unpopulated. Neither field alone is a safe bound, so add a helper that returns the minimum of the two and use it at every walk of the target array. Valid configurations keep interleave ways within nr_targets, so this is not a behavior change for them. Fixes: 40ba17afdfab ("cxl/acpi: Introduce cxl_decoder objects") Fixes: d6488fee6647 ("cxl/port: Fix decoder initialization when nr_targets > interleave_ways") Signed-off-by: Alison Schofield Reviewed-by: Li Ming Link: https://patch.msgid.link/d7577652cc6d414e1de0ee4045d4d6b2808172ce.1786143520.git.alison.schofield@intel.com Signed-off-by: Dave Jiang [ sashal: Dropped the update_decoder_targets() hunk because that function doesn't exist here, and adapted decoder_populate_targets() to its older target_map parameter and rwsem context. ] Signed-off-by: Sasha Levin --- drivers/cxl/core/port.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 6bc3dd4dcd8a8..f71ee86c8a085 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -142,20 +142,29 @@ static ssize_t target_type_show(struct device *dev, } static DEVICE_ATTR_RO(target_type); +/* + * Interleave ways selects how many targets a decoder uses, but the target + * array is only nr_targets long. Bound array access by both. + */ +static int cxlsd_nr_used_targets(struct cxl_switch_decoder *cxlsd) +{ + return min(cxlsd->cxld.interleave_ways, cxlsd->nr_targets); +} + static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf) { - struct cxl_decoder *cxld = &cxlsd->cxld; + int nr_used = cxlsd_nr_used_targets(cxlsd); ssize_t offset = 0; int i, rc = 0; - for (i = 0; i < cxld->interleave_ways; i++) { + for (i = 0; i < nr_used; i++) { struct cxl_dport *dport = cxlsd->target[i]; struct cxl_dport *next = NULL; if (!dport) break; - if (i + 1 < cxld->interleave_ways) + if (i + 1 < nr_used) next = cxlsd->target[i + 1]; rc = sysfs_emit_at(buf, offset, "%d%s", dport->port_id, next ? "," : ""); @@ -1581,7 +1590,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_find_port, CXL); static int decoder_populate_targets(struct cxl_switch_decoder *cxlsd, struct cxl_port *port, int *target_map) { - int i; + int i, nr_used; if (!target_map) return 0; @@ -1592,7 +1601,8 @@ static int decoder_populate_targets(struct cxl_switch_decoder *cxlsd, return -EINVAL; guard(rwsem_write)(&cxl_region_rwsem); - for (i = 0; i < cxlsd->cxld.interleave_ways; i++) { + nr_used = cxlsd_nr_used_targets(cxlsd); + for (i = 0; i < nr_used; i++) { struct cxl_dport *dport = find_dport(port, target_map[i]); if (!dport) -- 2.53.0