signal: PIDFD_SIGNAL_THREAD threads via pidfds

This commit extends pidfd_send_signal() to signal a specific thread.
As promised in the commit for pidfd_send_signal() [1] the extension is
based on a flag argument, i.e. the scope of the signal delivery is based on
the flag argument, not on the type of file descriptor.
To this end the flag PIDFD_SIGNAL_THREAD is added. With this change we now
cover most of the functionality of all the other signal sending functions
combined:

- pidfd_send_signal(<pidfd>, <sig>, NULL, 0);
  which is equivalent to
  kill(<positive-pid>, <signal>)

- pidfd_send_signal(<pidfd>, <sig>, <info>, 0);
  which is equivalent to
  rt_sigqueueinfo(<tgid>, <sig>, <uinfo>)

- pidfd_send_signal(<pidfd>, <sig>, NULL, PIDFD_SIGNAL_THREAD);
  which is equivalent to
  tgkill(<tgid>, <tid>, <signal)

- pidfd_send_signal(<pidfd>, <sig>, <info>, PIDFD_SIGNAL_THREAD);
  which is equivalent to
  rt_tgsigqueueinfo(<tgid>, <tid>, <sig>, <uinfo>)

/* References */
[1]: commit 3eb39f47934 ("signal: add pidfd_send_signal() syscall")

Signed-off-by: Christian Brauner <christian@brauner.io>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jann Horn <jannh@google.com
Cc: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Jonathan Kowalski <bl0pbl33p@gmail.com>
Cc: "Dmitry V. Levin" <ldv@altlinux.org>
Cc: Andy Lutomirsky <luto@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Nagarathnam Muthusamy <nagarathnam.muthusamy@oracle.com>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Florian Weimer <fweimer@redhat.com>
---
/* Changelog */
v1:
- Jann Horn <jannh@google.com [1]:
  - initialize PIDFD_SIGNAL_TID flag with 1U to match @flags unsigned int
    type
  - update comment about @flags
  - align pidfd_send_signal_specific()'s argument ordering with
    kill_pid_info()
  - s/PIDFD_SIGNAL_TID/PIDFD_SIGNAL_THREAD/
- Christian Brauner <christian@brauner.io>:
  - insert comment about what the flag arguments are going to be named if
    we extend pidfd_send_signal() to process groups and sessions

/* Changelog References */
[1]: https://lore.kernel.org/lkml/CAG48ez0=Q2CzgTGLiEU7F9B=gS-58VrpKz2XQ369cemo2FJdbQ@mail.gmail.com
2 files changed