Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alucerop@amd.com
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v1 3/4] cxl/memdev: Add support for multi PF devices
Date: Tue, 22 Sep 2026 17:56:13 +0000	[thread overview]
Message-ID: <20260922175614.13F031F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260921191239.4249-4-alucerop@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] cxl: UAF / memory corruption due to omitted no_free_ptr() in cxl_get_pf0_memdev()
- [High] cxl: NULL pointer dereference when cxlmd->attach is NULL
- [High] cxl: data race and NULL pointer dereference due to missing memory barriers
--

commit 8b8a34ac3eece08d08d13bded379e20360255e65
Author: Alejandro Lucero <alucerop@amd.com>

cxl/memdev: Add support for multi PF devices

This commit adds a device link between the CXL region a PF0 memdev is
attached to and the non-PF0 wanting to use the CXL region. A CXL region
release will trigger such a PF to be released from its driver first,
keeping the CXL memory use safe.

> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index b3419df586b9c..67be02faa7e14 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
[ ... ]
> @@ -802,6 +802,72 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
> +struct cxl_memdev *cxl_get_pf0_memdev(struct device *pf0, struct device *pfx,
> +				      struct range *range)
> +{
> +	struct cxl_attach_region *attach;
> +	struct cxl_memdev *cxlmd;
> +	struct device *mem_dev __free(put_device) =
> +		bus_find_device(&cxl_bus_type, NULL, pf0,
> +				match_memdev_by_parent_device);
> +
> +	if (!mem_dev)
> +		return ERR_PTR(-ENODEV);
> +
> +	cxlmd = to_cxl_memdev(mem_dev);
> +
> +	/*
> +	 * we got the cxl_memdev and the implicit get_device in bus_find_device
> +	 * makes the next steps safe.
> +	 */
> +	attach = container_of(cxlmd->attach, struct cxl_attach_region, attach);

[Severity: High]
If cxlmd->attach is NULL (e.g. for a standard class memory device initialized
via devm_cxl_add_memdev), does container_of() evaluate to NULL here since the
member is at offset 0?

> +
> +	/*
> +	 * The cxlmd object does exist and it can be found in the cxl bus after
> +	 * creation but before attach probe setting the proper HPA range. If so,
> +	 * the caller will need to try later.
> +	 */
> +	if (attach->hpa_range.end == -1)

[Severity: High]
Could this lead to a NULL pointer dereference when accessing
attach->hpa_range.end if attach evaluated to NULL above?

Additionally, since attach->hpa_range.end is checked locklessly to determine
if initialization is complete, could CPU or compiler reordering cause the
subsequent read of attach->cxlr to see an uninitialized or NULL value?

> +		return ERR_PTR(-EPROBE_DEFER);
> +
> +	/*
> +	 * Create the device link between the region and the consumer device.
> +	 * AUTOREMOVE_CONSUMER means the link implicitly to be removed if the
> +	 * consumer unbinds first with no consequences for the supplier.
> +	 */
> +	if (!device_link_add(pfx, &attach->cxlr->dev, DL_FLAG_AUTOREMOVE_CONSUMER))

[Severity: High]
If attach->cxlr is read as NULL due to missing memory barriers or acquire
semantics, could this dereference lead to a kernel panic?

> +		return ERR_PTR(-ENODEV);
> +
> +	range->start = attach->hpa_range.start;
> +	range->end = attach->hpa_range.end;
> +
> +	return to_cxl_memdev(mem_dev);

[Severity: High]
Will the device reference acquired by bus_find_device() be unconditionally
dropped here at scope exit due to the __free(put_device) cleanup attribute?

Should this return to_cxl_memdev(no_free_ptr(mem_dev)) to inhibit the
cleanup and safely transfer ownership of the acquired reference to the caller?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921191239.4249-1-alucerop@amd.com?part=3

  parent reply	other threads:[~2026-09-22 17:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 19:12 [PATCH v1 0/4] Type2 multipf support alucerop
2026-09-21 19:12 ` [PATCH v1 1/4] driver core: Rely on supplier driver binding at link creation alucerop
2026-09-22 17:56   ` sashiko-bot
2026-09-22 21:39   ` Maxime Chevallier
2026-09-23  8:49     ` Lucero Palau, Alejandro
2026-09-23  9:58       ` Lucero Palau, Alejandro
2026-09-24  8:59         ` Lucero Palau, Alejandro
2026-09-21 19:12 ` [PATCH v1 2/4] cxl/region: Add region reference in memdev attach alucerop
2026-09-22 17:56   ` sashiko-bot
2026-09-21 19:12 ` [PATCH v1 3/4] cxl/memdev: Add support for multi PF devices alucerop
2026-09-21 23:07   ` Dave Jiang
2026-09-22 14:07     ` Lucero Palau, Alejandro
2026-09-22 16:39       ` Dave Jiang
2026-09-22 17:56   ` sashiko-bot [this message]
2026-09-21 19:12 ` [PATCH v1 4/4] sfc: add multipf support alucerop
2026-09-22 17:56   ` sashiko-bot
2026-09-24  1:15   ` Jonathan Cameron
2026-09-25 11:16     ` Lucero Palau, Alejandro
2026-09-25 20:24       ` Jonathan Cameron
2026-09-23 20:00 ` [syzbot ci] Re: Type2 " syzbot ci

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=20260922175614.13F031F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alucerop@amd.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