Skip to content

RFC sysfs: Add hook for checking the file capability of opener

Lee, Chun-Yi linux-pm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2sysfs: Add hook for checking the file capable for openerfs/sysfs/file.c include/linux/kobject.h include/linux/sysfs.h +1 more+38 -00 replies
2/2PM / Sleep: Check the file capability when writing wake lock interfacekernel/power/main.c kernel/power/wakelock.c+14 -66 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/2] [RFC] sysfs: Add hook for checking the file capability of opener

There have some discussion in the following mail loop about checking capability in sysfs write handler:

    https://lkml.org/lkml/2018/9/13/978

Sometimes we check the capability in sysfs implementation by using capable function. But the checking can be bypassed by opening sysfs file within an unprivileged process then writing the file within a privileged process. The tricking way has been exposed by Andy Lutomirski for CVE-2013-1959.

Because the sysfs_ops does not forward the file descriptor to the show/store callback, there doesn't have chance to check the capability of file's opener. This patch adds the hook to sysfs_ops that allows different implementation in object and attribute levels for checking file capable before accessing sysfs interfaces.

The callback function of kobject sysfs_ops is the first implementation of new hook. It casts attribute to kobj_attribute then calls the file capability callback function of attribute level. The same logic can be implemented in other sysfs file types, like: device, driver and bus type.

The capability checking logic in wake_lock/wake_unlock sysfs interface is the first example for kobject. It will check the opener's capability.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Chen Yu <[email protected]>
Cc Giovanni Gherdovich <[email protected]>
Cc Jann Horn <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Joe Perches <[email protected]>
Cc Bart Van Assche <[email protected]>

Lee, Chun-Yi (2):
sysfs: Add hook for checking the file capable
PM / Sleep: Checking the file capability when writing wak lock
interface

 fs/sysfs/file.c         |  8 ++++++++
 include/linux/kobject.h |  2 ++
 include/linux/sysfs.h   |  2 ++
 kernel/power/main.c     | 14 ++++++++++++++
 kernel/power/wakelock.c |  6 ------
 lib/kobject.c           | 26 ++++++++++++++++++++++++++
 6 files changed, 52 insertions(+), 6 deletions(-)
Signature · 1 line
2.13.6