proc: also check the opener's capability for timerslack_ns
Subsystems (2)
PATCH 1/1 proc: also check the opener's capability for timerslack_ns
timerslack_ns_write() checks CAP_SYS_NICE against the task that calls write() when the target is another task. /proc/<pid>/timerslack_ns is mode 0666, so a task without the capability can open the file of any other task, including one owned by root, and have a privileged process write to that file descriptor, for example a set-user-ID program that inherits it as standard output. The write then changes the timer slack of a task that the opener is not allowed to change.
Require the capability from the opener of the file as well as from the
writer: check file_ns_capable() in addition to ns_capable().
Fixes 5de23d435e88 ("proc: add /proc/<pid>/timerslack_ns interface")
Reported-by Chen Linxuan <[email protected]>
Closes https://lore.kernel.org/all/CAC1kPDNf6CYcwJkQKtP2Rd3xy2MwCz9G-z6ay_GEXAOLK1iO8w@mail.gmail.com/ open here
Signed-off-by Hungyu Lin <[email protected]>
--- fs/proc/base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/proc/base.c +2 -1
@@ -2733,7 +2733,8 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,if (p != current) {rcu_read_lock (); -if (!ns_capable (__task_cred (p)->user_ns,CAP_SYS_NICE )) { +if (!file_ns_capable (file,__task_cred (p)->user_ns,CAP_SYS_NICE ) || + !ns_capable (__task_cred (p)->user_ns,CAP_SYS_NICE )) {rcu_read_unlock (); count = -EPERM ; goto out;
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
Signature · 1 line
2.43.0