Skip to content

char: misc: Introduce misc_sync to fix UAF

Tzung-Bi Shih chrome-platform lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8char: misc: Simplify locking with guard()drivers/char/misc.c+11 -210 replies
2/8char: misc: Introduce misc_find() helperdrivers/char/misc.c+23 -200 replies
3/8char: misc: Introduce misc_sync_register()drivers/char/misc.c include/linux/miscdevice.h+132 -15 replies
4/8char: misc: Use SRCU to protect list traversaldrivers/char/misc.c+48 -360 replies
5/8platform/chrome: cros_ec_chardev: Introduce chardev_datadrivers/platform/chrome/cros_ec_chardev.c+39 -120 replies
6/8platform/chrome: cros_ec_chardev: Move data to chardev_pdatadrivers/platform/chrome/cros_ec_chardev.c+20 -160 replies
7/8platform/chrome: cros_ec_chardev: Add event relayerdrivers/platform/chrome/cros_ec_chardev.c+29 -30 replies
8/8platform/chrome: cros_ec_chardev: Use misc_sync_register()drivers/platform/chrome/cros_ec_chardev.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/8] char: misc: Introduce misc_sync to fix UAF

This series introduces misc_sync to address potential Use-After-Free errors when a device is deregistered while file operations are still in progress or files remain open. It then adopts the mechanism in cros_ec_chardev driver.

- Patches 1 and 2 are independent refactors in the misc subsystem. These are safe cleanups and should be fine to apply.

- Patch 3 is the initial Proof-of-Concept for misc_sync. It uses a global lock to serialize file operations, so a performance downgrade is expected.

- Patch 4 is an improvement over the PoC that replaces the global lock with SRCU for list traversal in the file operations, avoiding performance bottlenecks.

- Patches 5 to 7 are preparation steps in cros_ec_chardev driver. They introduce reference counting for platform driver data and an event relayer. This removes the direct access to ec_dev->event_notifier in cros_ec_chardev_release(), which is a prerequisite for using misc_sync safely in this driver.

- Patch 8 switches cros_ec_chardev driver to use misc_sync.

Tzung-Bi Shih (8):
char: misc: Simplify locking with guard()
char: misc: Introduce misc_find() helper
char: misc: Introduce misc_sync_register()
char: misc: Use SRCU to protect list traversal platform/chrome: cros_ec_chardev: Introduce chardev_data platform/chrome: cros_ec_chardev: Move data to chardev_pdata platform/chrome: cros_ec_chardev: Add event relayer platform/chrome: cros_ec_chardev: Use misc_sync_register()

 drivers/char/misc.c                       | 228 +++++++++++++++++-----
 drivers/platform/chrome/cros_ec_chardev.c | 113 ++++++++---
 include/linux/miscdevice.h                |  10 +
 3 files changed, 272 insertions(+), 79 deletions(-)
Signature · 1 line
2.51.0