NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
standards/60998: POSIX requires that siginfo_t.si_uid be real uid, not effective uid
>Number: 60998
>Category: standards
>Synopsis: POSIX requires that siginfo_t.si_uid be real uid, not effective uid
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: standards-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Nov 13 07:05: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:
POSIX documents that the siginfo_t.si_uid member is to contain the *real* user id of the sending process (for kill/sigqueue) or the child process that triggered the signal (for SIGCHLD). NetBSD sets this member to the effective user id instead.
https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_04_03
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html
Note that the user id of the si_uid member is not tied to the user id used to evaluate if a process has the appropriate permissions to send a signal to a target process. Unlike si_uid, that permission check is permitted to use the effective user id.
>How-To-Repeat:
The test suite, as written, does try to verify that the si_uid field is set to the real uid, but because the tests run with the same real and effective uid, it does not catch the problem.
First, a patch to the test suite I found along the way. There are a couple tests which check the handling of a child process which dumps core, and trigger the core dump via a null(-ish) pointer dereference. Aside from being undefined behavior, the code falls back to using ATF failure APIs in case the segfault does not terminate the child process. ATF APIs don't, I believe, work as expected from a child process like this. And the next patch below will start using seteuid() and I found that ATF can fail to open the report output file in that case.
This patch switches these tests to have the child simply abort(). Because this should be guaranteed to terminate the child, I can avoid the ATF calls in the child and have fewer cases where I need to make sure they can open the report output file.
diff --git a/tests/lib/libc/gen/t_siginfo.c b/tests/lib/libc/gen/t_siginfo.c
index 3f7ed7a6e996..21d875b09274 100644
--- a/tests/lib/libc/gen/t_siginfo.c
+++ b/tests/lib/libc/gen/t_siginfo.c
@@ -228,14 +228,13 @@ ATF_TC_BODY(sigchild_dump, tc)
sigchild_setup();
- status = SIGSEGV;
+ status = SIGABRT;
code = CLD_DUMPED;
switch ((child = fork())) {
case 0:
sleep(1);
- *(volatile long *)0 = 0;
- atf_tc_fail("Child did not segfault");
+ abort();
/* NOTREACHED */
case -1:
atf_tc_fail("fork failed");
diff --git a/tests/lib/libc/sys/t_wait.c b/tests/lib/libc/sys/t_wait.c
index 293887e7234f..fadc61006825 100644
--- a/tests/lib/libc/sys/t_wait.c
+++ b/tests/lib/libc/sys/t_wait.c
@@ -148,16 +148,15 @@ ATF_TC_BODY(wait6_coredumped, tc)
switch (pid = fork()) {
case 0:
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
- *(char *)8 = 0;
- /*FALLTHROUGH*/
+ abort();
case -1:
ATF_REQUIRE(pid > 0);
__unreachable();
default:
ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
- ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV
+ ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGABRT
&& WCOREDUMP(st));
- ATF_REQUIRE(si.si_status == SIGSEGV);
+ ATF_REQUIRE(si.si_status == SIGABRT);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_DUMPED);
=====
This patch updates the tests to seteuid() to "nobody" before triggering a signal, so that the test can tell whether the real or effective user id was used in si_uid.
The tests do not verify that seteuid() succeeds -- if it fails, then the real and effective uid should still be equal and we can still at least verify that si_uid equals _that_ value. On top of all the other values that the tests verify.
Note that for the tests that require dumping core, the kern.coredump.setid.dump sysctl must be 1 for the core dump to happen if the seteuid call succeeds. I've updated the test to check that sysctl if it thinks the seteuid will succeed, and skip the test if it is not set correctly. The one catch is that we need to skip the test from the parent process, and it's the child process that does the seteuid call. I've written the check assuming that `geteuid() == 0` is a valid proxy for whether the seteuid call in the child can be expected to succeed.
diff --git a/tests/lib/libc/gen/t_siginfo.c b/tests/lib/libc/gen/t_siginfo.c
index 21d875b09274..7c628ea06b90 100644
--- a/tests/lib/libc/gen/t_siginfo.c
+++ b/tests/lib/libc/gen/t_siginfo.c
@@ -37,6 +37,7 @@
#include <assert.h>
#include <float.h>
#include <inttypes.h>
+#include <pwd.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
@@ -51,6 +52,7 @@
#include <ieeefp.h>
#endif
+#include "h_macros.h"
#include "isqemu.h"
#ifdef ENABLE_TESTS
@@ -167,6 +169,21 @@ setchildhandler(void (*action)(int, siginfo_t *, void *))
sigaction(SIGCHLD, &sa, NULL);
}
+static void
+seteuid_nobody(void)
+{
+ struct passwd *pw;
+
+ /*
+ * Attempt to change effective user id to differ from real user id, so the
+ * tests can verify that si_uid is set from the correct one.
+ */
+ if ((pw = getpwnam("nobody")) != NULL)
+ seteuid(pw->pw_uid);
+
+ endpwent();
+}
+
static void
sigchild_setup(void)
{
@@ -203,6 +220,7 @@ ATF_TC_BODY(sigchild_normal, tc)
switch ((child = fork())) {
case 0:
+ seteuid_nobody();
sleep(1);
exit(status);
case -1:
@@ -224,8 +242,18 @@ ATF_TC_HEAD(sigchild_dump, tc)
ATF_TC_BODY(sigchild_dump, tc)
{
+ int val;
+ size_t len;
sigset_t set;
+ /* If the child can seteuid, it will also need to be able to dump core */
+ if (geteuid() == 0) {
+ len = sizeof(val);
+ RL(sysctlbyname("kern.coredump.setid.dump", &val, &len, NULL, 0));
+ if (val == 0)
+ atf_tc_skip("Core dumps disabled for setuid processes");
+ }
+
sigchild_setup();
status = SIGABRT;
@@ -233,6 +261,7 @@ ATF_TC_BODY(sigchild_dump, tc)
switch ((child = fork())) {
case 0:
+ seteuid_nobody();
sleep(1);
abort();
/* NOTREACHED */
@@ -264,12 +293,14 @@ ATF_TC_BODY(sigchild_kill, tc)
switch ((child = fork())) {
case 0:
+ seteuid_nobody();
sigemptyset(&set);
sigsuspend(&set);
break;
case -1:
atf_tc_fail("fork failed");
default:
+ sleep(1);
kill(child, SIGPIPE);
sigemptyset(&set);
sigsuspend(&set);
diff --git a/tests/lib/libc/sys/t_ptrace_sigchld.c b/tests/lib/libc/sys/t_ptrace_sigchld.c
index f8de9cc0a8f6..f48a1b9ce572 100644
--- a/tests/lib/libc/sys/t_ptrace_sigchld.c
+++ b/tests/lib/libc/sys/t_ptrace_sigchld.c
@@ -48,6 +48,7 @@ __RCSID("$NetBSD: t_ptrace_sigchld.c,v 1.7 2025/05/02 02:37:07 riastradh Exp $")
#include <fcntl.h>
#include <lwp.h>
#include <pthread.h>
+#include <pwd.h>
#include <sched.h>
#include <signal.h>
#include <spawn.h>
@@ -90,6 +91,21 @@ static int expected_code;
static int expected_status;
static pid_t expected_pid;
+static void
+seteuid_nobody(void)
+{
+ struct passwd *pw;
+
+ /*
+ * Attempt to change effective user id to differ from real user id, so the
+ * tests can verify that si_uid is set from the correct one.
+ */
+ if ((pw = getpwnam("nobody")) != NULL)
+ seteuid(pw->pw_uid);
+
+ endpwent();
+}
+
static void
sigchld_action(int sig, siginfo_t *info, void *ctx)
{
@@ -142,6 +158,7 @@ traceme_raise(int sigval)
CHILD_FROM_PARENT("raise1 child", parent_child, msg);
+ seteuid_nobody();
raise(sigval);
CHILD_TO_PARENT("raise2 child", parent_child, msg);
diff --git a/tests/lib/libc/sys/t_wait.c b/tests/lib/libc/sys/t_wait.c
index fadc61006825..394522596b3e 100644
--- a/tests/lib/libc/sys/t_wait.c
+++ b/tests/lib/libc/sys/t_wait.c
@@ -31,6 +31,7 @@
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_wait.c,v 1.10 2021/07/17 14:03:35 martin Exp $");
+#include <sys/sysctl.h>
#include <sys/wait.h>
#include <sys/resource.h>
@@ -45,6 +46,54 @@ __RCSID("$NetBSD: t_wait.c,v 1.10 2021/07/17 14:03:35 martin Exp $");
#include <atf-c.h>
+#include "h_macros.h"
+
+static void
+seteuid_nobody(void)
+{
+ struct passwd *pw;
+
+ /*
+ * Attempt to change effective user id to differ from real user id, so the
+ * tests can verify that si_uid is set from the correct one.
+ */
+ if ((pw = getpwnam("nobody")) != NULL)
+ seteuid(pw->pw_uid);
+
+ endpwent();
+}
+
+/*
+ * Fork a child process, which will attempt to seteuid to "nobody". In both
+ * the parent and child process, waits until the child's seteuid call has
+ * completed before returning. Return value is as for fork.
+ */
+static pid_t
+setup_child_process(void)
+{
+ pid_t pid;
+ int fds[2];
+
+ RL(pipe(fds));
+ switch ((pid = fork())) {
+ case 0:
+ seteuid_nobody();
+ /* In the child process we can't rely on atf; abort instead. */
+ if (write(fds[1], &(char){0}, 1) != 1)
+ abort();
+ break;
+ case -1:
+ break;
+ default:
+ ATF_REQUIRE(read(fds[0], &(char){0}, 1) == 1);
+ break;
+ }
+
+ close(fds[0]);
+ close(fds[1]);
+ return pid;
+}
+
ATF_TC(wait6_invalid);
ATF_TC_HEAD(wait6_invalid, tc)
{
@@ -75,7 +124,7 @@ ATF_TC_BODY(wait6_exited, tc)
int st;
pid_t pid;
- switch (pid = fork()) {
+ switch ((pid = setup_child_process())) {
case 0:
exit(0x5a5a5a5a);
/*NOTREACHED*/
@@ -109,7 +158,7 @@ ATF_TC_BODY(wait6_terminated, tc)
int st;
pid_t pid;
- switch (pid = fork()) {
+ switch ((pid = setup_child_process())) {
case 0:
sleep(100);
/*FALLTHROUGH*/
@@ -141,11 +190,20 @@ ATF_TC_BODY(wait6_coredumped, tc)
{
siginfo_t si;
struct wrusage wru;
- int st;
+ int st, val;
+ size_t len;
pid_t pid;
static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
- switch (pid = fork()) {
+ /* If the child can seteuid, it will also need to be able to dump core */
+ if (geteuid() == 0) {
+ len = sizeof(val);
+ RL(sysctlbyname("kern.coredump.setid.dump", &val, &len, NULL, 0));
+ if (val == 0)
+ atf_tc_skip("Core dumps disabled for setuid processes");
+ }
+
+ switch ((pid = setup_child_process())) {
case 0:
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
abort();
@@ -182,7 +240,7 @@ ATF_TC_BODY(wait6_stop_and_go, tc)
static const struct rlimit rl = { 0, 0 };
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
- switch (pid = fork()) {
+ switch ((pid = setup_child_process())) {
case 0:
sleep(100);
/*FALLTHROUGH*/
@@ -249,7 +307,7 @@ ATF_TC_BODY(wait6_stopgo_loop, tc)
size_t N = 100;
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
- switch (pid = fork()) {
+ switch ((pid = setup_child_process())) {
case 0:
sleep(100);
/*FALLTHROUGH*/
>Fix:
diff --git a/lib/libc/softfloat/softfloat-specialize b/lib/libc/softfloat/softfloat-specialize
index 210b81889718..7727bd7fbb5c 100644
--- a/lib/libc/softfloat/softfloat-specialize
+++ b/lib/libc/softfloat/softfloat-specialize
@@ -143,7 +143,7 @@ float_raise( fp_except newflags )
memset(&info, 0, sizeof info);
info.si_signo = SIGFPE;
info.si_pid = getpid();
- info.si_uid = geteuid();
+ info.si_uid = getuid();
if (flags & float_flag_underflow)
info.si_code = FPE_FLTUND;
else if (flags & float_flag_overflow)
diff --git a/lib/libc/sys/sigqueue.c b/lib/libc/sys/sigqueue.c
index 2bf09ad4b946..e31f34246a01 100644
--- a/lib/libc/sys/sigqueue.c
+++ b/lib/libc/sys/sigqueue.c
@@ -54,7 +54,7 @@ sigqueue(pid_t pid, int signo, const union sigval value)
info.si_signo = signo;
info.si_code = SI_QUEUE;
info.si_pid = getpid();
- info.si_uid = geteuid();
+ info.si_uid = getuid();
info.si_value = value;
return sigqueueinfo(pid, &info);
diff --git a/lib/libm/softfloat/feraiseexcept.c b/lib/libm/softfloat/feraiseexcept.c
index 2280adb7fc04..68e47bbeab39 100644
--- a/lib/libm/softfloat/feraiseexcept.c
+++ b/lib/libm/softfloat/feraiseexcept.c
@@ -57,7 +57,7 @@ feraiseexcept(int excepts)
memset(&info, 0, sizeof info);
info.si_signo = SIGFPE;
info.si_pid = getpid();
- info.si_uid = geteuid();
+ info.si_uid = getuid();
if (excepts & FE_UNDERFLOW)
info.si_code = FPE_FLTUND;
else if (excepts & FE_OVERFLOW)
diff --git a/share/man/man2/siginfo.2 b/share/man/man2/siginfo.2
index 61cae7857431..6f0dc5f9d848 100644
--- a/share/man/man2/siginfo.2
+++ b/share/man/man2/siginfo.2
@@ -78,7 +78,7 @@ The
.Fa si_pid
field contains the pid of the sending process and the
.Fa si_uid
-field contains the user id of the sending process.
+field contains the real user id of the sending process.
.It SI_QUEUE
The signal was generated via
.Xr sigqueue 2 .
@@ -95,7 +95,7 @@ The
.Fa si_pid
field contains the pid of the sending process and the
.Fa si_uid
-field contains the user id of the sending process.
+field contains the real user id of the sending process.
Finally, the
.Fa si_value
field contains the value sent via
@@ -161,7 +161,7 @@ The
.Fa si_pid
field contains the pid of the sending process and the
.Fa si_uid
-field contains the user id of the sending process.
+field contains the real user id of the sending process.
.It SI_NOINFO
The signal was generated without specific info available.
.El
@@ -378,7 +378,7 @@ The
.Fa si_pid
field contains the pid of the process who's status changed, the
.Fa si_uid
-field contains the user id of the that process, the
+field contains the real user id of the that process, the
.Fa si_status
field contains either the exit code of the process (for
.Dv CLD_EXITED ) ,
diff --git a/sys/compat/common/kern_sig_43.c b/sys/compat/common/kern_sig_43.c
index d50241e5bdef..f2ad24feaf95 100644
--- a/sys/compat/common/kern_sig_43.c
+++ b/sys/compat/common/kern_sig_43.c
@@ -275,7 +275,7 @@ compat_43_sys_killpg(struct lwp *l, const struct compat_43_sys_killpg_args *uap,
ksi.ksi_signo = SCARG(uap, signum);
ksi.ksi_code = SI_USER;
ksi.ksi_pid = l->l_proc->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
+ ksi.ksi_uid = kauth_cred_getuid(l->l_cred);
return killpg1(l, &ksi, pgid, 0);
}
diff --git a/sys/compat/linux/arch/m68k/linux_machdep.c b/sys/compat/linux/arch/m68k/linux_machdep.c
index 6f490a92f498..6c74ece7f71e 100644
--- a/sys/compat/linux/arch/m68k/linux_machdep.c
+++ b/sys/compat/linux/arch/m68k/linux_machdep.c
@@ -397,7 +397,7 @@ setup_linux_rt_sigframe(struct frame *frame, int sig, const sigset_t *mask, void
kf.sf_info.lsi_signo = sig;
kf.sf_info.lsi_code = LINUX_SI_USER;
kf.sf_info.lsi_pid = p->p_pid;
- kf.sf_info.lsi_uid = kauth_cred_geteuid(l->l_cred); /* Use real uid here? */
+ kf.sf_info.lsi_uid = kauth_cred_getuid(l->l_cred);
/* Build the signal context to be used by sigreturn. */
native_to_linux_sigset(&kf.sf_uc.uc_sigmask, mask);
diff --git a/sys/compat/linux/common/linux_signal.c b/sys/compat/linux/common/linux_signal.c
index 5f48dbd5080d..fbdcf238994c 100644
--- a/sys/compat/linux/common/linux_signal.c
+++ b/sys/compat/linux/common/linux_signal.c
@@ -775,7 +775,7 @@ linux_do_tkill(struct lwp *l, int tgid, int tid, int signum)
ksi.ksi_signo = signum;
ksi.ksi_code = SI_LWP;
ksi.ksi_pid = l->l_proc->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
+ ksi.ksi_uid = kauth_cred_getuid(l->l_cred);
ksi.ksi_lid = tid;
mutex_enter(&proc_lock);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index b824a1ad89c5..4970e1a2cb13 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -159,7 +159,7 @@ exit_psignal(struct proc *p, struct proc *pp, ksiginfo_t *ksi)
* It's safe to access p->p_cred unlocked here.
*/
ksi->ksi_pid = p->p_pid;
- ksi->ksi_uid = kauth_cred_geteuid(p->p_cred);
+ ksi->ksi_uid = kauth_cred_getuid(p->p_cred);
/* XXX: is this still valid? */
ksi->ksi_utime = p->p_stats->p_ru.ru_utime.tv_sec;
ksi->ksi_stime = p->p_stats->p_ru.ru_stime.tv_sec;
@@ -916,7 +916,7 @@ match_process(const struct proc *pp, struct proc **q, idtype_t idtype, id_t id,
}
siginfo->si_pid = p->p_pid;
- siginfo->si_uid = kauth_cred_geteuid(p->p_cred);
+ siginfo->si_uid = kauth_cred_getuid(p->p_cred);
siginfo->si_utime = p->p_stats->p_ru.ru_utime.tv_sec;
siginfo->si_stime = p->p_stats->p_ru.ru_stime.tv_sec;
}
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index e43cdbfed009..343569b168f2 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1004,7 +1004,7 @@ child_psignal(struct proc *p, int mask)
ksi.ksi_signo = SIGCHLD;
ksi.ksi_code = (xsig == SIGCONT ? CLD_CONTINUED : CLD_STOPPED);
ksi.ksi_pid = p->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(p->p_cred);
+ ksi.ksi_uid = kauth_cred_getuid(p->p_cred);
ksi.ksi_status = xsig;
ksi.ksi_utime = p->p_stats->p_ru.ru_utime.tv_sec;
ksi.ksi_stime = p->p_stats->p_ru.ru_stime.tv_sec;
diff --git a/sys/kern/sys_lwp.c b/sys/kern/sys_lwp.c
index 7c4e4f27ad23..b8c17396a075 100644
--- a/sys/kern/sys_lwp.c
+++ b/sys/kern/sys_lwp.c
@@ -386,7 +386,7 @@ sys__lwp_kill(struct lwp *l, const struct sys__lwp_kill_args *uap,
ksi.ksi_signo = signo;
ksi.ksi_code = SI_LWP;
ksi.ksi_pid = p->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
+ ksi.ksi_uid = kauth_cred_getuid(l->l_cred);
ksi.ksi_lid = SCARG(uap, target);
mutex_enter(&proc_lock);
diff --git a/sys/kern/sys_ptrace_common.c b/sys/kern/sys_ptrace_common.c
index fc3d5cad4901..b251f3c357ca 100644
--- a/sys/kern/sys_ptrace_common.c
+++ b/sys/kern/sys_ptrace_common.c
@@ -976,7 +976,7 @@ ptrace_sendsig(struct lwp *l, int req, struct proc *t, struct lwp *lt, int signo
ksi.ksi_signo = signo;
ksi.ksi_code = SI_USER;
ksi.ksi_pid = l->l_proc->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
+ ksi.ksi_uid = kauth_cred_getuid(l->l_cred);
t->p_sigctx.ps_faked = false;
diff --git a/sys/kern/sys_sig.c b/sys/kern/sys_sig.c
index dbed5c8191bf..110b07b7f686 100644
--- a/sys/kern/sys_sig.c
+++ b/sys/kern/sys_sig.c
@@ -234,7 +234,7 @@ kill1(struct lwp *l, pid_t pid, ksiginfo_t *ksi, register_t *retval)
if (ksi->ksi_pid != l->l_proc->p_pid)
return EPERM;
- if (ksi->ksi_uid != kauth_cred_geteuid(l->l_cred))
+ if (ksi->ksi_uid != kauth_cred_getuid(l->l_cred))
return EPERM;
switch (ksi->ksi_code) {
@@ -318,7 +318,7 @@ sys_kill(struct lwp *l, const struct sys_kill_args *uap, register_t *retval)
ksi.ksi_signo = SCARG(uap, signum);
ksi.ksi_code = SI_USER;
ksi.ksi_pid = l->l_proc->p_pid;
- ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
+ ksi.ksi_uid = kauth_cred_getuid(l->l_cred);
return kill1(l, SCARG(uap, pid), &ksi, retval);
}
Home |
Main Index |
Thread Index |
Old Index