All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Akhil R" <akhilrajeev@nvidia.com>
Cc: linux-hwmon@vger.kernel.org, linux-i3c@lists.infradead.org,
	robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v7 06/12] i3c: master: match I3C device through DT and ACPI
Date: Tue, 28 Jul 2026 07:20:51 +0000	[thread overview]
Message-ID: <20260728072052.528E41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728065955.809445-7-akhilrajeev@nvidia.com>

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

Pre-existing issues:
- [High] Uninitialized stack memory read and kernel stack information leak during device unregistration when `i3cdev->desc` is NULL.
- [High] NULL pointer dereference in sysfs attribute show functions when accessed concurrently with device removal.
--

--- Patch [6]: [PATCH v7 06/12] i3c: master: match I3C device through DT and ACPI ---
commit d545f133fafb1ddd78e75d979b76dc143ac8e0b0
Author: Akhil R <akhilrajeev@nvidia.com>

i3c: master: match I3C device through DT and ACPI

This commit updates i3c_device_match() to allow SETAASA-based I3C devices
to be matched through Device Tree or ACPI. It checks if the device has a
SETAASA static address method and uses of_driver_match_device() or
acpi_driver_match_device() as fallbacks when standard ID matching is not
applicable.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 488177d95e484..f94e2410d37ba 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c

[ ... ]

> @@ -345,15 +346,32 @@ static int i3c_device_match(struct device *dev, const struct device_driver *drv)
>  {
>  	struct i3c_device *i3cdev;
>  	const struct i3c_driver *i3cdrv;
> +	u8 static_addr_method = 0;
>  
>  	if (dev->type != &i3c_device_type)
>  		return 0;
>  
>  	i3cdev = dev_to_i3cdev(dev);
>  	i3cdrv = drv_to_i3cdrv(drv);
> -	if (i3c_device_match_id(i3cdev, i3cdrv->id_table))
> +
> +	if (i3cdev->desc && i3cdev->desc->boardinfo)
> +		static_addr_method = i3cdev->desc->boardinfo->static_addr_method;
> +
> +	/*
> +	 * SETAASA-based devices need not always have a matching ID since
> +	 * it is not mandatory for such devices to implement deviceinfo
> +	 * CCC commands. Allow them to register through DT or ACPI.
> +	 */
> +	if (i3cdrv->id_table && i3c_device_match_id(i3cdev, i3cdrv->id_table))

[Severity: High]
This is a pre-existing issue, but can i3c_device_match_id() read
uninitialized stack memory here?

During device unregistration, i3c_master_unregister_i3c_devs() explicitly
sets i3cdev->dev->desc = NULL before calling device_unregister().

If driver matching occurs concurrently, i3c_device_match_id() might be called
while desc is NULL:

drivers/i3c/device.c:i3c_device_match_id() {
    struct i3c_device_info devinfo;
    ...
    i3c_device_get_info(i3cdev, &devinfo);
    manuf = I3C_PID_MANUF_ID(devinfo.pid);
    ...
}

Because i3c_device_get_info() does not initialize devinfo when desc is NULL,
this leaves stack memory to be read unconditionally and used in the matching
logic. This same uninitialized memory can also leak to userspace through the
uevent MODALIAS string in i3c_device_uevent() when desc is NULL.

Should i3c_device_match_id() be guarded by checking i3cdev->desc, similar
to how static_addr_method is guarded above?

>  		return 1;
>  
> +	if (static_addr_method & I3C_ADDR_METHOD_SETAASA) {
> +		if (of_driver_match_device(dev, drv))
> +			return 1;
> +		if (acpi_driver_match_device(dev, drv))
> +			return 1;
> +	}
> +
>  	return 0;
>  }

Also, while reviewing this, I noticed another pre-existing issue during device
unregistration:

[Severity: High]
This isn't a bug introduced by this patch, but can bcr_show() and dcr_show()
dereference a NULL pointer?

When i3c_master_unregister_i3c_devs() clears i3cdev->dev->desc = NULL, there
is a race window before the sysfs files are removed in device_del(). If a
user reads the bcr or dcr sysfs attributes during this window,
dev_to_i3cdesc() will return NULL:

drivers/i3c/master.c:bcr_show() {
    ...
    desc = dev_to_i3cdesc(dev);
    ret = sysfs_emit(buf, "0x%02x\n", desc->info.bcr);
    ...
}

Could this lead to a NULL pointer dereference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728065955.809445-1-akhilrajeev@nvidia.com?part=6

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Akhil R" <akhilrajeev@nvidia.com>
Cc: linux-hwmon@vger.kernel.org, linux-i3c@lists.infradead.org,
	robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v7 06/12] i3c: master: match I3C device through DT and ACPI
Date: Tue, 28 Jul 2026 07:20:51 +0000	[thread overview]
Message-ID: <20260728072052.528E41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728065955.809445-7-akhilrajeev@nvidia.com>

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

Pre-existing issues:
- [High] Uninitialized stack memory read and kernel stack information leak during device unregistration when `i3cdev->desc` is NULL.
- [High] NULL pointer dereference in sysfs attribute show functions when accessed concurrently with device removal.
--

--- Patch [6]: [PATCH v7 06/12] i3c: master: match I3C device through DT and ACPI ---
commit d545f133fafb1ddd78e75d979b76dc143ac8e0b0
Author: Akhil R <akhilrajeev@nvidia.com>

i3c: master: match I3C device through DT and ACPI

This commit updates i3c_device_match() to allow SETAASA-based I3C devices
to be matched through Device Tree or ACPI. It checks if the device has a
SETAASA static address method and uses of_driver_match_device() or
acpi_driver_match_device() as fallbacks when standard ID matching is not
applicable.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 488177d95e484..f94e2410d37ba 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c

[ ... ]

> @@ -345,15 +346,32 @@ static int i3c_device_match(struct device *dev, const struct device_driver *drv)
>  {
>  	struct i3c_device *i3cdev;
>  	const struct i3c_driver *i3cdrv;
> +	u8 static_addr_method = 0;
>  
>  	if (dev->type != &i3c_device_type)
>  		return 0;
>  
>  	i3cdev = dev_to_i3cdev(dev);
>  	i3cdrv = drv_to_i3cdrv(drv);
> -	if (i3c_device_match_id(i3cdev, i3cdrv->id_table))
> +
> +	if (i3cdev->desc && i3cdev->desc->boardinfo)
> +		static_addr_method = i3cdev->desc->boardinfo->static_addr_method;
> +
> +	/*
> +	 * SETAASA-based devices need not always have a matching ID since
> +	 * it is not mandatory for such devices to implement deviceinfo
> +	 * CCC commands. Allow them to register through DT or ACPI.
> +	 */
> +	if (i3cdrv->id_table && i3c_device_match_id(i3cdev, i3cdrv->id_table))

[Severity: High]
This is a pre-existing issue, but can i3c_device_match_id() read
uninitialized stack memory here?

During device unregistration, i3c_master_unregister_i3c_devs() explicitly
sets i3cdev->dev->desc = NULL before calling device_unregister().

If driver matching occurs concurrently, i3c_device_match_id() might be called
while desc is NULL:

drivers/i3c/device.c:i3c_device_match_id() {
    struct i3c_device_info devinfo;
    ...
    i3c_device_get_info(i3cdev, &devinfo);
    manuf = I3C_PID_MANUF_ID(devinfo.pid);
    ...
}

Because i3c_device_get_info() does not initialize devinfo when desc is NULL,
this leaves stack memory to be read unconditionally and used in the matching
logic. This same uninitialized memory can also leak to userspace through the
uevent MODALIAS string in i3c_device_uevent() when desc is NULL.

Should i3c_device_match_id() be guarded by checking i3cdev->desc, similar
to how static_addr_method is guarded above?

>  		return 1;
>  
> +	if (static_addr_method & I3C_ADDR_METHOD_SETAASA) {
> +		if (of_driver_match_device(dev, drv))
> +			return 1;
> +		if (acpi_driver_match_device(dev, drv))
> +			return 1;
> +	}
> +
>  	return 0;
>  }

Also, while reviewing this, I noticed another pre-existing issue during device
unregistration:

[Severity: High]
This isn't a bug introduced by this patch, but can bcr_show() and dcr_show()
dereference a NULL pointer?

When i3c_master_unregister_i3c_devs() clears i3cdev->dev->desc = NULL, there
is a race window before the sysfs files are removed in device_del(). If a
user reads the bcr or dcr sysfs attributes during this window,
dev_to_i3cdesc() will return NULL:

drivers/i3c/master.c:bcr_show() {
    ...
    desc = dev_to_i3cdesc(dev);
    ret = sysfs_emit(buf, "0x%02x\n", desc->info.bcr);
    ...
}

Could this lead to a NULL pointer dereference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728065955.809445-1-akhilrajeev@nvidia.com?part=6

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

  reply	other threads:[~2026-07-28  7:20 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  6:59 [PATCH v7 00/12] Support ACPI and SETAASA device discovery Akhil R
2026-07-28  6:59 ` Akhil R
2026-07-28  6:59 ` [PATCH v7 01/12] dt-bindings: i3c: Add mipi-i3c-static-method to support SETAASA Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:08   ` sashiko-bot
2026-07-28  7:08     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 02/12] i3c: master: Use unified device property interface Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:21   ` sashiko-bot
2026-07-28  7:21     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 03/12] i3c: master: Support ACPI enumeration of child devices Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:18   ` sashiko-bot
2026-07-28  7:18     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 04/12] i3c: master: Add support for devices using SETAASA Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:22   ` sashiko-bot
2026-07-28  7:22     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 05/12] i3c: master: Add support for devices without PID Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:20   ` sashiko-bot
2026-07-28  7:20     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 06/12] i3c: master: match I3C device through DT and ACPI Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:20   ` sashiko-bot [this message]
2026-07-28  7:20     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 07/12] i3c: dw-i3c-master: Add SETAASA as supported CCC Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:14   ` sashiko-bot
2026-07-28  7:14     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 08/12] i3c: dw-i3c-master: Add ACPI core clock frequency quirk Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:17   ` sashiko-bot
2026-07-28  7:17     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 09/12] i3c: dw-i3c-master: Add ACPI ID for Tegra410 Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:19   ` sashiko-bot
2026-07-28  7:19     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 10/12] hwmon: spd5118: Remove 16-bit addressing Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:18   ` sashiko-bot
2026-07-28  7:18     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 11/12] hwmon: spd5118: Add I3C support Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:32   ` sashiko-bot
2026-07-28  7:32     ` sashiko-bot
2026-07-28  6:59 ` [PATCH v7 12/12] arm64: defconfig: Enable I3C and SPD5118 hwmon Akhil R
2026-07-28  6:59   ` Akhil R
2026-07-28  7:24   ` sashiko-bot
2026-07-28  7:24     ` sashiko-bot

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=20260728072052.528E41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=akhilrajeev@nvidia.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=robh@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.