Skip to content

pps: generators: fix use-after-free on unregister with the file open

Danish Khateeb lkml stable 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 5 repliesIn review
  2. v12 patches 1 replySuperseded

Changes in v2 from the cover letter

- New 3/4 and 4/4, suggested by Rodolfo.
- 1/4 and 2/4 are unchanged.
- v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4pps: generators: fix use-after-free when closing a removed devicedrivers/pps/generators/pps_gen.c include/linux/pps_gen_kernel.h+32 -331 reply
2/4pps: generators: don't use the driver's info after unregisterdrivers/pps/generators/pps_gen.c include/linux/pps_gen_kernel.h+28 -51 reply
3/4pps: generators: stop the generator on unregisterdrivers/pps/generators/pps_gen.c+10 -11 reply
4/4pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregisterdrivers/pps/generators/pps_gen.c+8 -21 reply

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchRodolfo Giometti
SeriesA-b
1/4A-b
2/4A-b
3/4A-b
4/4A-b

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

Read the v2 thread

Cover letter [PATCH v2 0/4] pps: generators: fix use-after-free on unregister with the file open

This fixes what goes wrong when a PPS generator is unregistered while userspace is using it:

1/4: closing the file frees pps_gen in ->release(), and __fput() then calls cdev_put() on the cdev embedded in it. pps.c had the same bug before commit c79a39dc8d06 ("pps: Fix a use-after-free"). Fixed with cdev_device_add().

2/4: the ioctls keep using the driver's pps_gen_source_info: TIO's devm memory after an unbind, and pps_gen-dummy's module data and code after an rmmod. They now return -ENODEV, as PPS_KC_BIND does for a removed PPS device since commit 3649f9a6b897.

3/4: a PPS_GEN_SETENABLE, or a write to "enable", between the driver stopping its timer and the unregister starts the timer again, and it then outlives the driver. The core now stops the generator on unregister.

4/4: a reader in PPS_GEN_FETCHEVENT is now woken up on unregister and gets -ENODEV, instead of sleeping until a signal.

Yibo Tan's "pps: generators: Pin dummy provider while a file is open"
[1] keeps the dummy module loaded while its file is open. That covers only the dummy rmmod case; a device such as TIO can still be unbound, so 2/4 is needed either way.

Changes in v2:
- New 3/4 and 4/4, suggested by Rodolfo.
- 1/4 and 2/4 are unchanged.
- v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/

Danish Khateeb (4):
pps: generators: fix use-after-free when closing a removed device
pps: generators: don't use the driver's info after unregister
pps: generators: stop the generator on unregister
pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregister

 drivers/pps/generators/pps_gen.c | 111 ++++++++++++++++++++-----------
 include/linux/pps_gen_kernel.h   |   4 +-
 2 files changed, 76 insertions(+), 39 deletions(-)

base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e

Signature · 1 line
2.55.0