Re: [PATCH v2] pidfd: implement PIDFD_THREAD flag for pidfd_open()
From: Tycho Andersen
Date: Tue Jan 30 2024 - 21:28:20 EST
On Tue, Jan 30, 2024 at 12:34:09PM +0100, Oleg Nesterov wrote:
> Damn. Self-NACK.
>
> I forgot (we all ;) about mt-exec, and there are 2 problems.
>
> 1. The "if (!thread_group_leader(tsk))" block in de_thread() needs
> do_notify_pidfd() too, the execing non-leader thread looses its
> old pid, pidfd_poll(PIDFD_THREAD, pid-of-execing-sub-thread)
> should succeed. Must be fixed, I think.
I think the `test_non_tgl_exec` from my tests exercises the scenario
you're describing, and it works.
> 2. pidfd_poll(PIDFD_THREAD, pid-of-group-leader) should not succeed
> when its sub-thread execs, the execing thread inherits the leader's
> pid. Perhaps pidfd_task_exited() can check sig->group_exec_task,
I didn't have an explicit test for this, but I hacked one up, and
pidfd_poll(PIDFD_THREAD, pid-of-group-leader) doesn't return after
exec.
I think it's ok? But I must be missing something.
Tycho