From 668fa98385559e6ca53555e32da8e7eb618f0d80 Mon Sep 17 00:00:00 2001 From: mpi <> Date: Thu, 30 Jan 2020 08:22:30 +0000 Subject: Enable t_ptrace with an errno change compared to NetBSD. Note that the last test triggers a kernel bug related to waitpid(9) and ptraced processes. This is now visible thanks to recent make(1) changes. guenther@ suggests to look at the logic behind `p_orphan' in FreeBSD to fix this bug. --- src/regress/lib/libc/sys/Makefile | 14 ++++++++------ src/regress/lib/libc/sys/README | 2 +- src/regress/lib/libc/sys/macros.h | 30 ++++++++++++++++++++---------- src/regress/lib/libc/sys/t_ptrace.c | 4 ++-- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/regress/lib/libc/sys/Makefile b/src/regress/lib/libc/sys/Makefile index e30e0a08fb..8c2c6eb3f8 100644 --- a/src/regress/lib/libc/sys/Makefile +++ b/src/regress/lib/libc/sys/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.2 2020/01/13 17:06:56 bluhm Exp $ +# $OpenBSD: Makefile,v 1.3 2020/01/30 08:22:30 mpi Exp $ # Copyright (c) 2019 Moritz Buhl # Copyright (c) 2019 Alexander Bluhm @@ -30,8 +30,8 @@ PROGS += t_access t_bind t_chroot t_clock_gettime t_dup t_fsync PROGS += t_getgroups t_getitimer t_getlogin t_getpid t_getrusage PROGS += t_getsid t_getsockname t_gettimeofday t_kill t_link t_listen PROGS += t_mkdir t_mknod t_msgctl t_msgget t_msgsnd t_msync t_pipe -PROGS += t_poll t_revoke t_select t_sendrecv t_setuid t_socketpair -PROGS += t_sigaction t_truncate t_umask t_write +PROGS += t_poll t_ptrace t_revoke t_select t_sendrecv t_setuid +PROGS += t_socketpair t_sigaction t_truncate t_umask t_write # failing tests .if 0 @@ -40,7 +40,6 @@ PROGS += t_mlock PROGS += t_mmap PROGS += t_msgrcv PROGS += t_pipe2 -PROGS += t_ptrace PROGS += t_stat PROGS += t_syscall PROGS += t_unlink @@ -57,8 +56,9 @@ setup-t_truncate: ${SUDO} touch truncate_test.root_owned ${SUDO} chown root:wheel truncate_test.root_owned -run-t_chroot: cleanup-t_chroot -cleanup-t_chroot: +run-t_chroot: cleanup-dir +run-t_ptrace: cleanup-dir +cleanup-dir: ${SUDO} rm -rf dir CLEANFILES = access dummy mmap truncate_test.root_owned @@ -100,3 +100,5 @@ run-${PROG}-$n: .endif .include + +clean: cleanup-dir diff --git a/src/regress/lib/libc/sys/README b/src/regress/lib/libc/sys/README index 84a442eb5d..0f7d82e7b6 100644 --- a/src/regress/lib/libc/sys/README +++ b/src/regress/lib/libc/sys/README @@ -18,6 +18,7 @@ t_getrusage - no expected fail, PR kern/30115 is NetBSD, work more t_mknod - remove tests for unsupported file types t_msgget - remove msgget_limit test t_poll - remove pollts_* tests +t_ptrace - change EPERM -> EINVAL for PT_ATTACH of a parent t_revoke - remove basic tests, revoke only on ttys supported t_select - remove sigset_t struct as it is int on OpenBSD @@ -26,7 +27,6 @@ t_mlock - wrong errno, succeeds where not expected, POSIX imprecise t_mmap - ENOTBLK on test NetBSD is skipping, remove mmap_va0 test t_msgrcv - msgrcv(id, &r, 3 - 1, 0x41, 004000) != -1 t_pipe2 - closefrom(4) == -1, remove F_GETNOSIGPIPE and nosigpipe test -t_ptrace - ptrace(0, 0, ((void *)0), 0) != -1 t_stat - invalid GID with doas t_syscall - SIGSEGV t_unlink - wrong errno according to POSIX diff --git a/src/regress/lib/libc/sys/macros.h b/src/regress/lib/libc/sys/macros.h index 932f230c03..ef858d137a 100644 --- a/src/regress/lib/libc/sys/macros.h +++ b/src/regress/lib/libc/sys/macros.h @@ -1,4 +1,4 @@ -/* $OpenBSD: macros.h,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */ +/* $OpenBSD: macros.h,v 1.2 2020/01/30 08:22:30 mpi Exp $ */ /* Public domain - Moritz Buhl */ #include @@ -9,6 +9,7 @@ #include #include +#include #define __RCSID(str) #define __COPYRIGHT(str) @@ -26,17 +27,26 @@ int sysctlbyname(char *, void *, size_t *, void *, size_t); int sysctlbyname(char* s, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { - int ktc; - if (strcmp(s, "kern.timecounter.hardware") == 0) - ktc = KERN_TIMECOUNTER_HARDWARE; - else if (strcmp(s, "kern.timecounter.choice") == 0) - ktc = KERN_TIMECOUNTER_CHOICE; + int mib[3], miblen; - int mib[3]; mib[0] = CTL_KERN; - mib[1] = KERN_TIMECOUNTER; - mib[2] = ktc; - return sysctl(mib, 3, oldp, oldlenp, newp, newlen); + if (strcmp(s, "kern.timecounter.hardware") == 0) { + mib[1] = KERN_TIMECOUNTER; + mib[2] = KERN_TIMECOUNTER_HARDWARE; + miblen = 3; + } else if (strcmp(s, "kern.timecounter.choice") == 0) { + mib[1] = KERN_TIMECOUNTER; + mib[2] = KERN_TIMECOUNTER_CHOICE; + miblen = 3; + } else if (strcmp(s, "kern.securelevel") == 0) { + mib[1] = KERN_SECURELVL; + miblen = 2; + } else { + fprintf(stderr, "%s(): mib '%s' not supported\n", __func__, s); + return -42; + } + + return sysctl(mib, miblen, oldp, oldlenp, newp, newlen); } /* t_mlock.c */ diff --git a/src/regress/lib/libc/sys/t_ptrace.c b/src/regress/lib/libc/sys/t_ptrace.c index 756c9c514e..78c4a8e47b 100644 --- a/src/regress/lib/libc/sys/t_ptrace.c +++ b/src/regress/lib/libc/sys/t_ptrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_ptrace.c,v 1.1.1.1 2019/11/19 19:57:04 bluhm Exp $ */ +/* $OpenBSD: t_ptrace.c,v 1.2 2020/01/30 08:22:30 mpi Exp $ */ /* $NetBSD: t_ptrace.c,v 1.4 2018/05/14 12:44:40 kamil Exp $ */ /*- @@ -171,7 +171,7 @@ ATF_TC_BODY(attach_chroot, tc) rv = write(fds_toparent[1], &msg, sizeof(msg)); FORKEE_ASSERTX(rv == sizeof(msg)); - ATF_REQUIRE_ERRNO(EPERM, + ATF_REQUIRE_ERRNO(EINVAL, ptrace(PT_ATTACH, getppid(), NULL, 0) == -1); rv = read(fds_fromparent[0], &msg, sizeof(msg)); -- cgit v1.2.3-55-g6feb