All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: "Cen Zhang (Microsoft)" <blbllhy@gmail.com>,
	brauner@kernel.org, akpm@linux-foundation.org, jack@suse.cz,
	avagin@gmail.com, ptikhomirov@virtuozzo.com, include@grrlz.net,
	linux-kernel@vger.kernel.org,
	AutonomousCodeSecurity@microsoft.com,
	tgopinath@linux.microsoft.com, kys@microsoft.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] pid: fix cad_pid use-after-free race
Date: Sat, 18 Jul 2026 17:58:19 +0200	[thread overview]
Message-ID: <aluim8REjBcE4ejB@redhat.com> (raw)
In-Reply-To: <CAGudoHEMhAfDf8c0P89yEkaVgC6c=Q822-6OFzgG82v+SHvkvA@mail.gmail.com>

On 07/18, Mateusz Guzik wrote:
>
> On Sat, Jul 18, 2026 at 3:20 PM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > On 07/17, Cen Zhang (Microsoft) wrote:
> > >
> > >  int kill_cad_pid(int sig, int priv)
> > >  {
> > > -     return kill_pid(cad_pid, sig, priv);
> > > +     struct pid *pid;
> > > +     int ret;
> > > +
> > > +     rcu_read_lock();
> > > +     pid = get_pid(rcu_dereference(cad_pid));
> > > +     rcu_read_unlock();
> > > +
> > > +     ret = kill_pid(pid, sig, priv);
> > > +     put_pid(pid);
> >
> > Hmm. Why do we need get/put_pid() ? I think that
> >
> >         rcu_read_lock();
> >         ret = kill_pid(rcu_dereference(cad_pid), sig, priv);
> >         rcu_read_unlock();
> >
> >         return ret;
> >
> > should work just fine?
> >
>
> I suggested taking the ref as a future-proofing measure to *not*
> impose any requirements on kill_pid.
>
> Admittedly when responding to v1 I blindly assumed pid is always
> rcu-freed, my bad.
>
> Given the arcane nature of the proc file at hand and 0 performance
> concerns, I think the easiest way out is to give it a spinlock to
> protect access to cad_pid as opposed to trying to play any rcu and
> lockless games.

Just in case, I am fine either way. I'd personaly prefer to play rcu
games in this case, but I won't insist.

I've sent my comment only because get_pid + put_pid + kill_pid() outside
of rcu_read_lock() look really confusing to me.

As for requirements on kill_pid... See for example kill_pid_info().
kill_pid/kill_pid_info/etc are all rcu safe wrt "struct pid *pid" arg.

Oleg.


  reply	other threads:[~2026-07-18 15:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18  3:19 [PATCH v2 1/2] pid: deinline kill_cad_pid Cen Zhang (Microsoft)
2026-07-18  3:20 ` [PATCH v2 2/2] pid: fix cad_pid use-after-free race Cen Zhang (Microsoft)
2026-07-18 11:54   ` Bradley Morgan
2026-07-18 13:19   ` Oleg Nesterov
2026-07-18 13:59     ` Bradley Morgan
2026-07-18 14:13       ` Oleg Nesterov
2026-07-18 14:28         ` Bradley Morgan
2026-07-18 15:37     ` Mateusz Guzik
2026-07-18 15:58       ` Oleg Nesterov [this message]
2026-07-18 10:24 ` [PATCH v2 1/2] pid: deinline kill_cad_pid Bradley Morgan

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=aluim8REjBcE4ejB@redhat.com \
    --to=oleg@redhat.com \
    --cc=AutonomousCodeSecurity@microsoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=avagin@gmail.com \
    --cc=blbllhy@gmail.com \
    --cc=brauner@kernel.org \
    --cc=include@grrlz.net \
    --cc=jack@suse.cz \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=stable@vger.kernel.org \
    --cc=tgopinath@linux.microsoft.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.