From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Bartosz Golaszewski <brgl@kernel.org>,
Andi Shyti <andi.shyti@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
driver-core@lists.linux.dev, linux-acpi@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 4/8] software node: ignore primary nodes in device_remove_software_node()
Date: Wed, 18 Nov 2026 12:39:21 +0200 [thread overview]
Message-ID: <av2AWRsjQfrmr5A3@ashevche-desk.local> (raw)
In-Reply-To: <av1xsrv8zNIEOtxg@hovoldconsulting.com>
On Wed, Nov 18, 2026 at 10:36:50AM +0100, Johan Hovold wrote:
> On Tue, Nov 17, 2026 at 04:01:50PM +0200, Andy Shevchenko wrote:
> > On Tue, Nov 17, 2026 at 11:13:32AM +0100, Johan Hovold wrote:
...
> > > +++ b/drivers/i2c/i2c-core-base.c
> >
> > > void i2c_unregister_device(struct i2c_client *client)
> > > {
> > > struct fwnode_handle *fwnode;
> > > - bool fwnode_is_software_node;
> > >
> > > if (IS_ERR_OR_NULL(client))
> > > return;
> >
> > > - fwnode_is_software_node = is_software_node(fwnode);
> > > device_remove_software_node(&client->dev);
> > > /*
> > > - * If the firmware node is a software node, its reference count
> > > - * was decremented by device_remove_software_node().
> > > + * Must be done after device_remove_software_node() which may have
> > > + * freed a secondary firmware node and cleared the fwnode pointer.
> > > */
> > > - if (!fwnode_is_software_node)
> > > - fwnode_handle_put(fwnode);
> > > + fwnode_handle_put(client->dev.fwnode);
> >
> > We have fwnode getter, so better use it
> >
> > fwnode_handle_put(dev_fwnode(&client->dev));
>
> I used the fwnode pointer directly here on purpose since that is the
> pointer that gets cleared by device_remove_software_node() and which the
> comment refers to.
>
> This hopefully also reduces the risk of anyone introducing a UAF by
> reusing the fwnode variable (or the compiler doing something silly since
> dev_fwnode() returns the dev->of_node->fwnode when CONFIG_OF is
> enabled).
This makes explicit use of the member outside of driver core. It adds
an unneeded burden on the possible changes in the future if we decide
to make the fwnode stuff being hidden in struct device (in a sense
of having say list head instead of that). I think we really need to
mark fwnode with __private there.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-18 10:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:13 [PATCH v3 0/8] driver core: platform: fix swnode use-after-free on device release Johan Hovold
2026-11-17 10:13 ` [PATCH v3 1/8] " Johan Hovold
2026-11-17 10:13 ` [PATCH v3 2/8] i2c: core: fix swnode use-after-free on client deregistration Johan Hovold
2026-11-17 10:13 ` [PATCH v3 3/8] software node: fix device_add_software_node() kernel doc Johan Hovold
2026-11-17 15:06 ` Rafael J. Wysocki (Intel)
2026-11-17 10:13 ` [PATCH v3 4/8] software node: ignore primary nodes in device_remove_software_node() Johan Hovold
2026-11-17 14:01 ` Andy Shevchenko
2026-11-18 9:36 ` Johan Hovold
2026-11-18 10:39 ` Andy Shevchenko [this message]
2026-11-17 10:13 ` [PATCH v3 5/8] driver core: platform: warn on bad fwnode assignment Johan Hovold
2026-11-17 15:24 ` Rafael J. Wysocki (Intel)
2026-11-17 10:13 ` [PATCH v3 6/8] driver core: platform: tests: fix swnode reuse test description Johan Hovold
2026-11-17 10:13 ` [PATCH v3 7/8] software node: fix software_node_notify() primary node comment Johan Hovold
2026-11-17 15:25 ` Rafael J. Wysocki (Intel)
2026-11-17 10:13 ` [PATCH v3 8/8] device property: fix fwnode_get_next_child_node() comments Johan Hovold
2026-11-17 15:26 ` Rafael J. Wysocki (Intel)
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=av2AWRsjQfrmr5A3@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=andi.shyti@kernel.org \
--cc=brgl@kernel.org \
--cc=dakr@kernel.org \
--cc=djrscally@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=johan@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=wsa+renesas@sang-engineering.com \
/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
all inboxes | Powered by JetHome®