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>,
driver-core@lists.linux.dev, linux-acpi@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Hans de Goede <hansg@kernel.org>
Subject: Re: [PATCH v2 2/8] i2c: core: fix swnode use-after-free on client deregistration
Date: Tue, 10 Nov 2026 12:58:15 +0200 [thread overview]
Message-ID: <avL4x_clSegBu-Qi@ashevche-desk.local> (raw)
In-Reply-To: <20261110085125.2535508-3-johan@kernel.org>
On Tue, Nov 10, 2026 at 09:51:18AM +0100, Johan Hovold wrote:
> If a client has both a primary and a secondary firmware node, the
> secondary node is accessed via the ->secondary pointer of the primary
> node.
>
> Use a temporary variable to track whether the firmware node is a
> software node and remove any software node before dropping its reference
> to avoid a use-after-free in device_remove_software_node() when
> accessing the secondary firmware node.
...
> Fixes: df6d7277e552 ("i2c: core: Do not dereference fwnode in struct device")
> Fixes: 1c24e5fc0c70 ("i2c: core: Fix double-free of fwnode in i2c_unregister_device()")
> Cc: stable@vger.kernel.org # 6.16
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Hans de Goede <hansg@kernel.org>
Can we keep these two Cc out of the commit message?
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
...
> struct fwnode_handle *fwnode;
> + bool fwnode_is_software_node;
>
> if (IS_ERR_OR_NULL(client))
> return;
> @@ -1066,14 +1067,14 @@ void i2c_unregister_device(struct i2c_client *client)
> else if (is_acpi_device_node(fwnode))
> acpi_device_clear_enumerated(to_acpi_device_node(fwnode));
>
> + fwnode_is_software_node = is_software_node(fwnode);
> + device_remove_software_node(&client->dev);
> /*
> - * If the primary fwnode is a software node it is free-ed by
> - * device_remove_software_node() below, avoid double-free.
> + * If the firmware node is a software node, its reference count
> + * was decremented by device_remove_software_node().
> */
> - if (!is_software_node(fwnode))
> + if (!fwnode_is_software_node)
> fwnode_handle_put(fwnode);
Do I understand correctly that this is a dup with the platform device case? Can
we make a helper (on swnode API level) to cover any other existing or potential
case to avoid similar issues in the future?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-10 10:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 8:51 [PATCH v2 0/8] driver core: platform: fix swnode use-after-free on device release Johan Hovold
2026-11-10 8:51 ` [PATCH v2 1/8] " Johan Hovold
2026-11-10 8:51 ` [PATCH v2 2/8] i2c: core: fix swnode use-after-free on client deregistration Johan Hovold
2026-11-10 10:58 ` Andy Shevchenko [this message]
2026-11-10 11:15 ` Johan Hovold
2026-11-10 8:51 ` [PATCH v2 3/8] swnode: fix device_add_of_node() kernel doc Johan Hovold
2026-11-10 10:42 ` Johan Hovold
2026-11-10 11:00 ` Andy Shevchenko
2026-11-10 8:51 ` [PATCH v2 4/8] swnode: ignore primary nodes in device_remove_software_node() Johan Hovold
2026-11-10 11:05 ` Andy Shevchenko
2026-11-10 8:51 ` [PATCH v2 5/8] driver core: platform: warn on bad fwnode assignment Johan Hovold
2026-11-10 10:47 ` Johan Hovold
2026-11-10 8:51 ` [PATCH v2 6/8] driver core: platform: tests: fix swnode reuse test description Johan Hovold
2026-11-10 8:51 ` [PATCH v2 7/8] swnode: fix software_node_notify() primary node comment Johan Hovold
2026-11-10 8:51 ` [PATCH v2 8/8] device property: fix fwnode_get_next_child_node() comments Johan Hovold
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=avL4x_clSegBu-Qi@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=hansg@kernel.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=stable@vger.kernel.org \
/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®