Re: [PATCH] proc: also check the opener's capability for oom_score_adj and oom_adj

From: Oleg Nesterov

Date: Tue Dec 01 2026 - 11:26:58 EST


Damn ;) let me apologise first, I'am afraid my comments just added
the unnecessary noise to this thread.

But don't worry, I am going to add even more noise, please see below.

On 12/01, Chen Linxuan wrote:
>
> LGTM. A few additional comments below.

Same here, please see 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.

OK, agreed. In case it wasn't clear let me repeat: I didn't really try to argue,
I just tried to understand this patch.

Oh. Now let me also repeat that I don't really understand this code, so you
can safely ignore me.

-------------------------------------------------------------------------------
That said...

So. To simplify, lets forget about "legacy", ->vfork_done, and CAP_OPT_NOAUDIT.
And about this patch for the moment. In essence we have

if (oom_adj < oom_score_adj_min && !CAP_SYS_RESOURCE) // CHECK 1
return -EACCES;

oom_score_adj = oom_adj; // unconditional if CHECK 1 passes

if (CAP_SYS_RESOURCE) // CHECK 2
oom_score_adj_min = oom_adj;

This already looks messy to me, but perhaps this is because I don't really
understand this logic.

Now lets recall that this patch adds file_ns_capable() into CHECK 1, but not
into CHECK 2.

Now. Lets suppose a task T has oom_score_adj = oom_score_adj_min = 0. This task
does "setuid-app-which-writes-500-to-stdout > /proc/<getpid()>/oom_score_adj".

CHECK 1 is skipped. CHECK 2 passes (app is setuid), oom_score_adj_min is raised
to 500. Now, T can't lower oom_score_adj back to 0.

Compare that with the case when T writes "500" directly: oom_score_adj becomes
500, but oom_score_adj_min is still 0. And in this case T still can lower its
oom_score_adj to 0.


That is why I tried to suggest to unify / factor out CAP_SYS_RESOURCE checks
(again, let's ignore the possible noise from audit). I mean, suppose we add

bool xxx = CAP_SYS_RESOURCE && file_ns_capable(CAP_SYS_RESOURCE);

at the start and change __set_oom_adj() to use it consistently. In this case CHECK 1
and 2 will agree at least in the scenario above: oom_score_adj_min will be 0.

Oleg.