From: sashiko-bot@kernel.org
To: "Adrian Hunter" <adrian.hunter@intel.com>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
Frank.Li@kernel.org, linux-i3c@lists.infradead.org
Subject: Re: [PATCH] i3c: master: Fix device_register() error path
Date: Thu, 02 Jul 2026 19:00:02 +0000 [thread overview]
Message-ID: <20260702190003.8BF741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702183644.60827-1-adrian.hunter@intel.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Setting `desc->dev = NULL` on the `device_register()` error path introduces a retry loop that causes a double-put and Use-After-Free of the `boardinfo->of_node`.
- [High] Clearing `desc->dev->desc = NULL` introduces a data race and NULL pointer dereference for concurrent sysfs readers.
Pre-existing issues:
- [High] Uninitialized stack memory is leaked to userspace via sysfs uevents and attributes when an I3C device fails to register or is unregistered.
--
commit 31b28d71fcb9eca7e58c9138da77a1cc7e414f6d
Author: Adrian Hunter <adrian.hunter@intel.com>
i3c: master: Fix device_register() error path
When device_register() fails in i3c_master_register_new_i3c_devs(),
put_device() is called to drop the reference taken by
device_register(). That drops the last reference, so the device's
release callback i3c_device_release() runs and frees the i3c_device.
Link: https://lore.kernel.org/linux-i3c/20260701203053.8F3971F000E9@smtp.kernel.org/
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index f1be38a640ca1..ac408086ddcc7 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1934,7 +1934,9 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
> if (ret) {
> dev_err(&master->dev,
> "Failed to add I3C device (err = %d)\n", ret);
> + desc->dev->desc = NULL;
[Severity: High]
Does clearing desc->dev->desc here introduce a data race with concurrent
sysfs readers?
i3c_master_register_new_i3c_devs() is protected by a read lock.
If device_register() fails, we write desc->dev->desc = NULL. Concurrently,
sysfs attribute readers like bcr_show() also acquire the same read lock:
drivers/i3c/master.c:bcr_show() {
...
desc = dev_to_i3cdesc(dev);
ret = sysfs_emit(buf, "0x%02x\n", desc->info.bcr);
...
}
Can the reader fetch a NULL descriptor and crash since both paths only hold a
read lock?
[Severity: High]
This is a pre-existing issue, but can setting the descriptor to NULL cause
uninitialized stack memory to leak in the uevent and modalias paths?
When an I3C device fails to register (or is unregistered), clearing the
descriptor triggers a remove uevent. In i3c_device_uevent():
struct i3c_device_info devinfo;
...
if (i3cdev->desc)
devinfo = i3cdev->desc->info;
manuf = I3C_PID_MANUF_ID(devinfo.pid);
If i3cdev->desc is NULL, devinfo remains uninitialized on the stack but its
fields are unconditionally extracted and formatted into the modalias string.
A similar leak happens concurrently in modalias_show(). Will this leak kernel
stack memory to userspace?
> put_device(&desc->dev->dev);
> + desc->dev = NULL;
[Severity: High]
Would setting desc->dev to NULL here introduce a use-after-free of
boardinfo->of_node on subsequent retries?
If device_register() fails, put_device() calls i3c_device_release(), which
unconditionally calls of_node_put() on dev.of_node (consuming the single
reference originally held by boardinfo).
By setting desc->dev = NULL, on a subsequent execution of
i3c_master_register_new_i3c_devs() (e.g., triggered by a hot-join event or
dynamic address assignment), the loop will retry registration, allocate a
new device, and reassign the now-freed of_node. Will any further failure or
successful unregistration then trigger a double-put?
> }
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702183644.60827-1-adrian.hunter@intel.com?part=1
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
next prev parent reply other threads:[~2026-07-02 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 18:36 [PATCH] i3c: master: Fix device_register() error path Adrian Hunter
2026-07-02 18:36 ` Adrian Hunter
2026-07-02 19:00 ` sashiko-bot [this message]
2026-07-02 19:16 ` Frank Li
2026-07-02 19:16 ` Frank Li
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=20260702190003.8BF741F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-i3c@lists.infradead.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.