Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Jiang" <dave.jiang@intel.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v4 4/6] cxl/test: Add hierarchy enumeration support for type2 device
Date: Thu, 11 Jun 2026 15:31:50 +0000	[thread overview]
Message-ID: <20260611153151.4A7D31F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611152124.3656434-5-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The topology teardown functions remove devices in forward (parent-to-child) order, causing use-after-free and double-free vulnerabilities.
- [High] Double `platform_device_put()` on `cxl_acpi` when `cxl_mock_platform_device_add()` fails.
--

commit 7f72f92a89170bc076d1c5ae46854f2ff2fcf32d
Author: Dave Jiang <dave.jiang@intel.com>

cxl/test: Add hierarchy enumeration support for type2 device

Add enumeration of type2 device hierarchy in cxl-test. The type2 device
is setup to be directly attached to a root port instead of rp -> switch
-> device that type3 hierarchy is setup..

> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index 71b6203d2fcf0..de4124afa1328 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
[ ... ]
> @@ -2049,6 +2137,92 @@ static int cxl_switches_populate(void)
>  	return 0;
>  }
>  
> +static void cxl_type2_topo_exit(void)
> +{
> +	host_bridges_remove();
> +	cxl_rootports_remove();
> +}

[Severity: High]
Does this topology teardown order cause a use-after-free? When the parent
device (host bridge) is removed, the driver core recursively unregisters and
frees its child devices. It seems that calling cxl_rootports_remove() after
host_bridges_remove() will operate on already-freed platform_device
pointers. Should the teardown be done in bottom-up (reverse) order?

> +
> +static int cxl_type2_topo_init(void)
> +{
[ ... ]
> +static void cxl_type3_topo_exit(void)
> +{
> +	host_bridges_remove();
> +	cxl_rootports_remove();
> +	cxl_switches_remove();
> +	cxl_single_topo_exit();
> +	cxl_rch_topo_exit();
> +}

[Severity: High]
Similarly here in cxl_type3_topo_exit(), does removing parent devices before
their children cause the subsequent removal functions to access freed memory?

[ ... ]
> @@ -2122,7 +2280,7 @@ static __init int cxl_test_init(void)
>  
>  	rc = cxl_mock_platform_device_add(cxl_acpi, NULL);
>  	if (rc)
> -		goto err_rch;
> +		goto err_root;
>  
>  	rc = cxl_mem_init();
>  	if (rc)
> @@ -2138,16 +2296,8 @@ static __init int cxl_test_init(void)
>  	cxl_mem_exit();
>  err_root:
>  	platform_device_put(cxl_acpi);

[Severity: High]
If cxl_mock_platform_device_add() fails, it drops the reference to cxl_acpi
before returning. Jumping to err_root will call platform_device_put()
a second time on the same pointer. Does this result in a double-free? 

In the pre-patch code, the error path jumped past this to err_rch, which
bypassed the extraneous put.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260611152124.3656434-1-dave.jiang@intel.com?part=4

  reply	other threads:[~2026-06-11 15:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 15:21 [PATCH v4 0/6] cxl: Add CXL type2 accelerator support for cxl_test Dave Jiang
2026-06-11 15:21 ` [PATCH v4 1/6] cxl/test: Add test for module parameters Dave Jiang
2026-06-11 15:34   ` sashiko-bot
2026-06-11 15:21 ` [PATCH v4 2/6] cxl/test: Add type2 support for mock CFMWS0 Dave Jiang
2026-06-11 15:38   ` sashiko-bot
2026-06-11 15:21 ` [PATCH v4 3/6] cxl/test: Refactor platform device enumerations Dave Jiang
2026-06-11 15:21 ` [PATCH v4 4/6] cxl/test: Add hierarchy enumeration support for type2 device Dave Jiang
2026-06-11 15:31   ` sashiko-bot [this message]
2026-06-11 15:21 ` [PATCH v4 5/6] cxl/test: Fixup hdm init for auto region to support type2 Dave Jiang
2026-06-11 15:44   ` sashiko-bot
2026-06-11 15:21 ` [PATCH v4 6/6] cxl/test: Add cxl_test accelerator driver Dave Jiang
2026-06-11 15:32   ` sashiko-bot
2026-06-11 15:41     ` Dave Jiang

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=20260611153151.4A7D31F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dave.jiang@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