Skip to contentSkip to conversation

proc: also check the opener's capability for timerslack_ns

PATCH New Hungyu Lin 1 participant 1 message Dec 5

Subsystems (2)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

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().

---
 fs/proc/base.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/proc/base.c +2 -1
index dc3c58478116..bea31e8e8520 100644
@@ -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