]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
ptp: rework ptp_clock_unregister() to disable events
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tue, 16 Sep 2025 21:36:03 +0000 (22:36 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 17 Sep 2025 22:04:09 +0000 (15:04 -0700)
commita60fc3294a377204664b5484e4a487fa124155da
tree94bc0b7dc06f4fe2f65fb7e505bb6fc722b94b54
parent0fcb1dc3e8044a20f584c3dbdf01ce6d2234ca4c
ptp: rework ptp_clock_unregister() to disable events

The ordering of ptp_clock_unregister() is not ideal, as the chardev
remains published while state is being torn down, which means userspace
can race with the kernel teardown. There is also no cleanup of enabled
pin settings nor of the internal PPS event, which means enabled events
can still forward into the core, dereferencing a free'd pointer.

Rework the ordering of cleanup in ptp_clock_unregister() so that we
unpublish the posix clock (and user chardev), disable any pins that
have EXTTS events enabled, disable the PPS event, and then clean up
the aux work and PPS source.

This avoids potential use-after-free and races in PTP clock driver
teardown.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com> # ocelot, sja1105, netdevsim, vclocks
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Link: https://patch.msgid.link/E1uydLH-000000061DM-2gcV@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/ptp/ptp_chardev.c
drivers/ptp/ptp_clock.c
drivers/ptp/ptp_private.h