Linux-i3c Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <linux-pci@vger.kernel.org>, <Frank.Li@kernel.org>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	<linux-i3c@lists.infradead.org>
Subject: Re: [PATCH V3 07/14] i3c: master: Fix potential UAF in i3c_device_match()
Date: Tue, 4 Aug 2026 20:14:18 +0300	[thread overview]
Message-ID: <603aff8f-b7dc-4853-8fe6-8cecdb83e9f0@intel.com> (raw)
In-Reply-To: <20260804151107.333DF1F000E9@smtp.kernel.org>

On 04/08/2026 18:11, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> 
> New issues:
> - [High] Removal of the NULL check for `i3cdev->desc` introduces a guaranteed NULL pointer dereference in concurrent unregistration paths.

Not valid

> - [High] Unconditional access to `i3cdev->bus` in `i3c_device_match()` causes a Use-After-Free if the parent master controller has been freed.

Makes no sense.

> 
> Pre-existing issues:
> - [High] Preexisting use-after-free race condition in AMD SBRMI (`sbrmi_i3c_probe`) accessing `i3cdev->desc` without holding the bus lock.
> --
> 
> --- Patch [7]: [PATCH V3 07/14] i3c: master: Fix potential UAF in i3c_device_match() ---
> commit d088359c0cccb56067d426e92d0a49f24376de53
> Author: Adrian Hunter <adrian.hunter@intel.com>
> 
> i3c: master: Fix potential UAF in i3c_device_match()
> 
> This commit protects access to i3cdev->desc with the bus normal-use lock
> in i3c_device_match() to prevent a use-after-free during concurrent
> descriptor replacement. It also removes the NULL check for i3cdev->desc,
> assuming the lock guarantees validity.
> 
>> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
>> index 947ab3c681d5e..e7ea410078891 100644
>> --- a/drivers/i3c/master.c
>> +++ b/drivers/i3c/master.c
>> @@ -347,8 +347,10 @@ static int i3c_device_match(struct device *dev, const struct device_driver *drv)
>>  	i3cdev = dev_to_i3cdev(dev);
>>  	i3cdrv = drv_to_i3cdrv(drv);
>>  
>> -	if (i3cdev->desc && i3cdev->desc->boardinfo)
>> +	i3c_bus_normaluse_lock(i3cdev->bus);
> 
> [Severity: High]
> Does accessing i3cdev->bus here risk a use-after-free if the parent master
> controller has been freed?
> 
> During unregistration, i3c_master_unregister() unregisters child devices,
> and device_del() drops the child's reference to the parent by calling
> put_device(parent). Once unregistration finishes, the parent platform device
> unbinds and its devres frees the I3C master struct. 
> 
> If a concurrent bus_for_each_dev() iterator (such as from driver registration)

That makes no sense.

> holds a reference to the child device, the child outlives the parent. The
> child's i3cdev->bus pointer would then remain pointing to the freed master
> memory, leading to a use-after-free when acquiring the lock.
> 
>> +	if (i3cdev->desc->boardinfo)
> 
> [Severity: High]
> Could removing the NULL check for i3cdev->desc lead to a NULL pointer
> dereference during concurrent unregistration?
> 
> In i3c_master_unregister_i3c_devs(), i3cdev->dev->desc = NULL; is set without
> holding any bus locks. 

The DAA and registration paths are already blocked by
master->shutting_down flag - refer i3c_master_shutdown()

> 
> If a concurrent driver matching thread invokes i3c_device_match(), it can
> proceed in parallel because driver_match_device() operates outside
> device_lock(). The thread acquires the bus lock, but since unregistration
> doesn't hold it, it could read desc as NULL and crash when accessing
> i3cdev->desc->boardinfo.
> 
>>  		static_addr_method = i3cdev->desc->boardinfo->static_addr_method;
>> +	i3c_bus_normaluse_unlock(i3cdev->bus);
>>  
>>  	/*
>>  	 * SETAASA-based devices need not always have a matching ID since
> 
> [Severity: High]
> This is a pre-existing issue, but I noticed a similar locking problem in
> the AMD SBRMI driver.
> 
> In drivers/misc/amd-sbi/rmi-i2c.c:sbrmi_i3c_probe():
> 
>     if (I3C_PID_INSTANCE_ID(i3cdev->desc->info.pid) != 1)
> 
> This dereferences i3cdev->desc without acquiring i3c_bus_normaluse_lock()
> or using the safe i3c_device_get_info() API.
> 
> Since probe runs holding device_lock(), it is not mutually exclusive with
> the bus maintenance write-lock used for descriptor replacement in
> __i3c_master_add_i3c_dev_locked(). If a device's address is concurrently
> re-assigned during DAA hot-join, could probe dereference a freed descriptor
> when it resumes?
> 


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

  reply	other threads:[~2026-08-04 17:14 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 13:37 [PATCH V3 00/14] i3c: Support IBI-based system wakeup Adrian Hunter
2026-08-04 13:37 ` [PATCH V3 01/14] i3c: master: Fix recursive locking during device registration Adrian Hunter
2026-08-04 14:51   ` sashiko-bot
2026-08-04 16:46   ` Frank Li
2026-08-04 16:50     ` Adrian Hunter
2026-08-04 22:10       ` Frank Li
2026-08-04 13:37 ` [PATCH V3 02/14] i3c: Fix unlocked dereference of dev->desc in i3c_device_get_supported_xfer_mode() Adrian Hunter
2026-08-04 15:09   ` sashiko-bot
2026-08-04 15:38     ` Adrian Hunter
2026-08-04 13:37 ` [PATCH V3 03/14] i3c: master: Do not treat master device as a duplicate target Adrian Hunter
2026-08-04 14:17   ` sashiko-bot
2026-08-04 16:50   ` Frank Li
2026-08-04 17:33   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 04/14] i3c: master: Fix use-after-free of master->this Adrian Hunter
2026-08-04 14:10   ` sashiko-bot
2026-08-04 15:50     ` Adrian Hunter
2026-08-04 13:38 ` [PATCH V3 05/14] i3c: Make dev->desc locking assumptions explicit Adrian Hunter
2026-08-04 14:18   ` sashiko-bot
2026-08-04 18:08   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 06/14] i3c: master: Fix potential UAF in i3c_device_uevent() Adrian Hunter
2026-08-04 15:08   ` sashiko-bot
2026-08-04 18:12   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 07/14] i3c: master: Fix potential UAF in i3c_device_match() Adrian Hunter
2026-08-04 15:11   ` sashiko-bot
2026-08-04 17:14     ` Adrian Hunter [this message]
2026-08-04 13:38 ` [PATCH V3 08/14] i3c: master: Support IBI-based wakeup capability Adrian Hunter
2026-08-04 14:05   ` sashiko-bot
2026-08-04 18:21   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 09/14] i3c: master: Report wakeup events for IBIs Adrian Hunter
2026-08-04 15:10   ` sashiko-bot
2026-08-04 16:12     ` Adrian Hunter
2026-08-04 13:38 ` [PATCH V3 10/14] i3c: master: Add helper to query bus wakeup requirements Adrian Hunter
2026-08-04 13:53   ` sashiko-bot
2026-08-04 18:52   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 11/14] i3c: master: Reject IBI requests from non-IBI-capable devices Adrian Hunter
2026-08-04 14:28   ` sashiko-bot
2026-08-04 13:38 ` [PATCH V3 12/14] i3c: mipi-i3c-hci-pci: Propagate I3C wakeup requirements to PCI Adrian Hunter
2026-08-04 15:05   ` sashiko-bot
2026-08-04 13:38 ` [PATCH V3 13/14] i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev() Adrian Hunter
2026-08-04 14:40   ` sashiko-bot
2026-08-04 19:28   ` Mukesh Savaliya
2026-08-04 13:38 ` [PATCH V3 14/14] i3c: mipi-i3c-hci: Advertise IBI wakeup capability Adrian Hunter
2026-08-04 14:45   ` 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=603aff8f-b7dc-4853-8fe6-8cecdb83e9f0@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-pci@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