From: Davidlohr Bueso <dave@stgolabs.net>
To: dave.jiang@intel.com
Cc: jic23@kernel.org, alison.schofield@intel.com,
linux-cxl@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH] cxl/hdm: Robustify decoder target list reads
Date: Tue, 28 Jul 2026 16:02:29 -0700 [thread overview]
Message-ID: <20260728230228.781303-1-dave@stgolabs.net> (raw)
Since the target_list union is fixed at 8 entries, if a CXL switch
device has an IW value larger than 8 (such as 12 or 16 way), things
can go bad:
BUG: KASAN: stack-out-of-bounds in devm_cxl_enumerate_decoders+0xefd/0x1b00
Read of size 1 at addr ffff8881003bf180 by task kworker/u16:0/12
kasan_report+0xe0/0x110
devm_cxl_enumerate_decoders+0xefd/0x1b00
cxl_port_add_dport+0x9c/0x200
devm_cxl_enumerate_ports+0xa36/0x1190
cxl_mem_probe+0x26f/0x710
The buggy address belongs to stack of task kworker/u16:0/12
and is located at offset 40 in frame:
devm_cxl_enumerate_decoders+0x0/0x1b00
This frame has 1 object:
[32, 40) 'target_list'
While this is out of spec (see Table 123), we can robustify and
just reject such a decoder - noting that cxl_port_setup_targets()
already refuses to program more than 8 ways.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Fixes: d17d0540a0db ("cxl/core/hdm: Add CXL standard decoder enumeration to the core")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
drivers/cxl/core/hdm.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
index 0c80b76a5f9b..87bdadeccb5f 100644
--- a/drivers/cxl/core/hdm.c
+++ b/drivers/cxl/core/hdm.c
@@ -1084,6 +1084,13 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
cxld->interleave_ways, cxld->interleave_granularity);
if (!cxled) {
+ if (cxld->interleave_ways > ARRAY_SIZE(target_list.target_id)) {
+ dev_warn(&port->dev,
+ "decoder%d.%d: Invalid target list (iw: %d)\n",
+ port->id, cxld->id, cxld->interleave_ways);
+ return -EINVAL;
+ }
+
lo = readl(hdm + CXL_HDM_DECODER0_TL_LOW(which));
hi = readl(hdm + CXL_HDM_DECODER0_TL_HIGH(which));
target_list.value = (hi << 32) + lo;
--
2.39.5
next reply other threads:[~2026-07-28 23:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 23:02 Davidlohr Bueso [this message]
2026-07-28 23:17 ` [PATCH] cxl/hdm: Robustify decoder target list reads sashiko-bot
2026-07-28 23:45 ` Alison Schofield
2026-07-29 16:36 ` Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728230228.781303-1-dave@stgolabs.net \
--to=dave@stgolabs.net \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox