From: sashiko-bot@kernel.org
To: "Alison Schofield" <alison.schofield@intel.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path
Date: Tue, 21 Jul 2026 17:50:32 +0000 [thread overview]
Message-ID: <20260721175033.0B0D41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <3a36953b5c665cb9544ba61dafbea0b0fa508c77.1784654628.git.alison.schofield@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Hardware-provided interleave ways can exceed switch decoder target count, causing out-of-bounds heap writes.
--
--- Patch [1]: [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path ---
commit bd336b4d1e6d9374287b7dbe87f0953733e4d653
Author: Alison Schofield <alison.schofield@intel.com>
cxl/region: Fix use-after-free in find_pos_and_ways() error path
The error path releases its reference to a switch decoder before logging an
error that includes the decoder name. If the released reference is the last
one, the decoder can be freed before the error message accesses its name.
Drop the reference after the error is reported.
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 1e211542b6b64..c86dd9d55e939 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1938,8 +1938,6 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
> break;
> }
> }
[Severity: High]
This is a pre-existing issue, but I have a question about the loop that
concludes here.
In drivers/cxl/core/region.c:find_pos_and_ways(), the code iterates up to the
interleave_ways read from the switch decoder:
*ways = cxlsd->cxld.interleave_ways;
for (int i = 0; i < *ways; i++) {
if (cxlsd->target[i] == port->parent_dport) {
*pos = i;
rc = 0;
break;
}
}
Is it possible for the hardware-provided interleave_ways to exceed the switch
decoder's actual target count (cxlsd->nr_targets)?
If the hardware control register specifies an interleave_ways value that is
larger than the capability used to size the flexible array, could this loop
read out-of-bounds from the cxlsd->target[] array?
Similarly, in drivers/cxl/core/port.c:decoder_populate_targets(), could this
mismatch also result in an out-of-bounds write when populating targets from
hardware registers without bounds checking against nr_targets?
> - put_device(dev);
> -
> if (rc)
> dev_err(port->uport_dev,
> "failed to find %s:%s in target list of %s\n",
> @@ -1947,6 +1945,8 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
> dev_name(port->parent_dport->dport_dev),
> dev_name(&cxlsd->cxld.dev));
>
> + put_device(dev);
> +
> return rc;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/3a36953b5c665cb9544ba61dafbea0b0fa508c77.1784654628.git.alison.schofield@intel.com?part=1
next prev parent reply other threads:[~2026-07-21 17:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 17:37 [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path Alison Schofield
2026-07-21 17:37 ` [PATCH v2 2/2] cxl/region: Use __free(put_device) in find_pos_and_ways() Alison Schofield
2026-07-21 23:56 ` Jonathan Cameron
2026-07-24 21:57 ` Alison Schofield
2026-07-22 5:25 ` Li Ming
2026-07-21 17:50 ` sashiko-bot [this message]
2026-07-24 21:40 ` [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path Alison Schofield
2026-07-21 23:53 ` Jonathan Cameron
2026-07-24 21:54 ` Alison Schofield
2026-07-22 5:24 ` Li Ming
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=20260721175033.0B0D41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alison.schofield@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.