mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Demi Marie Obenour <demiobenour@gmail.com>,
	 Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel: Prevent prctl(PR_SET_PDEATHSIG) from racing with parent process exit
Date: Tue, 7 Oct 2025 14:53:15 +0200	[thread overview]
Message-ID: <20251007-hochnehmen-zerreden-d17ad9147c7c@brauner> (raw)
In-Reply-To: <CAGudoHED4nx8QT-yw-zdcUApUyvt2HCOR9c3SQ3tAm9J7Q1jEQ@mail.gmail.com>

On Tue, Sep 23, 2025 at 03:39:06PM +0200, Mateusz Guzik wrote:
> On Tue, Sep 23, 2025 at 2:05 PM Oleg Nesterov <oleg@redhat.com> wrote:
> > As you correctly pointed out, forget_original_parent/prctl lack the necessary
> > barries. So lets add the barriers instead of abusing tasklist? As for sys_prctl(),
> > I think that ret-to-user-mode + enter-the-kernel-mode should act as a full
> > barrier, so it only needs WRITE_ONCE()...
> >
> 
> So I looked over this and I think I see why you are not eager to fix
> the problem to begin with. ;)
> 
> I agree with reluctance to take tasklist lock to handle
> PR_SET_PDEATHSIG, but I wonder if in practice this is used rarely
> enough that the lock trip would not be a problem? It avoids any
> modifications to the exit codepath.

Unprivileged userspace can now just call that prctl() in a loop to
hammer on tasklist_lock. Already possible with the subreaper stuff but I
think we don't need to add more. At least for the subreaper stuff it has
an actual meaningful use and not just plugs a theoretical problem.

> 
> By barriers I presume you meant smp_mb() between
> RCU_INIT_POINTER(t->real_parent, reaper) and
> READ_ONCE(t->pdeath_signal) in forget_original_parent. That's very
> nasty as the full fence is quite expensive. This could be done with
> just one fence for the entire call by iterating the list twice, but
> that's still preferably avoided.
> 
> > Or perhaps user-space can do something else to sync with the exiting parent
> > instead of using getppid() ?
> >
> 
> I never put any thought concerning this mechanism, I do think it
> nicely showcases the prctl at hand is kind of crap. The non-crap
> version would pass the PID you think your parent is, so that you do
> this race-free. I don't know if makes any sense to add this.

I see that stuff already made it into the tree. I strongly dislike
adding more tasklist_lock usage. All for a theoretical race with limited
impact.

If I'd seen this sooner I would have NAKed this out of existence.

> 
> I'm wondering if the fact that tasklist is write-locked in that code
> path could be utilized to synchronize this in a matter other than
> taking it.
> 
> pseudo-code wise, something like this:
> WRITE_ONCE(me->pdeath_signal, arg2);
> /* publish the above store and load the lock after */
> smb_mb();
> /* here spin waiting until tasklist_lock is not write-locked */
> smb_rmb();
> 
> Unless I'm missing something this should provide the guarantee you see
> the updated parent, if any.
> 
> I don't see a routine to do it though and knowing memory barriers
> there might be some bullshit hiding there making this not work, so not
> my first choice unless someone with more memory barrier clue can chime
> in.

  parent reply	other threads:[~2025-10-07 12:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-13 22:28 Demi Marie Obenour via B4 Relay
2025-09-20  4:10 ` Demi Marie Obenour
2025-09-22 22:48   ` Andrew Morton
2025-09-23 12:03     ` Oleg Nesterov
2025-09-23 13:39       ` Mateusz Guzik
2025-09-25 16:28         ` Oleg Nesterov
2025-09-25 18:35           ` Mateusz Guzik
2025-09-25 18:50             ` Oleg Nesterov
2025-09-26 23:58             ` Demi Marie Obenour
2025-09-27  1:51               ` Mateusz Guzik
2025-10-07 12:53         ` Christian Brauner [this message]
2025-09-20  4:10 ` Demi Marie Obenour

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=20251007-hochnehmen-zerreden-d17ad9147c7c@brauner \
    --to=brauner@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=demiobenour@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=oleg@redhat.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

all inboxes | Powered by JetHome®