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
Subject: Re: [PATCH v3 06/13] i3c: master: Add support for devices without PID
Date: Thu, 23 Apr 2026 23:01:28 +0000	[thread overview]
Message-ID: <20260423230128.E9D2AC2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260423085718.70762-7-akhilrajeev@nvidia.com>

Sashiko AI review found 4 potential issue(s):
- [Critical] Pre-existing use-after-free and double-free on device registration failure.
- [High] Validation bypass allows SETDASA devices with a missing or zero PID to be incorrectly registered.
- [Medium] PID validation is completely bypassed for SETAASA devices, allowing malformed PIDs to be accepted and exposed.
- [Medium] Dead code and logic flaws in device matching and duplicate detection for dynamically discovered devices.
--

commit dbd7e3bde8caae211d2b1844852f3a001da04d22
Author: Akhil R <akhilrajeev@nvidia.com>

i3c: master: Add support for devices without PID

This commit allows devices without a 48-bit PID to register using their
static address. It primarily supports SETAASA address assignment as per the
I3C specification where a PID is not strictly required.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index de72317c9a5c73..fbe8710c4c56f8 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1842,8 +1842,17 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
>  		desc->dev->dev.type = &i3c_device_type;
>  		desc->dev->dev.bus = &i3c_bus_type;
>  		desc->dev->dev.release = i3c_device_release;
> -		dev_set_name(&desc->dev->dev, "%d-%llx", master->bus.id,
> -			     desc->info.pid);
> +
> +		/*
> +		 * For devices without PID (e.g., SETAASA devices), use
> +		 * static address for naming instead.
> +		 */
> +		if (desc->info.pid)
> +			dev_set_name(&desc->dev->dev, "%d-%llx", master->bus.id,
> +				     desc->info.pid);
> +		else
> +			dev_set_name(&desc->dev->dev, "%d-%02x", master->bus.id,
> +				     desc->info.static_addr);
>  
>  		if (desc->boardinfo)
>  			device_set_node(&desc->dev->dev, desc->boardinfo->fwnode);

This problem wasn't introduced by this patch, but does the error path further
down in this function leave a dangling pointer?

When device_register() fails, put_device() is called, which triggers
i3c_device_release() and frees desc->dev. However, desc->dev is not set to
NULL.

Later, during master teardown or driver unbind,
i3c_master_unregister_i3c_devs() iterates over the bus devices and checks
if (!i3cdev->dev) which will incorrectly pass. Could this lead to a
use-after-free and a subsequent double-free?

[ ... ]

> @@ -2288,8 +2297,18 @@ static void i3c_master_attach_boardinfo(struct i3c_dev_desc *i3cdev)
>  	struct i3c_dev_boardinfo *i3cboardinfo;
>  
>  	list_for_each_entry(i3cboardinfo, &master->boardinfo.i3c, node) {
> -		if (i3cdev->info.pid != i3cboardinfo->pid)
> -			continue;
> +		/*
> +		 * For devices without PID (e.g., SETAASA devices), match by
> +		 * static address. For devices with PID, match by PID.
> +		 */
> +		if (i3cboardinfo->pid) {
> +			if (i3cdev->info.pid != i3cboardinfo->pid)
> +				continue;
> +		} else {
> +			if (!i3cboardinfo->static_addr ||
> +			    i3cdev->info.static_addr != i3cboardinfo->static_addr)
> +				continue;
> +		}

Is it possible for the static address match to succeed here?

This function appears to be called by i3c_master_add_i3c_dev_locked() for
devices dynamically discovered via the ENTDAA procedure. During ENTDAA, the
static address is not retrieved, meaning i3cdev->info.static_addr would be
zero.

Could this cause the match against non-zero SETAASA static addresses
to always fail?

[ ... ]

> @@ -2303,8 +2322,12 @@ i3c_master_search_i3c_dev_duplicate(struct i3c_dev_desc *refdev)
>  	struct i3c_master_controller *master = i3c_dev_get_master(refdev);
>  	struct i3c_dev_desc *i3cdev;
>  
> +	if (!refdev->info.pid)
> +		return NULL;
> +

Can refdev->info.pid ever be zero here?

Similar to attach_boardinfo, this duplicate search seems to be used during
ENTDAA discovery. During ENTDAA, the hardware PID is always retrieved, so
refdev->info.pid is never zero. Devices statically configured with SETAASA
bypass these functions entirely.

[ ... ]

> @@ -2604,9 +2627,15 @@ i3c_master_add_i3c_boardinfo(struct i3c_master_controller *master,
>  
>  	boardinfo->pid = ((u64)reg[1] << 32) | reg[2];
>  
> -	if ((boardinfo->pid & GENMASK_ULL(63, 48)) ||
> -	    I3C_PID_RND_LOWER_32BITS(boardinfo->pid))
> -		return -EINVAL;
> +	/* For SETAASA devices, validate the static address instead of PID */
> +	if (boardinfo->static_addr_method & I3C_ADDR_METHOD_SETAASA) {
> +		if (!boardinfo->static_addr)
> +			return -EINVAL;
> +	} else {
> +		if ((boardinfo->pid & GENMASK_ULL(63, 48)) ||
> +		    I3C_PID_RND_LOWER_32BITS(boardinfo->pid))
> +			return -EINVAL;
> +	}

Does this bypass PID validation entirely for SETAASA devices, even if a
PID is provided?

If a device tree node explicitly provides a PID in its reg property for a
SETAASA device, it skips the reserved upper bits check. The unvalidated PID
is then stored in boardinfo->pid, and later used to name the device via
dev_set_name(). Could this expose malformed data to userspace in sysfs?

Also, if the mipi-i3c-static-method is SETDASA (or any method other than
SETAASA) and the device has a missing or zero PID, the execution reaches
this else block. Because boardinfo->pid is zero, the bitwise validation
mathematically evaluates to zero and passes.

Does this allow SETDASA devices to bypass validation and be registered
without a valid PID, violating the I3C specification?

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

  reply	other threads:[~2026-04-23 23:01 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23  8:56 [PATCH v3 00/13] Support ACPI and SETAASA device discovery Akhil R
2026-04-23  8:56 ` Akhil R
2026-04-23  8:57 ` [PATCH v3 01/13] dt-bindings: i3c: Add mipi-i3c-static-method to support SETAASA Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 11:23   ` sashiko-bot
2026-05-05 21:32     ` Rob Herring
2026-05-05 22:17       ` Guenter Roeck
2026-05-05 23:12         ` Rob Herring
2026-04-23  8:57 ` [PATCH v3 02/13] ACPICA: Read LVR from the I2C resource descriptor Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 19:35   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 03/13] i3c: master: Use unified device property interface Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 20:08   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 04/13] i3c: master: Support ACPI enumeration of child devices Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 22:11   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 05/13] i3c: master: Add support for devices using SETAASA Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 22:36   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 06/13] i3c: master: Add support for devices without PID Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 23:01   ` sashiko-bot [this message]
2026-04-23  8:57 ` [PATCH v3 07/13] i3c: master: match I3C device through DT and ACPI Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23 23:27   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 08/13] i3c: dw-i3c-master: Add SETAASA as supported CCC Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-23  8:57 ` [PATCH v3 09/13] i3c: dw-i3c-master: Add a quirk to skip clock and reset Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-24  0:18   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 10/13] i3c: dw-i3c-master: Add ACPI ID for Tegra410 Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-24  0:34   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 11/13] hwmon: spd5118: Remove 16-bit addressing Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-24  1:03   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 12/13] hwmon: spd5118: Add I3C support Akhil R
2026-04-23  8:57   ` Akhil R
2026-04-24  3:08   ` sashiko-bot
2026-04-23  8:57 ` [PATCH v3 13/13] arm64: defconfig: Enable I3C and SPD5118 hwmon Akhil R
2026-04-23  8:57   ` Akhil R

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=20260423230128.E9D2AC2BCAF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akhilrajeev@nvidia.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko@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.