Linux filesystem development
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Chen Linxuan <me@black-desk.cn>
Cc: Hungyu Lin <dennylin0707@gmail.com>,
	akpm@linux-foundation.org, brauner@kernel.org,
	adobriyan@gmail.com, jannh@google.com, jack@suse.cz,
	sforshee@kernel.org, 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: Tue, 1 Dec 2026 17:26:04 +0100	[thread overview]
Message-ID: <aw71HPqPl1uTB02M@redhat.com> (raw)
In-Reply-To: <CAC1kPDNf6CYcwJkQKtP2Rd3xy2MwCz9G-z6ay_GEXAOLK1iO8w@mail.gmail.com>

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.


      reply	other threads:[~2026-12-01 16:26 UTC|newest]

Thread overview: 9+ 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
2026-11-26 14:42   ` Oleg Nesterov
2026-11-26 20:34     ` Hungyu Lin
2026-11-27 10:59       ` Oleg Nesterov
2026-11-26 18:08   ` Hungyu Lin
2026-11-26 19:03     ` Oleg Nesterov
2026-12-01  8:59 ` Chen Linxuan
2026-12-01 16:26   ` Oleg Nesterov [this message]

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=aw71HPqPl1uTB02M@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