add rt_tgsigqueueinfo syscall -V2
cover add rt_tgsigqueueinfo syscall -V2
sys_kill has a counterpart sys_tgkill which allows to send signals to a particular thread. sys_rt_sigqueueinfo is lacking such a counterpart.
Aside of the asymetry it is a show stopper for migrating applications from other unix-alike RTOSes.
The following patch series implements rt_tgsigqueueinfo and hooks it up for x86.
Changes since V1:
- match rt_siqqueueinfo and rt_tgsigqueueinfo handling of info.si_pid/si_uid
Find below the raw documentation.
Thanks,
tglx
----
NAME
rt_tgsigqueueinfo - Send signal information to a signal to a thread
SYNOPSIS
long sys_rt_tgsigqueueinfo (int tgid, int tid, int sig, siginfo_t *uinfo);
DESCRIPTION
rt_tgsigqueueinfo sends signal sig information uinfo to the thread with the thread ID tid in the thread group tgid. (By contrast, rt_sigqueueinfo(2) can only be used to send a signal info to a process (i.e., thread group) as a whole, and the signal will be delivered to an arbitrary thread within that process.)
RETURN VALUE
rt_tgsigqueueinfo returns 0 on success; otherwise, rt_sigqueueinfo returns one of the errors listed in the "Errors" section.
ERRORS
-EFAULT
An invalid value for uinfo was specified.
-EINVAL
An invalid TID, TGID or signal was specified.
-EPERM
Permission denied. For the required permissions, see rt_sigqueueinfo(2).
-ESRCH
No process with the specified thread ID and thread group ID exists.
PATCH 1/3 signals: split do_tkill
Split out the code from do_tkill to make it reusable by the follow up patch which implements sys_rt_tgsigqueueinfo
--- kernel/signal.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
kernel/signal.c +18 -12
@@ -2235,24 +2235,17 @@ SYSCALL_DEFINE2(kill, pid_t, pid, int, sreturn kill_something_info (sig, &info, pid); } -static int do_tkill (pid_t tgid,pid_t pid,int sig) +static int +do_send_specific (pid_t tgid,pid_t pid,int sig,struct siginfo *info) { -int error; -struct siginfo info;struct task_struct *p;unsigned long flags; - - error = -ESRCH ; - info.si_signo = sig; - info.si_errno =0 ; - info.si_code =SI_TKILL ; - info.si_pid =task_tgid_vnr (current); - info.si_uid =current_uid (); +int error = -ESRCH ;rcu_read_lock (); p =find_task_by_vpid (pid);if (p && (tgid <=0 ||task_tgid_vnr (p) == tgid)) { - error =check_kill_permission (sig, &info, p); + error =check_kill_permission (sig, info, p);/* * The null signal is a permissions and process existence * probe. No signal is actually delivered.
@@ -2262,7 +2255,7 @@ static int do_tkill(pid_t tgid, pid_t pi* signal is private anyway. */ if (!error && sig &&lock_task_sighand (p, &flags)) { - error =specific_send_sig_info (sig, &info, p); + error =specific_send_sig_info (sig, info, p);unlock_task_sighand (p, &flags); } }
@@ -2271,6 +2264,19 @@ static int do_tkill(pid_t tgid, pid_t pireturn error; } +static int do_tkill (pid_t tgid,pid_t pid,int sig) +{ +struct siginfo info; + + info.si_signo = sig; + info.si_errno =0 ; + info.si_code =SI_TKILL ; + info.si_pid =task_tgid_vnr (current); + info.si_uid =current_uid (); + +return do_send_specific (tgid, pid, sig, &info); +} +/** * sys_tgkill - send signal to one specific thread * @tgid: the thread group ID of the thread
PATCH 2/3 signals: implement sys_rt_tgsigqueueinfo
In reply to Thomas Gleixnersys_kill has the per thread counterpart sys_tgkill. sigqueueinfo is missing a thread directed counterpart. Such an interface is important for migrating applications from other OSes which have the per thread delivery implemented.
--- include/linux/compat.h | 2 ++ include/linux/signal.h | 2 ++ kernel/compat.c | 11 +++++++++++ kernel/signal.c | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+)
include/linux/compat.h +2 -0
@@ -208,6 +208,8 @@ int copy_siginfo_from_user32(siginfo_t *int copy_siginfo_to_user32 (struct compat_siginfo __user *to,siginfo_t *from);int get_compat_sigevent (struct sigevent *event,const struct compat_sigevent __user *u_event); +long compat_sys_rt_tgsigqueueinfo (compat_pid_t tgid,compat_pid_t pid,int sig, +struct compat_siginfo __user *uinfo);static inline int compat_timeval_compare (struct compat_timeval *lhs,struct compat_timeval *rhs)
include/linux/signal.h +2 -0
@@ -235,6 +235,8 @@ static inline int valid_signal(unsignedextern int next_signal (struct sigpending *pending,sigset_t *mask);extern int group_send_sig_info (int sig,struct siginfo *info,struct task_struct *p);extern int __group_send_sig_info (int ,struct siginfo *,struct task_struct *); +extern long do_rt_tgsigqueueinfo (pid_t tgid,pid_t pid,int sig, +siginfo_t *info);extern long do_sigpending (void __user *,unsigned long );extern int sigprocmask (int ,sigset_t *,sigset_t *);extern int show_unhandled_signals;
kernel/compat.c +11 -0
@@ -882,6 +882,17 @@ compat_sys_rt_sigtimedwait (compat_sigse } +asmlinkage long +compat_sys_rt_tgsigqueueinfo (compat_pid_t tgid,compat_pid_t pid,int sig, +struct compat_siginfo __user *uinfo) +{ +siginfo_t info; + +if (copy_siginfo_from_user32 (&info, uinfo)) +return -EFAULT ; +return do_rt_tgsigqueueinfo (tgid, pid, sig, &info); +} +#ifdef __ARCH_WANT_COMPAT_SYS_TIME/* compat_time_t is a 32 bit "long" and needs to get converted. */
kernel/signal.c +26 -0
@@ -2326,6 +2326,32 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t,return kill_proc_info (sig, &info, pid); } +long do_rt_tgsigqueueinfo (pid_t tgid,pid_t pid,int sig,siginfo_t *info) +{ +/* This is only valid for single tasks */ +if (pid <=0 || tgid <=0 ) +return -EINVAL ; + +/* Not even root can pretend to send signals from the kernel. +Nor can they impersonate a kill(), which adds source info. */ +if (info->si_code >=0 ) +return -EPERM ; + info->si_signo = sig; + +return do_send_specific (tgid, pid, sig, info); +} + +SYSCALL_DEFINE4 (rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig, + siginfo_t __user *, uinfo) +{ +siginfo_t info; + +if (copy_from_user (&info, uinfo,sizeof (siginfo_t))) +return -EFAULT ; + +return do_rt_tgsigqueueinfo (tgid, pid, sig, &info); +} +int do_sigaction (int sig,struct k_sigaction *act,struct k_sigaction *oact) {struct task_struct *t = current;
PATCH 3/3 x86: hookup sys_rt_tgsigqueueinfo
In reply to Thomas GleixnerMake the new sys_rt_tgsigqueueinfo available for x86.
--- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 1 + arch/x86/include/asm/unistd_64.h | 2 ++ arch/x86/kernel/syscall_table_32.S | 1 + 4 files changed, 5 insertions(+)
arch/x86/ia32/ia32entry.S +1 -0
@@ -828,4 +828,5 @@ ia32_sys_call_table: .quad sys_dup3 /* 330 */ .quad sys_pipe2 .quad sys_inotify_init1 + .quad compat_sys_rt_tgsigqueueinfo ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +1 -0
@@ -338,6 +338,7 @@#define __NR_dup3 330#define __NR_pipe2 331#define __NR_inotify_init1 332 +#define __NR_rt_tgsigqueueinfo 333#ifdef __KERNEL__
arch/x86/include/asm/unistd_64.h +2 -0
@@ -653,6 +653,8 @@ __SYSCALL(__NR_dup3, sys_dup3) __SYSCALL(__NR_pipe2, sys_pipe2)#define __NR_inotify_init1 294 __SYSCALL(__NR_inotify_init1, sys_inotify_init1) +#define __NR_rt_tgsigqueueinfo 295 +__SYSCALL(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo)#ifndef __NO_STUBS
arch/x86/kernel/syscall_table_32.S +1 -0
@@ -332,3 +332,4 @@ ENTRY(sys_call_table) .long sys_dup3 /* 330 */ .long sys_pipe2 .long sys_inotify_init1 + .long sys_rt_tgsigqueueinfo
Quoted 7 lines · Thomas Gleixner
sys_killhas a counterpartsys_tgkillwhich allows to send signals to a particular thread.sys_rt_sigqueueinfois lacking such a counterpart.Aside of the asymetry it is a show stopper for migrating applications from other unix-alike RTOSes.
Quoted 6 lines
The following patch series implements
rt_tgsigqueueinfoand hooks it up for x86.Changes since V1:
- matchrt_siqqueueinfoandrt_tgsigqueueinfohandling of info.si_pid/si_uid
I think this all is correct. And I think "Changes since V1" are good, rt_tgsigqueueinfo() should not play with si_pid/si_uid.
Quoted 11 lines · Oleg Nesterov
Quoted 10 lines · Thomas Gleixner
sys_killhas a counterpartsys_tgkillwhich allows to send signals to a particular thread.sys_rt_sigqueueinfois lacking such a counterpart.Aside of the asymetry it is a show stopper for migrating applications from other unix-alike RTOSes.
The following patch series implements
rt_tgsigqueueinfoand hooks it up for x86.
Quoted 8 lines
Quoted 3 lines
Changes since V1:
- matchrt_siqqueueinfoandrt_tgsigqueueinfohandling of info.si_pid/si_uidI think this all is correct. And I think "Changes since V1" are good,
rt_tgsigqueueinfo()should not play with si_pid/si_uid.Reviewed-by Oleg Nesterov <[email protected]>
I had two concerns with earlier iteraions of this patch (
http://thread.gmane.org/gmane.linux.kernel/799866/focus=667 ):
[[
1) With rt_siqueueinfo(), we can get the PID (TGID) of the sender, which enables the receiver of the signal to know who the sender was, and perhaps use that information to (for example) send a signal in the other direction.
With rt_tgsigqueueinfo(), we don't quite have that ability: all that the receiver gets is the TGID of the sender, not the TID. This means that we can't (for example) send a signal back to the precise thread that signaled us. I'm not sure if this matters or not (but perhaps it might when sender and receiver are in the same process?). I'm also not sure whether we want to do anything about this (i.e., extending siginfo_t to include a si_tid field), but I wanted to point out this assymetry w.r.t. to rt_sigqueueinfo(), in case you had not considered it.
2) With rt_sigqueueinfo(), we can specify the si_pid and and si_uid fields that should be sent to the receiver. This is not possible with rt_tgsigqueueinfo(), which always supplied the caller';s PID and UID in the si_pid and si_uid fields sent to the receiver. See the following, created using my test programs below (the 111 & 222 arguments to t_*sigqueueinfo set the si_pid and si_uid fields in the siginfo_t given to the *sigqueueinfo() syscall):
]]
Roland pointed out that the first problem could be dealt with via the sigval associated with the signal.
The second problem is addressed by this change:
Quoted 3 lines
Quoted 3 lines
Changes since V1:
- matchrt_siqqueueinfoandrt_tgsigqueueinfohandling of info.si_pid/si_uid
I've tested this version of the interface (using the programs shown in the mail thread referred to above), and it works as I expect, and I find the design otherwise sane, so:
Cheers,
Michael
Signature · 5 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
Quoted 1 line
1) With
rt_siqueueinfo(), we can get the PID (TGID) of the sender,
No. You can get whatever the caller put into the siginfo_t. Only the si_signo field is set by the kernel.
Quoted 1 line
With
rt_tgsigqueueinfo(), [...]
You still get whatever the caller put into the siginfo_t.
Thanks,
Roland
Quoted 8 lines · Roland McGrath
Quoted 1 line
1) With
rt_siqueueinfo(), we can get the PID (TGID) of the sender,No. You can get whatever the caller put into the
siginfo_t. Only thesi_signofield is set by the kernel.Quoted 1 line
With
rt_tgsigqueueinfo(), [...]You still get whatever the caller put into the
siginfo_t.
Yes. I wrote the text awkwardly, but I think the point was clear. In my point 1, I wrongly thought we needed a way to get the sender's TID to the receiver, and you pointed out that sigval could do the job. In my point 2, I made the same observation as you just made above.
Thanks,
Michael
Signature · 5 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html