* [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
@ 2026-11-26 4:52 Hungyu Lin
2026-11-26 10:50 ` Oleg Nesterov
0 siblings, 1 reply; 5+ messages in thread
From: Hungyu Lin @ 2026-11-26 4:52 UTC (permalink / raw)
To: akpm, brauner
Cc: adobriyan, jannh, oleg, jack, sforshee, me, linux-fsdevel,
linux-kernel, dennylin0707
__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@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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
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
2026-11-26 14:42 ` Oleg Nesterov
2026-11-26 18:08 ` Hungyu Lin
0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2026-11-26 10:50 UTC (permalink / raw)
To: Hungyu Lin
Cc: akpm, brauner, adobriyan, jannh, jack, sforshee, me,
linux-fsdevel, linux-kernel
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
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
2026-11-26 10:50 ` Oleg Nesterov
@ 2026-11-26 14:42 ` Oleg Nesterov
2026-11-26 18:08 ` Hungyu Lin
1 sibling, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2026-11-26 14:42 UTC (permalink / raw)
To: Hungyu Lin
Cc: akpm, brauner, adobriyan, jannh, jack, sforshee, me,
linux-fsdevel, linux-kernel
I just noticed that __set_oom_adj() has more CAP_SYS_RESOURCE checks below.
Shouldn't we unify them or even factor out?
Oleg.
On 11/26, Oleg Nesterov wrote:
>
> 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
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
2026-11-26 10:50 ` Oleg Nesterov
2026-11-26 14:42 ` Oleg Nesterov
@ 2026-11-26 18:08 ` Hungyu Lin
2026-11-26 19:03 ` Oleg Nesterov
1 sibling, 1 reply; 5+ messages in thread
From: Hungyu Lin @ 2026-11-26 18:08 UTC (permalink / raw)
To: Oleg Nesterov
Cc: akpm, brauner, adobriyan, jannh, jack, sforshee, me,
linux-fsdevel, linux-kernel
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?
A write that needs CAP_SYS_RESOURCE still needs it from the writer,
even if the opener was privileged. For example, a task can open its
own oom_score_adj with CAP_SYS_RESOURCE and still have the fd after
dropping that capability and calling execve(). If we only check the
opener, it could then lower its value down to OOM_SCORE_ADJ_MIN, and
any children it creates afterward would inherit that.
I kept capable() so that a fix for stable doesn't relax anything. Or do
you think the opener check alone is enough?
Thanks,
Hungyu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj
2026-11-26 18:08 ` Hungyu Lin
@ 2026-11-26 19:03 ` Oleg Nesterov
0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2026-11-26 19:03 UTC (permalink / raw)
To: Hungyu Lin
Cc: akpm, brauner, adobriyan, jannh, jack, sforshee, me,
linux-fsdevel, linux-kernel
On 11/26, Hungyu Lin wrote:
>
> 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?
>
> A write that needs CAP_SYS_RESOURCE still needs it from the writer,
> even if the opener was privileged. For example, a task can open its
> own oom_score_adj with CAP_SYS_RESOURCE and still have the fd after
> dropping that capability and calling execve(). If we only check the
> opener, it could then lower its value down to OOM_SCORE_ADJ_MIN, and
> any children it creates afterward would inherit that.
And my question was: do we really care about this case?
> I kept capable() so that a fix for stable doesn't relax anything.
OK,
> Or do
> you think the opener check alone is enough?
Well, let me quote the part of my email you have removed:
Just in case, I am not saying that the old check should be removed,
I am trying to understand.
So no, I am not sure the opener check alone is enough.
Oleg.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 19:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-26 14:42 ` Oleg Nesterov
2026-11-26 18:08 ` Hungyu Lin
2026-11-26 19:03 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox