[PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
From: Hungyu Lin
Date: Wed Nov 25 2026 - 23:52:40 EST
__set_oom_adj() checks CAP_SYS_RESOURCE against the task that calls
write(). A task without the capability can open its own
/proc/<pid>/oom_score_adj or /proc/<pid>/oom_adj 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 lowers the
value below oom_score_adj_min, down to OOM_SCORE_ADJ_MIN, which the
opener is not allowed to do.
Require the capability from the opener of the file as well as from the
writer: check file_ns_capable() in addition to capable().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/proc/base.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index e6d54193b9f5..42e4645899fe 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1099,7 +1099,8 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
mutex_lock(&oom_adj_mutex);
if (legacy) {
if (oom_adj < task->signal->oom_score_adj &&
- !capable(CAP_SYS_RESOURCE)) {
+ (!file_ns_capable(file, &init_user_ns, CAP_SYS_RESOURCE) ||
+ !capable(CAP_SYS_RESOURCE))) {
err = -EACCES;
goto err_unlock;
}
@@ -1112,7 +1113,8 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
task_pid_nr(task));
} else {
if ((short)oom_adj < task->signal->oom_score_adj_min &&
- !capable(CAP_SYS_RESOURCE)) {
+ (!file_ns_capable(file, &init_user_ns, CAP_SYS_RESOURCE) ||
+ !capable(CAP_SYS_RESOURCE))) {
err = -EACCES;
goto err_unlock;
}
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
--
2.43.0