Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
From: Chen Linxuan
Date: Tue Dec 01 2026 - 04:00:07 EST
On Thu, Nov 26, 2026 at 04:52:22AM +0000, Hungyu Lin wrote:
> __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().
LGTM. A few additional comments below.
On Thu, Nov 26, 2026 at 11:50:54AM +0100, Oleg Nesterov wrote:
> do we really need to keep the old capable(CAP_SYS_RESOURCE) check?
>
> If a privileged opener of /proc/<pid>/oom_score_adj passes fd to
> to unprivileged writer, we probably don't care?
I agree with keeping the writer-side check: a permission check should not be
relaxed without a detailed justification. Checking both the opener and the
writer is an existing pattern in the kernel (uid_map/gid_map), and it is also
what Documentation/security/credentials.rst, "Open File Credentials", asks
for. So I'd suggest keeping it for now; if there is a use case for removing
it, that can be discussed in a separate patch.
> program that inherits it as standard output.
For later readers who wonder how this can happen in practice, sudo's
-S -p is a ready-made example (the prompt is written to stderr, before
authentication).
And there are also a few existing instances of the same pattern:
- /proc/<pid>/timerslack_ns: the reach is even wider than
oom_score_adj; any process can be the target. The fix is the same: add
file_ns_capable(file, __task_cred(p)->user_ns, CAP_SYS_NICE).
- /proc/<pid>/make-it-fail (proc_fault_inject_write,
fs/proc/base.c:1409): the same writer-only capable(CAP_SYS_RESOURCE);
there should be no security impact, but it could be fixed along the
way for consistency.
--
Chen Linxuan