History

pidfs: ensure that PIDFS_INFO_EXIT is available

When we currently create a pidfd we check that the task hasn't been reaped right before we create the pidfd. But it is of course possible that by the time we return the pidfd to userspace the task has already been reaped since we don't check again after having created a dentry for it. This was fine until now because that race was meaningless. But now that we provide PIDFD_INFO_EXIT it is a problem because it is possible that the kernel returns a reaped pidfd and it depends on the race whether PIDFD_INFO_EXIT information is available. This depends on if the task gets reaped before or after a dentry has been attached to struct pid. Make this consistent and only returned pidfds for reaped tasks if PIDFD_INFO_EXIT information is available. This is done by performing another check whether the task has been reaped right after we attached a dentry to struct pid. Since pidfs_exit() is called before struct pid's task linkage is removed the case where the task got reaped but a dentry was already attached to struct pid and exit information was recorded and published can be handled correctly. In that case we do return a pidfd for a reaped task like we would've before.

Christian Brauner committed 1 year ago

Commit 68db2721 parent 6092c503 files · +62 −5Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/pidfd.h+4−0
@@ -10,6 +10,10 @@ · 9 unmodified lines
10/* Flags for pidfd_open(). */10/* Flags for pidfd_open(). */
11#define PIDFD_NONBLOCK O_NONBLOCK11#define PIDFD_NONBLOCK O_NONBLOCK
12#define PIDFD_THREAD O_EXCL12#define PIDFD_THREAD O_EXCL
13#ifdef __KERNEL__
14#include <linux/sched.h>
15#define PIDFD_CLONE CLONE_PIDFD
16#endif
13 17
14/* Flags for pidfd_send_signal(). */18/* Flags for pidfd_send_signal(). */
15#define PIDFD_SIGNAL_THREAD (1UL << 0)19#define PIDFD_SIGNAL_THREAD (1UL << 0)