mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>
Cc: Johan Hovold <johan@kernel.org>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Daniel Scally <djrscally@gmail.com>,
	 Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Bartosz Golaszewski <brgl@kernel.org>,
	driver-core@lists.linux.dev,  linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org,  stable@vger.kernel.org
Subject: [PATCH 0/3] driver core: swnode: fix release with shared primary fwnode
Date: Wed, 02 Dec 2026 17:34:48 -0800	[thread overview]
Message-ID: <20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com> (raw)

This series fixes secondary software node reference count corruption
and premature detachment when a child device shares its parent's
primary firmware node that has a secondary software node attached,
causing reference count underflow and use-after-free in the ACPI case
or early detachment and a leaked reference and sysfs link in the
non-ACPI case.

The issue came up while converting Windows ACPI GPIO lookups in
drivers/mfd/arizona-spi.c to a secondary software node, and also
affects existing ACPI MFD parents sharing their companion fwnode with
child platform devices such as
drivers/platform/x86/x86-android-tablets/lenovo.c.

When an ACPI-shared primary firmware node is detached from a child via
set_primary_fwnode(..., NULL), the child's firmware node pointer is
still left pointing to the parent's secondary software node, and
platform_device_release() drops an extra reference per child via
device_remove_software_node() or fwnode_handle_put(). When a non-ACPI
shared primary node stays attached through release,
device_remove_software_node() unconditionally clears the shared
secondary link and drops one of the parent's references, leaving the
other reference and sysfs link leaked.

The first patch adds a per-device flag tracking whether the device
attached a secondary software node, uses it in set_primary_fwnode() to
avoid leaving a shared primary node's secondary node on the child or
modifying the secondary link unless owned by the device, and gates
secondary software node removal and managed creation reference release
on that flag.

The second patch replaces the un-refcounted owner pointer in struct
swnode with a managed bitfield now that per-device ownership is tracked
via the new device flag.

The third patch adds KUnit regression tests covering shared primary
fwnodes with unmanaged and managed secondary software nodes, detachment
before release, child-owned secondary nodes on shared primary fwnodes,
release of unregistered devices with managed software nodes, and
device_remove_software_node() on a registered managed device.

This series is intentionally kept minimal for stable backporting.
Storing the secondary pointer directly on the shared struct
fwnode_handle still leaves broader limitations unaddressed:
set_primary_fwnode() only detects direct parent sharing (not grandparent
or sibling sharing), parent and child or sibling devices sharing a
primary node still contend for a single secondary slot, and cross-device
lookups of fwnode->secondary are not synchronized against concurrent
removal. A separate follow-up (such as an immutable composite
fwnode_handle) would be needed to address those cleanly.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Dmitry Torokhov (3):
      driver core: swnode: only release owned secondary software nodes
      software node: replace owner pointer with managed bitfield
      driver core: platform: tests: add shared primary fwnode swnode tests

 drivers/base/core.c                      |  15 +-
 drivers/base/swnode.c                    |  19 +-
 drivers/base/test/platform-device-test.c | 328 +++++++++++++++++++++++++++++++
 include/linux/device.h                   |   7 +
 4 files changed, 358 insertions(+), 11 deletions(-)
---
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
change-id: 20261201-swnode-shared-primary-fix-aa415f344a97

Thanks.

-- 
Dmitry


             reply	other threads:[~2026-12-03  1:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  1:34 Dmitry Torokhov [this message]
2026-12-03  1:34 ` [PATCH 1/3] driver core: swnode: only release owned secondary software nodes Dmitry Torokhov
2026-12-03  1:34 ` [PATCH 2/3] software node: replace owner pointer with managed bitfield Dmitry Torokhov
2026-12-03  1:34 ` [PATCH 3/3] driver core: platform: tests: add shared primary fwnode swnode tests Dmitry Torokhov
2026-12-03 11:35 ` [PATCH 0/3] driver core: swnode: fix release with shared primary fwnode Andy Shevchenko

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=20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --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-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®