NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/61004: compat_linux rt_sigqueueinfo implementation does not pass info to target process
>Number: 61004
>Category: kern
>Synopsis: compat_linux rt_sigqueueinfo implementation does not pass info to target process
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Nov 14 03:40:00 +0000 2026
>Originator: Bobby Bingham
>Release: NetBSD-current 20261111155711
>Organization:
>Environment:
NetBSD netbsdvm.local 11.99.11 NetBSD 11.99.11 (GENERIC) #0: Wed Nov 11 15:57:11 UTC 2026 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
compat_linux's implementation of rt_sigqueueinfo is built on top of kill, I think because it predates NetBSD support for sigqueue.
This means that the recipient of the signal does not receive the provided value of siginfo_t.si_value, and receives the value SI_USER instead of the correct value SI_QUEUE for siginfo_t.si_code.
While fixing this, I also discovered that compat_linux's rt_sigqueueinfo enforces that si_code < 0, but this should only be a requirement when sending a signal to a different process. The Linux manpage also documents that si_code may not equal SI_TKILL when sending to a different process.
>How-To-Repeat:
Check out https://gitlab.com/sortix/os-test on a Linux system and compile it. Copy the compiled basic/signal/sigqueue binary to a NetBSD system and run it there.
The test will fail with the error "si_signo != SI_QUEUE" (which is a typo and should say "si_code != SI_QUEUE").
>Fix:
First, a patch to move the definition of native_to_linux_si_code earlier in the linux_signal.c file. This is so that the second patch can the inverse function, linux_to_native_si_code, and keep the two near each other without requiring a forward declaration.
diff --git a/sys/compat/linux/common/linux_signal.c b/sys/compat/linux/common/linux_signal.c
index 34054405e3d2..8d294699ac67 100644
--- a/sys/compat/linux/common/linux_signal.c
+++ b/sys/compat/linux/common/linux_signal.c
@@ -154,6 +154,20 @@ native_to_linux_sigset(linux_sigset_t *lss, const sigset_t *bss)
}
}
+int
+native_to_linux_si_code(int code)
+{
+ int si_codes[] = {
+ LINUX_SI_USER, LINUX_SI_QUEUE, LINUX_SI_TIMER, LINUX_SI_ASYNCIO,
+ LINUX_SI_MESGQ, LINUX_SI_TKILL /* SI_LWP */
+ };
+
+ if (code <= 0 && -code < __arraycount(si_codes))
+ return si_codes[-code];
+
+ return code;
+}
+
void
native_to_linux_siginfo(linux_siginfo_t *lsi, const struct _ksiginfo *ksi)
{
@@ -821,20 +835,6 @@ linux_sys_tgkill(struct lwp *l, const struct linux_sys_tgkill_args *uap, registe
return linux_do_tkill(l, SCARG(uap, tgid), SCARG(uap, tid), SCARG(uap, sig));
}
-int
-native_to_linux_si_code(int code)
-{
- int si_codes[] = {
- LINUX_SI_USER, LINUX_SI_QUEUE, LINUX_SI_TIMER, LINUX_SI_ASYNCIO,
- LINUX_SI_MESGQ, LINUX_SI_TKILL /* SI_LWP */
- };
-
- if (code <= 0 && -code < __arraycount(si_codes))
- return si_codes[-code];
-
- return code;
-}
-
int
native_to_linux_si_status(int code, int status)
{
===
And the fix itself:
diff --git a/sys/compat/linux/common/linux_signal.c b/sys/compat/linux/common/linux_signal.c
index 8d294699ac67..169e1032e08c 100644
--- a/sys/compat/linux/common/linux_signal.c
+++ b/sys/compat/linux/common/linux_signal.c
@@ -168,6 +168,27 @@ native_to_linux_si_code(int code)
return code;
}
+static int
+linux_to_native_si_code(int code)
+{
+ switch (code) {
+ case LINUX_SI_USER:
+ return SI_USER;
+ case LINUX_SI_QUEUE:
+ return SI_QUEUE;
+ case LINUX_SI_TIMER:
+ return SI_TIMER;
+ case LINUX_SI_ASYNCIO:
+ return SI_ASYNCIO;
+ case LINUX_SI_MESGQ:
+ return SI_MESGQ;
+ case LINUX_SI_TKILL:
+ return SI_LWP;
+ default:
+ return code;
+ };
+}
+
void
native_to_linux_siginfo(linux_siginfo_t *lsi, const struct _ksiginfo *ksi)
{
@@ -640,10 +661,6 @@ linux_sys_rt_sigtimedwait(struct lwp *l,
}
#if !defined(__aarch64__)
-/*
- * Once more: only a signal conversion is needed.
- * Note: also used as sys_rt_queueinfo. The info field is ignored.
- */
int
linux_sys_rt_queueinfo(struct lwp *l, const struct linux_sys_rt_queueinfo_args *uap, register_t *retval)
{
@@ -652,8 +669,9 @@ linux_sys_rt_queueinfo(struct lwp *l, const struct linux_sys_rt_queueinfo_args *
syscallarg(int) signum;
syscallarg(linix_siginfo_t *) uinfo;
*/
- int error;
+ int error, sig;
linux_siginfo_t info;
+ ksiginfo_t ksi;
int pid = SCARG(uap, pid);
@@ -665,12 +683,22 @@ linux_sys_rt_queueinfo(struct lwp *l, const struct linux_sys_rt_queueinfo_args *
error = copyin(SCARG(uap, uinfo), &info, sizeof(info));
if (error)
return error;
- if (info.lsi_code >= 0)
+ if (l->l_proc->p_pid != pid &&
+ (info.lsi_code >= 0 || info.lsi_code == LINUX_SI_TKILL))
return EPERM;
- /* XXX To really implement this we need to */
- /* XXX keep a list of queued signals somewhere. */
- return linux_sys_kill(l, (const void *)uap, retval);
+ sig = SCARG(uap, signum);
+ if ((unsigned)sig >= LINUX__NSIG)
+ return EINVAL;
+
+ KSI_INIT(&ksi);
+ ksi.ksi_signo = linux_to_native_signo[sig];
+ ksi.ksi_code = linux_to_native_si_code(info.lsi_code);
+ ksi.ksi_pid = info.lsi_pid;
+ ksi.ksi_uid = info.lsi_uid;
+ ksi.ksi_value.sival_ptr = info.lsi_value.sival_ptr;
+
+ return kill1(l, pid, &ksi, retval);
}
#endif
Home |
Main Index |
Thread Index |
Old Index