Skip to content

Commit

Permalink
signal: support CLONE_PIDFD with pidfd_send_signal
Browse files Browse the repository at this point in the history
Let pidfd_send_signal() use pidfds retrieved via CLONE_PIDFD.  With this
patch pidfd_send_signal() becomes independent of procfs.  This fullfils
the request made when we merged the pidfd_send_signal() patchset.  The
pidfd_send_signal() syscall is now always available allowing for it to
be used by users without procfs mounted or even users without procfs
support compiled into the kernel.

Signed-off-by: Christian Brauner <[email protected]>
Co-developed-by: Jann Horn <[email protected]>
Signed-off-by: Jann Horn <[email protected]>
Acked-by: Oleg Nesterov <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: David Howells <[email protected]>
Cc: "Michael Kerrisk (man-pages)" <[email protected]>
Cc: Andy Lutomirsky <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Aleksa Sarai <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Al Viro <[email protected]>
  • Loading branch information
brauner committed May 7, 2019
1 parent b3e5838 commit 2151ad1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 9 additions & 3 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,6 @@ SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
return kill_something_info(sig, &info, pid);
}

#ifdef CONFIG_PROC_FS
/*
* Verify that the signaler and signalee either are in the same pid namespace
* or that the signaler's pid namespace is an ancestor of the signalee's pid
Expand Down Expand Up @@ -3550,6 +3549,14 @@ static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info)
return copy_siginfo_from_user(kinfo, info);
}

static struct pid *pidfd_to_pid(const struct file *file)
{
if (file->f_op == &pidfd_fops)
return file->private_data;

return tgid_pidfd_to_pid(file);
}

/**
* sys_pidfd_send_signal - send a signal to a process through a task file
* descriptor
Expand Down Expand Up @@ -3586,7 +3593,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
return -EBADF;

/* Is this a pidfd? */
pid = tgid_pidfd_to_pid(f.file);
pid = pidfd_to_pid(f.file);
if (IS_ERR(pid)) {
ret = PTR_ERR(pid);
goto err;
Expand Down Expand Up @@ -3620,7 +3627,6 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
fdput(f);
return ret;
}
#endif /* CONFIG_PROC_FS */

static int
do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info)
Expand Down
3 changes: 0 additions & 3 deletions kernel/sys_ni.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ COND_SYSCALL(syslog);

/* kernel/sched/core.c */

/* kernel/signal.c */
COND_SYSCALL(pidfd_send_signal);

/* kernel/sys.c */
COND_SYSCALL(setregid);
COND_SYSCALL(setgid);
Expand Down

0 comments on commit 2151ad1

Please sign in to comment.