Linux CXL
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH v2 4/6] cxl/region: Validate mixed-granularity at sysfs and attach gates
Date: Tue, 16 Jun 2026 15:52:08 -0700	[thread overview]
Message-ID: <ajHTmAuRUMTNcyu4@aschofie-mobl2.lan> (raw)
In-Reply-To: <20260611180334.7EC6B1F000E9@smtp.kernel.org>

On Thu, Jun 11, 2026 at 06:03:33PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] The function `check_interleave_cap()` ignores the return values of `ways_to_eiw()` and `granularity_to_eig()`, leading to the use of uninitialized stack variables (`eiw`, `eig`) in bitmask calculations.
> --
> 
> commit 999caa321a85ce92543a94c3525b252f33aab308
> Author: Alison Schofield <alison.schofield@intel.com>
> 
> cxl/region: Validate mixed-granularity at sysfs and attach gates
> 
> Replace the same-granularity sysfs check with is_ig_allowed() to permit valid
> mixed-granularity regions. Call this helper at attach time to enforce the same
> rules for auto regions, and add an explicit span equality check for
> 3-way-family roots.
> 
> > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> > index 9fff538a9ce16..311b5052bbc8f 100644
> > --- a/drivers/cxl/core/region.c
> > +++ b/drivers/cxl/core/region.c
> 
> [ ... ]
> 
> > @@ -2096,6 +2107,8 @@ static int cxl_region_attach(struct cxl_region *cxlr,
> >  	struct cxl_dport *dport;
> >  	int rc = -ENXIO;
> >  	int stride;
> > +	int root_ways = cxlrd->cxlsd.cxld.interleave_ways;
> > +	int root_gran = cxlrd->cxlsd.cxld.interleave_granularity;
> >  
> >  	rc = check_interleave_cap(&cxled->cxld, p->interleave_ways,
> >  				  p->interleave_granularity);
> 
> [Severity: High]
> This isn't a bug introduced by this patch, but check_interleave_cap() is
> called here with potentially uninitialized (zero) values for interleave_ways
> and interleave_granularity prior to state verification.
> 
> Inside check_interleave_cap() in drivers/cxl/core/region.c, ways_to_eiw() and
> granularity_to_eig() are called but their return values are ignored:
> 
> 	ways_to_eiw(iw, &eiw);
> 	if (eiw == 0 || eiw == 8)
> 		return 0;
> 
> 	granularity_to_eig(ig, &eig);
> 	if (eiw > 8)
> 		high_pos = eiw + eig - 1;
> 	else
> 		high_pos = eiw + eig + 7;
> 	low_pos = eig + 8;
> 	interleave_mask = GENMASK(high_pos, low_pos);
> 
> If interleave_ways and interleave_granularity are 0, both ways_to_eiw() and
> granularity_to_eig() return -EINVAL, leaving eiw and eig uninitialized.
> Because eig is an uninitialized u16, low_pos can be as large as 65543.
> 
> Passing values greater than 64 to GENMASK() results in an out-of-bounds
> bitwise shift.
> 
> On systems with CONFIG_UBSAN_TRAP enabled, could this lead to a kernel panic
> if a privileged user misorders sysfs writes?

This issue is already fixed for 7.2, sitting in cxl/next here:

https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git/commit/?h=next&id=661c092f9839

cxl: Align interleave decode/encode helpers with their callers

which initializes the encode helper outputs (*eiw = 0, *eig = 0) before
the -EINVAL returns. With that, the iw == 0 case reads a defined eiw == 0
and takes the existing early return, so eig is never consumed and the
shift is never reached.

ATM, I'm thinking the v3 of this series will appear rebased on 7.2-rc1
(that has the fix) so nothing to see here.

-- Alison

> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/cover.1781199122.git.alison.schofield@intel.com?part=4

  reply	other threads:[~2026-06-16 22:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 17:47 [PATCH v2 0/6] cxl: Support mixed-granularity region interleaves Alison Schofield
2026-06-11 17:47 ` [PATCH v2 1/6] cxl/region: Validate interleave selector bits Alison Schofield
2026-06-26 11:37   ` Robert Richter
2026-06-26 15:21     ` Robert Richter
2026-07-08  2:05       ` Alison Schofield
2026-07-08  2:00     ` Alison Schofield
2026-06-11 17:47 ` [PATCH v2 2/6] cxl/region: Derive port granularity from " Alison Schofield
2026-06-26 12:09   ` Robert Richter
2026-07-08  2:09     ` Alison Schofield
2026-06-11 17:47 ` [PATCH v2 3/6] cxl/region: Account for mixed-granularity in position calculations Alison Schofield
2026-06-11 18:01   ` sashiko-bot
2026-06-12  6:21   ` Richard Cheng
2026-06-17  3:10     ` Alison Schofield
2026-06-29  6:41   ` Robert Richter
2026-07-08  1:43     ` Alison Schofield
2026-06-11 17:47 ` [PATCH v2 4/6] cxl/region: Validate mixed-granularity at sysfs and attach gates Alison Schofield
2026-06-11 18:03   ` sashiko-bot
2026-06-16 22:52     ` Alison Schofield [this message]
2026-06-11 17:47 ` [PATCH v2 5/6] cxl/test: Add a topology to test mixed-granularity regions Alison Schofield
2026-06-11 17:47 ` [PATCH v2 6/6] Documentation/cxl: Add region granularity and multi-level interleave guide Alison Schofield
2026-06-29  8:56   ` Robert Richter
2026-07-08  2:33     ` Alison Schofield

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=ajHTmAuRUMTNcyu4@aschofie-mobl2.lan \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox