[PATCH] proc: also check the opener's capability for timerslack_ns
From: Hungyu Lin
Date: Fri Dec 04 2026 - 21:15:53 EST
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 <me@xxxxxxxxxxxxx>
Closes: https://lore.kernel.org/all/CAC1kPDNf6CYcwJkQKtP2Rd3xy2MwCz9G-z6ay_GEXAOLK1iO8w@xxxxxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/proc/base.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index dc3c58478116..bea31e8e8520 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -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
--
2.43.0