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 v5 1/6] cxl/test: Add test for module parameters
Date: Thu, 11 Jun 2026 23:59:26 +0000	[thread overview]
Message-ID: <20260611235926.A37021F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260611234409.256765-2-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The statically allocated `hmem_test_device.work` work item is not flushed or cancelled when the `cxl_test` module unloads, leading to a potential use-after-free.
- [High] cxl_test_init() leaks the cxl_acpi platform device on the err_root error path, leading to a use-after-free.
--

commit 3d4ed8e7e71c954497e1a45802d1e8387b3fcfc0
Author: Dave Jiang <dave.jiang@intel.com>

cxl/test: Add test for module parameters

Add a test for module paraters during module init to make sure that
only one is activated.

> Add a test for module paraters during module init to make sure that

[Severity: Low]
This isn't a bug, but there is a typo (paraters) in the commit message.

> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index 296516eecfd6a..1c8ac8bdd8f7a 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c

[ ... ]

>  static __init int cxl_test_init(void)
>  {
>  	int rc, i;
>  	struct range mappable;
>  
> +	/* Enforce a single module param active at a time */
> +	if (have_multiple_modparms())
> +		return -EINVAL;
> +
>  	cxl_acpi_test();
>  	cxl_core_test();
>  	cxl_mem_test();

[ ... ]

>  	rc = hmem_test_init();
>  	if (rc)
>  		goto err_mem;
>  
>  	return 0;
>  
>  err_mem:
>  	cxl_mem_exit();
>  err_root:
>  	platform_device_put(cxl_acpi);

[Severity: High]
This is a pre-existing issue, but does cxl_test_init() leak the cxl_acpi
platform device on this err_root error path?

Since cxl_mock_platform_device_add() successfully added the device to the bus,
should this use platform_device_unregister() instead of platform_device_put()
for the already active device?

Dropping the initial allocation reference leaves the device active on the bus.
The device's mock companion data (acpi0017_mock) is statically allocated in
the module. When the module initialization fails and the module is unloaded,
the backing memory is freed, leaving a dangling pointer on the active platform
bus that can cause a kernel panic upon access.

> diff --git a/tools/testing/cxl/test/hmem_test.c b/tools/testing/cxl/test/hmem_test.c
> index 3a1a089e1721b..0fa00f7e16db5 100644
> --- a/tools/testing/cxl/test/hmem_test.c
> +++ b/tools/testing/cxl/test/hmem_test.c
> @@ -3,8 +3,9 @@
>  #include <linux/moduleparam.h>
>  #include <linux/workqueue.h>
>  #include "../../../drivers/dax/bus.h"
> +#include "mock.h"
>  
> -static bool hmem_test;
> +bool hmem_test;

[ ... ]

>  static struct hmem_platform_device hmem_test_device = {
>  	.pdev = {
>  		.name = "hmem_platform",
>  		.id = 1,
>  		.dev = {
>  			.release = hmem_test_release,
>  		},
>  	},
>  	.work = __WORK_INITIALIZER(hmem_test_device.work, hmem_test_work),
>  };

[ ... ]

>  void hmem_test_exit(void)
>  {
>  	if (hmem_test)
>  		platform_device_unregister(&hmem_test_device.pdev);
>  }

[Severity: High]
This isn't a bug introduced by this patch, but can this leak the
hmem_test_device.work item when the cxl_test module unloads, leading to a
potential use-after-free?

The hmem_test_device is statically allocated in the module. When the dax_hmem
driver binds to this device, it queues hpdev->work on dax_hmem_wq.

On module unload, hmem_test_exit() unregisters the device but fails to call
cancel_work_sync() or flush_work(). The device release callback zeroes out
the structure while the work might still be queued. Since the module memory
is then freed, the workqueue will access freed memory when it eventually
processes the work item.

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

  reply	other threads:[~2026-06-11 23:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 23:44 [PATCH v5 0/6] cxl: Add CXL type2 accelerator support for cxl_test Dave Jiang
2026-06-11 23:44 ` [PATCH v5 1/6] cxl/test: Add test for module parameters Dave Jiang
2026-06-11 23:59   ` sashiko-bot [this message]
2026-06-12  2:33   ` Richard Cheng
2026-06-12 15:35     ` Dave Jiang
2026-06-11 23:44 ` [PATCH v5 2/6] cxl/test: Add type2 support for mock CFMWS0 Dave Jiang
2026-06-11 23:56   ` sashiko-bot
2026-06-11 23:44 ` [PATCH v5 3/6] cxl/test: Refactor platform device enumerations Dave Jiang
2026-06-11 23:44 ` [PATCH v5 4/6] cxl/test: Add hierarchy enumeration support for type2 device Dave Jiang
2026-06-11 23:44 ` [PATCH v5 5/6] cxl/test: Fixup hdm init for auto region to support type2 Dave Jiang
2026-06-11 23:44 ` [PATCH v5 6/6] cxl/test: Add cxl_test accelerator driver Dave Jiang
2026-06-11 23:58   ` sashiko-bot
2026-06-12  2:44     ` Richard Cheng
2026-06-12 15:38       ` Dave Jiang
2026-06-17 14:24   ` Uwe Kleine-König
2026-06-17 17:28     ` 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=20260611235926.A37021F000E9@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