ptp: Add sysfs attribute to show PTP device is safe to open RO
Subsystems (3)
PATCH v2 1/1 ptp: Add sysfs attribute to show PTP device is safe to open RO
Recent patches introduced in 6.15 implement permissions checks for PTP clocks [1]. Prior to those, a process with readonly access could modify the state of PTP devices, in particular the generation and consumption of PPS signals. This security hole was not widely exposed as userspace managing the ownership and permissions of PTP device nodes (e.g. udev) typically disabled unprivileged access entirely as a stopgap workaround.
Although the security vulnerability has been fixed in the kernel, userspace has no reliable way to detect whether the necessary permissions checks are actually in place. As a result, it must continue restricting PTP device permissions, even though unprivileged users can now be granted readonly access.
There is little precedent for fixing device permissions security hole covered by a long-standing userspace workaround. In previous cases where device permission checks were tightened [2-4], there were no userspace workarounds to remove/disable and so kernel fixes were applied silently without notifying the userspace.
A possible solution that would not require new ABI is for userspace to check the kernel version to detect whether the fix is in place. However, this approach is unreliable and error-prone, especially if backports are considered [5].
Add a readonly sysfs attribute to PTP clocks, "ro_safe", backed by a static string.
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/linux-mtd/[email protected]/
[4] https://lore.kernel.org/linux-mtd/[email protected]/
[5] https://github.com/systemd/systemd/pull/37302#issuecomment-2850510329
Changes in v2:
- Document the new sysfs node
--- Documentation/ABI/testing/sysfs-ptp | 8 ++++++++ drivers/ptp/ptp_sysfs.c | 3 +++ 2 files changed, 11 insertions(+)
Documentation/ABI/testing/sysfs-ptp +8 -0
@@ -140,3 +140,11 @@ Description: PPS events to the Linux PPS subsystem. To enable PPS events, write a "1" into the file. To disable events, write a "0" into the file. + +What: /sys/class/ptp/ptp<N>/ro_safe +Date: May 2025 +Contact: Wojtek Wasko <[email protected]> +Description: + This read-only file conveys whether the kernel + implements necessary permissions checks to allow + safe readonly access to PTP devices.
drivers/ptp/ptp_sysfs.c +3 -0
@@ -28,6 +28,8 @@ static ssize_t max_phase_adjustment_show(struct device *dev, }static DEVICE_ATTR_RO (max_phase_adjustment); +static DEVICE_STRING_ATTR_RO(ro_safe, 0444, "1\n"); +#define PTP_SHOW_INT (name, var) \ static ssize_t var##_show(struct device *dev, \ struct device_attribute *attr, char *page) \
@@ -320,6 +322,7 @@ static DEVICE_ATTR_RW(max_vclocks);static struct attribute *ptp_attrs[] = { &dev_attr_clock_name.attr, + &dev_attr_ro_safe.attr.attr, &dev_attr_max_adjustment.attr, &dev_attr_max_phase_adjustment.attr,
Signature · 1 line
2.43.5
Quoted 63 lines · Wojtek Wasko
Recent patches introduced in 6.15 implement permissions checks for PTP clocks [1]. Prior to those, a process with readonly access could modify the state of PTP devices, in particular the generation and consumption of PPS signals. This security hole was not widely exposed as userspace managing the ownership and permissions of PTP device nodes (e.g. udev) typically disabled unprivileged access entirely as a stopgap workaround.
Although the security vulnerability has been fixed in the kernel, userspace has no reliable way to detect whether the necessary permissions checks are actually in place. As a result, it must continue restricting PTP device permissions, even though unprivileged users can now be granted readonly access.
There is little precedent for fixing device permissions security hole covered by a long-standing userspace workaround. In previous cases where device permission checks were tightened [2-4], there were no userspace workarounds to remove/disable and so kernel fixes were applied silently without notifying the userspace.
A possible solution that would not require new ABI is for userspace to check the kernel version to detect whether the fix is in place. However, this approach is unreliable and error-prone, especially if backports are considered [5].
Add a readonly sysfs attribute to PTP clocks, "
ro_safe", backed by a static string.[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/linux-mtd/[email protected]/
[4] https://lore.kernel.org/linux-mtd/[email protected]/
[5] https://github.com/systemd/systemd/pull/37302#issuecomment-2850510329Changes in v2:
- Document the new sysfs nodeSigned-off-by Wojtek Wasko <[email protected]>--- Documentation/ABI/testing/sysfs-ptp | 8 ++++++++ drivers/ptp/ptp_sysfs.c | 3 +++ 2 files changed, 11 insertions(+)Documentation/ABI/testing/sysfs-ptp +8
-0@@ -140,3 +140,11 @@ Description: PPS events to the Linux PPS subsystem. To enable PPS events, write a "1" into the file. To disable events, write a "0" into the file. + +What: /sys/class/ptp/ptp<N>/ro_safe +Date: May 2025 +Contact: Wojtek Wasko <[email protected]> +Description: + This read-only file conveys whether the kernel + implements necessary permissions checks to allow + safe readonly access to PTP devices.drivers/ptp/ptp_sysfs.c +0
-0
drivers/ptp/ptp_sysfs.c static ssize_t max_phase_adjustment_show(struct device *dev, · line 31
Quoted 4 lines
drivers/ptp/ptp_sysfs.c +1
-0@@ -28,6 +28,8 @@ static ssize_t max_phase_adjustment_show(struct device *dev, }static DEVICE_ATTR_RO (max_phase_adjustment); +static DEVICE_STRING_ATTR_RO(ro_safe, 0444, "1\n");
This is not how to use sysfs, sorry. We do NOT use it for "feature flags" like this.
Userspace should do something else to determine if the feature is there or not, or just default to "do not allow" if it can not figure it out.
sorry, but this change is not ok.
greg k-h
Quoted 7 lines · Greg K-H
This is not how to use sysfs, sorry. We do NOT use it for "feature flags" like this.
Userspace should do something else to determine if the feature is there or not, or just default to "do not allow" if it can not figure it out.
sorry, but this change is not ok.
Thanks for explaining this. I'll find a way to make it work in userspace.
Wojtek