Skip to content

driver core: platform: fix swnode use-after-free on device release

Johan Hovold driver-core linux-acpi linux-i2c lkml stable 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest8 patches 7 repliesIn review
  2. v28 patches 16 repliesSuperseded
  3. v12 patches 5 repliesApplied

Changes in v3 from the cover letter

- drop stray "the" in commit message (1/8)
- refer to device_add_software_node() in summary (3/8)
- use "software node:" as patch summary prefix (3,4,7/8)
- don't export fwnode_is_primary() (4/8)
- only warn when assigning a firmware node to a device which already has a software node or secondary firmware node assigned (5/8)
- fix "at" typo in commit message (8/8)
- drop one comment instead of updating, and rephrase the other (8/8)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8driver core: platform: fix swnode use-after-free on device releasedrivers/base/platform.c+4 -30 replies
2/8i2c: core: fix swnode use-after-free on client deregistrationdrivers/i2c/i2c-core-base.c+6 -50 replies
3/8software node: fix device_add_software_node() kernel docdrivers/base/swnode.c+4 -41 reply
4/8software node: ignore primary nodes in device_remove_software_node()drivers/base/base.h drivers/base/core.c drivers/base/platform.c +2 more+13 -123 replies
5/8driver core: platform: warn on bad fwnode assignmentdrivers/base/platform.c+24 -161 reply
6/8driver core: platform: tests: fix swnode reuse test descriptiondrivers/base/test/platform-device-test.c+3 -20 replies
7/8software node: fix software_node_notify() primary node commentdrivers/base/swnode.c+4 -51 reply
8/8device property: fix fwnode_get_next_child_node() commentsdrivers/base/property.c+2 -31 reply

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchWolfram SangRafael J. Wysocki (Intel)
1/8R-b
2/8A-b
3/8A-b
4/8R-b
5/8A-b
6/8A-b
7/8A-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/8] driver core: platform: fix swnode use-after-free on device release

When fixing a use-after-free regression in 7.3, I noticed that the software node implementation is internally inconsistent.

Specifically, the firmware node pointer of a struct device may point to either a primary or secondary firmware node, but in several places kernel-doc and comments suggests that the firmware node pointer always points to a primary node (cf. [1][2]).

This series fixes the 7.3 regression along with a similar issue in i2c core due which are both stem from the fact that device_remove_software_node() happens to drop a reference to a primary software node that was never added by device_add_software_node().

The next two patches clarify that device_remove_software_node() should only be used to remove nodes added by device_add_software_node() and stops touching primary nodes.

The rest of the series addresses further inconsistencies.

The first two fixes could go into 7.4 and the rest (which depends on the fixes) into 7.5. And preferably with an ack from the i2c maintainer for patches 2/8 and 4/8.

Johan

[1] 97badf873ab6 ("device property: Make it possible to use secondary firmware nodes")
[2] 3f7bddaf5d5a ("device property: add description of fwnode cases")

Changes in v3
- drop stray "the" in commit message (1/8)
- refer to device_add_software_node() in summary (3/8)
- use "software node:" as patch summary prefix (3,4,7/8)
- don't export fwnode_is_primary() (4/8)
- only warn when assigning a firmware node to a device which already has a software node or secondary firmware node assigned (5/8)
- fix "at" typo in commit message (8/8)
- drop one comment instead of updating, and rephrase the other (8/8)

Changes in v2
- rename temporary variable and amend comment as dev->fwnode is not always a primary node (patch 1/8)
- fix related UAF in i2c core (patch 2/8, new)
- fix inconsistencies in interfaces, kernel-doc, and comments (patches 3-8, new).

Johan Hovold (8):
driver core: platform: fix swnode use-after-free on device release
i2c: core: fix swnode use-after-free on client deregistration software node: fix device_add_software_node() kernel doc software node: ignore primary nodes in device_remove_software_node() driver core: platform: warn on bad fwnode assignment driver core: platform: tests: fix swnode reuse test description software node: fix software_node_notify() primary node comment device property: fix fwnode_get_next_child_node() comments

 drivers/base/base.h                      |  2 +
 drivers/base/core.c                      |  2 +-
 drivers/base/platform.c                  | 48 ++++++++++++++----------
 drivers/base/property.c                  |  5 +--
 drivers/base/swnode.c                    | 20 +++++-----
 drivers/base/test/platform-device-test.c |  5 ++-
 drivers/i2c/i2c-core-base.c              | 10 ++---
 7 files changed, 51 insertions(+), 41 deletions(-)
Signature · 1 line
2.56.1