From: Oleg Nesterov <oleg@redhat.com>
To: Hungyu Lin <dennylin0707@gmail.com>
Cc: akpm@linux-foundation.org, brauner@kernel.org,
adobriyan@gmail.com, jannh@google.com, jack@suse.cz,
sforshee@kernel.org, me@black-desk.cn,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
Date: Thu, 26 Nov 2026 11:50:54 +0100 [thread overview]
Message-ID: <awgPDmEbGpJsT_iS@redhat.com> (raw)
In-Reply-To: <20261126045222.20770-1-dennylin0707@gmail.com>
On 11/26, 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()
Looks reasonable but
> in addition to capable().
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?
Just in case, I am not saying that the old check should be removed,
I am trying to understand.
Oleg.
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
> 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
>
>
next prev parent reply other threads:[~2026-11-26 10:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 4:52 [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj Hungyu Lin
2026-11-26 10:50 ` Oleg Nesterov [this message]
2026-11-26 14:42 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awgPDmEbGpJsT_iS@redhat.com \
--to=oleg@redhat.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=dennylin0707@gmail.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@black-desk.cn \
--cc=sforshee@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox