The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>,
	linux-kernel@vger.kernel.org, peterz@infradead.org,
	brauner@kernel.org, chris@chrisdown.name
Subject: Re: [PATCH v2 3/3] sched/psi: allow unprivileged polling of N*2s period
Date: Thu, 23 Mar 2023 13:44:59 -0400	[thread overview]
Message-ID: <20230323174459.GH739026@cmpxchg.org> (raw)
In-Reply-To: <CAJuCfpFh0iL0cE8V3dh-HkDx3-20Kyo+ZAt0vnqvOzA33HwnFg@mail.gmail.com>

On Thu, Mar 23, 2023 at 09:55:11AM -0700, Suren Baghdasaryan wrote:
> On Thu, Mar 23, 2023 at 3:34 AM Domenico Cerasuolo
> > @@ -1254,16 +1262,19 @@ int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res)
> >  }
> >
> >  struct psi_trigger *psi_trigger_create(struct psi_group *group,
> > -                       char *buf, enum psi_res res)
> > +                       char *buf, enum psi_res res, struct file *file)
> >  {
> >         struct psi_trigger *t;
> >         enum psi_states state;
> >         u32 threshold_us;
> > +       bool privileged;
> >         u32 window_us;
> >
> >         if (static_branch_likely(&psi_disabled))
> >                 return ERR_PTR(-EOPNOTSUPP);
> >
> > +       privileged = cap_raised(file->f_cred->cap_effective, CAP_SYS_RESOURCE);
> 
> I missed one detail here. We are moving the cap check from open() to
> write(). That might break potential users which open the file from a
> process with that cap and then pass that FD to an unprivileged process
> to create the trigger by writing to that file. I'm not aware of any
> use of such a pattern but it is possible there are such users.
> With this change such users would have to delegate trigger creation to
> the privileged process too and the received FD would be used only for
> polling. IMHO that's a safer pattern because triggers are created by
> the privileged process.

Oh, it's checking file->f_cred, which is set up at open(). So if the
opener is privileged, the write can be delegated to an unprivileged
process.

But I agree that this is subtle and could use a comment.

This was a usecase specifically requested by Christian, actually.

  reply	other threads:[~2023-03-23 17:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 10:33 [PATCH v2 0/3] sched/psi: Allow unprivileged PSI polling Domenico Cerasuolo
2023-03-23 10:33 ` [PATCH v2 1/3] sched/psi: rearrange polling code in preparation Domenico Cerasuolo
2023-03-23 10:33 ` [PATCH v2 2/3] sched/psi: extract update_triggers side effect Domenico Cerasuolo
2023-03-23 10:33 ` [PATCH v2 3/3] sched/psi: allow unprivileged polling of N*2s period Domenico Cerasuolo
2023-03-23 15:09   ` Johannes Weiner
2023-03-23 16:43     ` Suren Baghdasaryan
2023-03-23 17:40       ` Johannes Weiner
2023-03-23 16:55   ` Suren Baghdasaryan
2023-03-23 17:44     ` Johannes Weiner [this message]
2023-03-23 18:07       ` Suren Baghdasaryan

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=20230323174459.GH739026@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=brauner@kernel.org \
    --cc=cerasuolodomenico@gmail.com \
    --cc=chris@chrisdown.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=surenb@google.com \
    /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