History log of /src/tests/lib/libc/sys/t_ptrace_wait.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
Revision tags: perseant-exfatfs-base-20250801 netbsd-11-base
# 1.195 02-May-2025 riastradh

t_ptrace_*: Turn debug output back off.

Even with the output reduction I recently implemented, this seems to
be filling up the releng testbed disk with excess output. Not
completely obviated by the recent diagnostic improvements -- e.g.,
the traceme_signalmasked_crash_fpe test still uses DPRINTF for some
output that isn't available any other way. But let's get the tests
running to completion again before improving that.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky


# 1.194 01-May-2025 riastradh

t_ptrace_*.c: Make debug output a little less verbose.

Maybe it will stop overflowing the releng testbed file systems this
way.


# 1.193 29-Apr-2025 riastradh

t_ptrace_wait, t_ptrace_sigchld: Enable debug output.

Otherwise failures lead only to nearly useless output like:

FAILED: /work/src/tests/lib/libc/sys/t_ptrace_signal_wait.h:852: info.psi_siginfo.si_signo != sig

What _was_ si_signo, you ask? Sorry, you have to guess or run the
test yourself!


Revision tags: perseant-exfatfs-base-20240630 perseant-exfatfs-base
# 1.192 01-Apr-2024 riastradh

branches: 1.192.2;
elftoolchain: Be consistent about which ELF header files we use.

1. For tools that use elftoolchain: always use elftoolchain's
elfdefinitions.h. Don't even think about looking at the host's
sys/exec_elf.h, which makes no sense and should never happen.

(ELF tools that don't use elftoolchain, like m68k-elf2coff,
continue to use nbincludes/sys/exec_elf.h. But no more nbincludes
hacks in elftoolchain.)

2. For kernel components (solaris, zfs, dtrace): always use
sys/exec_elf.h, even in Solaris components via sys/elf.h.
elfdefinitions.h is not wired up in the kernel build at all.

3. For most userland components that involve libelf: use
elfdefinitions.h via libelf header files (libelf.h, gelf.h).

libdtrace in particular requires _all_ R_* reloc type definitions,
but sys/exec_elf.h brings in only the _current machine's_ R_*
reloc type definitions. (While here: Use uintptr_t instead of
Elf_Addr for pointer-to-integer cast, since Elf_Addr is MD and
provided only by sys/exec_elf.h, not by elfdefinitions.h.)

And most userland components using libelf don't rely on any
properties of the current machine from sys/exec_elf.h, so they can
use libelf's elfdefinition.h.

Exceptions:

- dtrace drti.c relies on link.h -> link_elf.h -> sys/exec_elf.h,
but it also relies on sys/dtrace.h -> sys/elf.h ->
elfdefinitions.h like other userland components using sys/elf.h.

- kdump-ioctl.c uses sys/exec_elf.h directly and sys/dtrace.h ->
sys/elf.h -> elfdefinitions like other userland components using
sys/elf.h.

- t_ptrace_wait.c (via t_ptrace_core_wait.h) uses libelf to parse
core files, but relies on sys/exec_elf.h for struct
netbsd_elfcore_procinfo.

None of these exceptions needs all R_* reloc type definitions, so
as a workaround, we can just suppress libelf's elfdefinitions.h by
defining _SYS_ELFDEFINITIONS_H_ and use sys/exec_elf.h in these
exceptions.

And undo the whole BUILTIN_ELF_HEADERS mistake. This was:

- half bogus workarounds for missing build_install dependencies in
tools/Makefile, which are no longer missing now, and
- half futile attempt to use src/sys/sys/exec_elf.h via nbincludes in
tools involving libelf instead of libelf's elfdefinitions.h, which
collides.

Longer-term, we may wish to unify sys/exec_elf.h and libelf's
elfdefinitions.h, so we don't have to play these games.

But at least now the games are limited to three .c files (one of
which is generated by Makefile.ioctl-c), rather than haphazardly
applied tree-wide by monstrous kludges in widely used .h files with
broken hackarounds to get the tools build lurching to completion.


Revision tags: netbsd-10-1-RELEASE netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base thorpej-futex2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-futex-base
# 1.191 05-May-2020 kamil

Move misc tests out of t_ptrace_wait.c to t_ptrace_misc_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.190 05-May-2020 kamil

Move core tests out of t_ptrace_wait.c to t_ptrace_core_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.189 05-May-2020 kamil

Move siginfo tests out of t_ptrace_wait.c to t_ptrace_siginfo_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.188 05-May-2020 kamil

Move threads tests out of t_ptrace_wait.c to t_ptrace_threads_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.187 05-May-2020 kamil

Move topology tests out of t_ptrace_wait.c to t_ptrace_topology_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.186 05-May-2020 kamil

Move exec() tests out of t_ptrace_wait.c to t_ptrace_exec_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.185 05-May-2020 kamil

Move LWP tests out of t_ptrace_wait.c to t_ptrace_lwp_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.184 05-May-2020 kamil

Remove the duplicate ATF_TP_ADD_TC() entries

Event mask tests are already defined in
ATF_TP_ADD_TCS_PTRACE_WAIT_EVENTMASK().


# 1.183 05-May-2020 kamil

Move eventmask tests out of t_ptrace_wait.c to t_ptrace_eventmask_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.182 04-May-2020 kamil

Remove the duplicate ATF_TP_ADD_TC() entries

Byte transfer tests are already defined in
ATF_TP_ADD_TCS_PTRACE_WAIT_BYTETRANSFER().


# 1.181 04-May-2020 kamil

Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.180 04-May-2020 kamil

Move fork/vfork/posix_spawn tests out of t_ptrace_wait.c to t_ptrace_fork_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.179 04-May-2020 kamil

Move clone() tests out of t_ptrace_wait.c to t_ptrace_clone_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.178 04-May-2020 kamil

Move byte transfer tests out of t_ptrace_wait.c to t_ptrace_bytetransfer_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.177 04-May-2020 kamil

Move kill()-like tests out of t_ptrace_wait.c to t_ptrace_kill_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.176 04-May-2020 kamil

Move PT_STEP tests out of t_ptrace_wait.c to t_ptrace_step_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.175 04-May-2020 kamil

Move syscall tests out of t_ptrace_wait.c to t_ptrace_syscall_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.174 04-May-2020 kamil

Move register tests out of t_ptrace_wait.c to t_ptrace_register_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.


# 1.173 24-Apr-2020 kamil

Reduce assumptions about LWP numbers


# 1.172 24-Apr-2020 thorpej

Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP
process is the PID, not 1.


Revision tags: phil-wifi-20200421
# 1.171 17-Apr-2020 kamil

Switch from C11 specific static_assert() to __CTASSERT()


# 1.170 14-Apr-2020 kamil

Add timeout to syscall_signal_on_sce that hangs from time to time


Revision tags: phil-wifi-20200411 phil-wifi-20200406
# 1.169 07-Mar-2020 christos

Try to fix the build. This is why all those inlines should really be in a
separate file as regular function. The code is too large and hard to manage
this way, and only increases in complexity as time goes by.


# 1.168 06-Mar-2020 kamil

Move macros wrapping functions from msg.h into msg.h

This makes code reusing easier.


Revision tags: is-mlppp-base
# 1.167 01-Mar-2020 kamil

Add new signal trap entry tests in t_ptrace_wait*

New tests:
- syscall_signal_on_sce
- syscall_detach_on_sce

The first one fails as a signal emitted to the child is caught by the
debugger.

The second one passes.


# 1.166 24-Feb-2020 kamil

Add new test in t_ptrace_wait*

New test: syscall_killed_on_sce

Test passes correctly.


# 1.165 22-Feb-2020 kamil

Disable t_ptrace_wait* tests for MKSANITIZER/MKLIBCSANITIZER

A subset of tests is not compatible with the sanitizers.


# 1.164 20-Feb-2020 kamil

Minor changes to t_ptrace_wait*

Add check for security.models.extensions.user_set_dbregs in the
concurrent event tests.

Use unconditionally atf_tc_skip(); as the test is racy.


# 1.163 19-Feb-2020 kamil

Fix clang(1) build

Namespace a symbol that can be unused.


# 1.162 13-Feb-2020 mgorny

Enable combined breakpoint, watchpoint and signal tests


# 1.161 13-Feb-2020 mgorny

Extend concurrent events test to watchpoints


# 1.160 13-Feb-2020 mgorny

Extend concurrent events test to breakpoints

Add testing for concurrent breakpoint hits. The code is currently
x86-specific but since it reuses most of the generic concurrent event
test code, it's put in t_ptrace_wait.c with arch-specific hooks.


# 1.159 13-Feb-2020 mgorny

Include LWP events in concurrent event test

LWP events will be necessary when breakpoint/watchpoint support is added
to the test. However, they also benefit us by testing whether TRAP_LWP
events do not break signal reporting.


# 1.158 13-Feb-2020 mgorny

Test whether signal handler is called in concurrent bombarding


# 1.157 13-Feb-2020 mgorny

Extend concurrent signal tests to pass signal back to the thread


# 1.156 13-Feb-2020 mgorny

Generalize thread_concurrent_signals to a generic factory

Build thread_concurrent_signals on a generic parametrized
thread_concurrent_test() function. At first, this permits adjusting
the number of running signal threads but in the followup commits
support for different concurrent events (breakpoints, watchpoints)
and different signal handling will be added.


# 1.155 11-Feb-2020 kamil

Rewrite the t_ptrace_wait resume1 test

Switch to pthread functions.
Rename to 'resume'.
Synchronize the threads with pthread barriers.
Avoid race in the test.

Test passes correctly.

Fixes PR bin/54893 by Andreas Gustafsson


# 1.154 10-Feb-2020 kamil

Rename suspend2 to suspend_no_deadlock


# 1.153 05-Feb-2020 kamil

Refactor signal9 and signal10 tests in t_ptrace_wait*

Remove signal9 and signal10. Reimplement the idea of these test in new
trace_thread_lwpexit_masked_sigtrap, trace_thread_lwpcreate_masked_sigtrap
and trace_thread_lwpcreate_and_exit_masked_sigtrap.

This removes 2 tests directly using low-level lwp APIs.


# 1.152 04-Feb-2020 kamil

Disable debug code


# 1.151 04-Feb-2020 kamil

Add new ATF ptrace(2) test in t_ptrace_wait*

threads_and_exec - verify that the expected LWP events are reported for a
multithreaded process that calls execve(2).

Test passes.


# 1.150 04-Feb-2020 kamil

Add new ATF tests for unrelated tracer in t_ptrace_wait*

New tests:
- unrelated_tracer_posix_spawn_detach_spawner
- unrelated_tracer_fork_detach_forker
- unrelated_tracer_vfork_detach_vforker
- unrelated_tracer_vfork_detach_vforkerdone
- unrelated_tracer_posix_spawn_kill_spawner
- unrelated_tracer_fork_kill_forker
- unrelated_tracer_vfork_kill_vforker
- unrelated_tracer_vfork_kill_vforkerdone

All tests pass.


# 1.149 29-Jan-2020 kamil

Add new fork/vfork/posix_spawn ATF tests in t_ptrace_wait*

Add unrelated tracer variation of tests: fork1-16, vfork1-16,
posix_spawn1-16.

All tests pass.


# 1.148 23-Jan-2020 martin

Fix the build: access_regs_set_unaligned_pc_* tests depend on availability
of gpregs


# 1.147 21-Jan-2020 kamil

Add new ATF tests in t_ptrace_wait*

New tests:
- access_regs_set_unaligned_pc_0x1
- access_regs_set_unaligned_pc_0x3
- access_regs_set_unaligned_pc_0x7

The purpose of these tests is check whether unaligned PC can panic the
kernel. If there is a panic it is fine to return EINVAL on PT_SETREGS.
New tests check respectively pc |= 0x1, pc |= 0x3 and pc |= 0x7.

Inspired by https://marc.info/?l=openbsd-bugs&m=107558043319084&w=2

While there fix access_regs6 to really test PT_SETREGS.


# 1.146 08-Jan-2020 mgorny

Fix alignment when reading core notes

Both desc and note header needs to be aligned. Therefore, we need
to realign after skipping past desc as well.

While at it, fix the other alignment fix to use roundup() macro.


# 1.145 25-Dec-2019 kamil

Read TLS base pointer with _lwp_getprivate()

This avoid usage of fast versions that are mostly internal to RTLD.


# 1.144 24-Dec-2019 kamil

Define _RTLD_SOURCE in t_ptrace_wait.c

The __lwp_gettcb_fast() and __lwp_getprivate_fast() functions are
namespaced on a selection of ports.


# 1.143 24-Dec-2019 kamil

Introduce PT_LWPSTATUS + PT_LWPNEXT, obsolete PT_LWPINFO

PT_LWPINFO is a legacy ptrace(2) operation that was originally intended
to retrieve the thread (LWP) information inside a traced process.

It has a number of flaws and is confused with PT_LWPINFO from FreeBSD.

PT_LWPSTATUS and PT_LWPNEXT address the problems (shortly by: rename,
removal of pl_event) and introduces new features: signal context
(pl_sigpend, pl_sigmask), LWP name (pl_name), LWP TLS base address
(pl_private). The private pointer was so far missing information for
a debugger.

PT_LWPSTATUS@nnn is now shipped with core(5) files and contain LWP specific
information, so far missed in the core(5) files.

PT_LWPSTATUS retrieves LWP information for the prompted thread.
PT_LWPNEXT retrieves LWP information for the next thread, borrowing the
semantics from NetBSD specific PT_LWPINFO.

PT_LWPINFO is namespaced with __LEGACY_PT_LWPINFO and still available for
the foreseeable future, without plans of removing it.

Add ATF tests for PT_LWPSTATUS + PT_LWPNEXT.

Keep ATF tests for PT_LWPINFO.

Switch GDB to new API.

Proposed on tech-kern@.


# 1.142 06-Dec-2019 kamil

Log PID.LWP in t_ptrace_wait* tests for enabled debug

This is useful for multithreaded test scenarios.


Revision tags: phil-wifi-20191119
# 1.141 12-Nov-2019 kamil

Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by <mgorny>, tested and tweaked by myself.


# 1.140 21-Oct-2019 kamil

Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.


# 1.139 21-Oct-2019 kamil

Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.


# 1.138 21-Oct-2019 mgorny

Fix a race condition when handling concurrent LWP signals and add a test

Fix a race condition that caused PT_GET_SIGINFO to return incorrect
information when multiple signals were delivered concurrently
to different LWPs. Add a regression test that verifies that when 50
threads concurrently use pthread_kill() on themselves, the debugger
receives all signals with correct information.

The kernel uses separate signal queues for each LWP. However,
the signal context used to implement PT_GET_SIGINFO is stored in 'struct
proc' and therefore common to all LWPs in the process. Previously,
this member was filled in kpsignal2(), i.e. when the signal was sent.
This meant that if another LWP managed to send another signal
concurrently, the data was overwritten before the process was stopped.

As a result, PT_GET_SIGINFO did not report the correct LWP and signal
(it could even report a different signal than wait()). This can be
quite reliably reproduced with the number of 20 LWPs, however it can
also occur with 10.

This patch moves setting of signal context to issignal(), just before
the process is actually stopped. The data is taken from per-LWP
or per-process signal queue. The added test confirms that the debugger
correctly receives all signals, and PT_GET_SIGINFO reports both correct
LWP and signal number.

Reviewed by kamil.


# 1.137 13-Oct-2019 kamil

Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.


# 1.136 13-Oct-2019 kamil

Enable TEST_LWP_ENABLED in t_ptrace_wait*

The LWP events (created, exited) are now reliable in my local tests.

PR kern/51420
PR kern/51995


# 1.135 13-Oct-2019 kamil

Bump the number of threads in LWP t_ptrace_wait*() tests from to 100

This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:

- trace_thread_nolwpevents
- trace_thread_lwpexit
- trace_thread_lwpcreate
- trace_thread_lwpcreate_and_exit


# 1.134 02-Oct-2019 kamil

Remove ATF t_ptrace_wait test suspend1

The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.


# 1.133 01-Oct-2019 kamil

Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests

Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).


# 1.132 01-Oct-2019 kamil

Add a few static asserts in t_ptrace_wait.c for conditions that must be kept

Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.


Revision tags: netbsd-9-base
# 1.131 01-Jul-2019 kamil

branches: 1.131.2;
Avoid GCC warning on NetBSD/i386

Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
signedness bit shifts.


# 1.130 30-Jun-2019 mgorny

Add a test for verifying procinfo note inside coredumps.

Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it. The test finds procinfo note
and checks its contents.

The core dump is processed through libelf. However, it only provides
for finding all note segments (or sections?). I had to implement
finding and processing individual notes myself. I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.


# 1.129 26-Jun-2019 mgorny

Implement PT_GETXSTATE and PT_SETXSTATE

Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386. At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers. It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled. The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'. The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument. This requires the caller to explicitly specify the buffer
size. As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).


# 1.128 18-Jun-2019 kamil

Allow to conditionally enable LWP ATF tests in t_ptrace_wait*

By default the tests are disabled.


# 1.127 13-Jun-2019 kamil

Enable vfork(2) ATF tests in t_ptrace_wait*

The racing issues are gone in my local setup.


# 1.126 12-Jun-2019 kamil

Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork

New tests:
- posix_spawn_detach_spawner
- posix_spawn_kill_spawner
- posix_spawn_singalmasked
- posix_spawn_singalignored

All test pass.


# 1.125 11-Jun-2019 kamil

Add new PTRACE_POSIX_SPAWN tests in ptrace(3)

Add test:
- eventmask_preserved_posix_spawn
- fork9..fork16
- vfork9..vfork16
- posix_spawn1..16

New tests verify semantics of PTRACE_POSIX_SPAWN.

All tests pass.


# 1.124 10-Jun-2019 kamil

Add posix_spawn(3) ATF tests in t_ptrace_wait*

New tests verify whether forking process reports forking events to a
debugger.

Right now there is no support in the kernel for this system.


# 1.123 10-Jun-2019 kamil

Add more verbosity to debug messages in t_ptrace_wait

Log func() file:line for each debug message.

Most messages are similar one with the other and this change allows easier
navigation in the code.


Revision tags: phil-wifi-20190609
# 1.122 25-May-2019 kamil

Add new user_va0_disable* tests in t_ptrace_wait*

Add tests:
- user_va0_disable_pt_continue
- user_va0_disable_pt_syscall
- user_va0_disable_pt_detach

Assert that setting PC to 0x0 in PT_CONTINUE/PT_SYSCALL/PT_DETACH for
vm.user_va0_disable==0 is disallowed.


# 1.121 09-May-2019 mgorny

Add ptrace() tests for reading mm* and xmm* registers


# 1.120 02-May-2019 kamil

Adapt t_ptrace_wait* tests for recent kernel changes

Adapt AUXV reading loop to handle io.piod_len == 0 as EOF.

Temporarily disable trace_thread_lwpcreate until it will be verified that
it is stable.


# 1.119 02-May-2019 kamil

Rename and partially enable trace_thread ATF ptrace(2) tests

Rename trace_thrad[1234] to more meaningful names:

- trace_thread_nolwpevents
- trace_thread_lwpexit
- trace_thread_lwpcreate
- trace_thread_lwpcreate_and_exit

In my local tests LWP CREATE events work as expected.
LWP EXIT ones are still racy and keep them disabled racy.

PR kern/51995


# 1.118 01-May-2019 kamil

ATF ptrace(2) tests suspend1 and resume1 now pass

Verified on bare metal and in qemu.

PR kern/51995


# 1.117 01-May-2019 kamil

ATF ptrace(2) tests signal9 and signal10 now pass

PR kern/51918


# 1.116 01-May-2019 kamil

Add new fork/vfork ATF trests in t_ptrace_wait*

Add new tests:

- fork_detach_forker
- vfork_detach_vforker
- vfork_detach_vforkerdone
- fork_kill_forker
- vfork_kill_vforker
- vfork_kill_vforkerdone

All tests pass with recent kernel changes.


# 1.115 30-Apr-2019 kamil

Add new ATF ptrace(2) tests: bytes_transfer_eof

Assert that error is returned after attempt to read or write post EOF.


# 1.114 25-Apr-2019 kamil

Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c


# 1.113 25-Apr-2019 kamil

Do not allow 0 as ILL si_code as it's reserved for SI_USER


# 1.112 25-Apr-2019 kamil

In ATF t_ptrace_wait* SIGILL tests allow any si_code

These codes are not portable between CPUs and kernels.

Change the checks to return any valid si_code in the defined range of ILL
values.

PR port-sparc/54140 by Andreas Gustafsson


# 1.111 19-Apr-2019 kamil

Fix typo in TEST_VFORK_ENABLED

This allows building and running vfork(2) test scenarios correctly.


# 1.110 17-Apr-2019 kamil

Fix Clang/LLVM build in t_ptrace_wait.c

Do not compile functions that might be unused.


# 1.109 15-Apr-2019 kamil

Temporarily ifdef out PTRACE_VFORK and PTRACE_VFORKDONE tests

It's not reliable on all ports. sparc and evbarm are known to hang.

PR kern/54111 by Martin Husemann


# 1.108 11-Apr-2019 kamil

Add new tests in ATF t_prace_wait*

New tests:

- traceme_vfork_fork
- traceme_vfork_vfork

New tests assert that fork/vfork in vforked traced does not emit any
events.


# 1.107 11-Apr-2019 kamil

Add new tests traceme_vfork_clone* in ATF t_ptrace_wait*

Added tests:

- traceme_vfork_clone
- traceme_vfork_clone_vm
- traceme_vfork_clone_fs
- traceme_vfork_clone_files
- traceme_vfork_clone_sighand
- traceme_vfork_clone_vfork

All tests pass. Validate that children do not trigger any signals and dead
locks when traced by a vfork(2)ed parent.


# 1.106 11-Apr-2019 kamil

Validate that clone(2) is handled properly with more ptrace(2) ATF tests

New tests:

- clone[1-8]
- clone_vm[1-8]
- clone_fs[1-8]
- clone_files[1-8]
- clone_sighand[1-8] // disabled temporarily
- clone_vfork[1-8]

Assert that appropriate events are triggered for the combination of:

- PTRACE_FORK
- PTRACE_VFORK
- PTRACE_VFORK_DONE


# 1.105 06-Apr-2019 kamil

Simplify FORK_TEST in ATF t_ptrace_wait*

Reduce the scope of combinations that were planned to be tested from the
same function body.

NFCI


# 1.104 05-Apr-2019 kamil

Reenable tests vfork7 and vfork8 in ATF t_ptrace_wait*

These tests used to hang on SMP machines.

For experiment after recent changes reenable the tests.


# 1.103 05-Apr-2019 kamil

Add __clone(2) tests in t_ptrace_wait*

The __clone(2) API is a variation of fork(2)/vfork(2) operations.

New tests:
- clone_signalignored
- clone_signalmasked
- clone_vm_signalignored
- clone_vm_signalmasked
- clone_fs_signalignored
- clone_fs_signalmasked
- clone_files_signalignored
- clone_files_signalmasked
- clone_vfork_signalignored
- clone_vfork_signalmasked

All new tests pass.

CLONE_SIGHAND tests are right now disabled as they cannot reuse the shared
signal operations (wait(2)) to wait for a clonee.

Another nit is that wait(2) must be used right now with WALLSIG as for some
reason the default variation doesn't work.


# 1.102 03-Apr-2019 kamil

The *fork*_signalmasked ATF tests no longer fail

Add a fixup for signalmasking in the vforkdone_singalmasked test.


# 1.101 28-Mar-2019 kamil

Add new ATF ptrace(2) tests bytes_transfer_alignment*

Verify bytes transfer for potentially misaligned operation.

New tests:

- bytes_transfer_alignment_pt_read_i
- bytes_transfer_alignment_pt_read_d
- bytes_transfer_alignment_pt_write_i
- bytes_transfer_alignment_pt_write_d
- bytes_transfer_alignment_piod_read_i
- bytes_transfer_alignment_piod_read_d
- bytes_transfer_alignment_piod_write_i
- bytes_transfer_alignment_piod_write_d
- bytes_transfer_alignment_piod_read_auxv

All tests pass (at least on x86_64).


# 1.100 08-Mar-2019 kamil

Remove expected fail in various ATF t_ptrace_wait* tests

Tests for trap signal scenarios no longer fail.


# 1.99 02-Mar-2019 kamil

Refactor signal6-8 tests in t_ptrace_wait*

Transform original tests into new ones:
- fork_singalmasked
- fork_singalignored
- vfork_singalmasked
- vfork_singalignored
- vforkdone_singalmasked
- vforkdone_singalignored

All the signalignored ones pass, the remaining ones of them fail.


# 1.98 23-Feb-2019 kamil

Drop signal5 test-case from ATF t_ptrace_wait*

This test is now duplicated with traceme_signalmasked_exec.


# 1.97 23-Feb-2019 kamil

Add signal masked and ignored variations of traceme_exec in ATF tests

All tests pass.


# 1.96 23-Feb-2019 kamil

Add signal masked and ignored variations of traceme_vfork_exec in ATF tests

All tests pass.


# 1.95 20-Feb-2019 kamil

Replace signal4 (PT_STEP) test with refactored ones with extra asserts

New tests: step_signalmasked and step_signalignored.

Assert that signal context is not reset upon PT_STEP trap.

Mark new tests as expecting to fail.


# 1.94 20-Feb-2019 kamil

Add more tests for variations of unrelated_tracer_sees_crash in ATF

New tests:
- unrelated_tracer_sees_signalmasked_crash_trap
- unrelated_tracer_sees_signalmasked_crash_segv
- unrelated_tracer_sees_signalmasked_crash_ill
- unrelated_tracer_sees_signalmasked_crash_fpe
- unrelated_tracer_sees_signalmasked_crash_bus
- unrelated_tracer_sees_signalignored_crash_trap
- unrelated_tracer_sees_signalignored_crash_segv
- unrelated_tracer_sees_signalignored_crash_ill
- unrelated_tracer_sees_signalignored_crash_fpe
- unrelated_tracer_sees_signalignored_crash_bus

All these tests are failing with the current kernel.


# 1.93 20-Feb-2019 kamil

Add minor improvements in unrelated_tracer_sees_crash in t_ptrace_wait*

Switch forkee commands with asserts to be aligned for the purpose of being
used by forkees.


# 1.92 17-Feb-2019 kamil

Add new ATF t_ptrace_wait* vfork(2) tests

Add traceme_vfork_signalmasked_crash and traceme_vfork_signalignored_crash
tests for crash signals (SIGTRAP, SIGSEGV, SIGILL, SIGFPE, SIGBUS).

These new scenario assert that signal masked/ignored are delivered to
vfork(2)ed child.

All tests pass.


# 1.91 17-Feb-2019 kamil

Remove redundant test from ATF t_ptrace_wait*

signal3 duplicates traceme_signalmasked_crash(SIGSEGV)


# 1.90 17-Feb-2019 kamil

Add additional assert in traceme_signalignored_crash t_ptrace_wait* tests

Check whether sigignore is not reset on a trapsignal under a debugger.
The expected behavior is to not reset it. A side effect of resetting
signal mask is noticable especially with a software/hardware breakpoint
that changes state of a process.

Mark these tests as failing.


# 1.89 17-Feb-2019 kamil

Add additional assert in traceme_signalmasked_crash t_ptrace_wait* tests

Check whether signal mask is not reset on a trapsignal under a debugger.
The expected behavior is to not reset it. A side effect of resetting
signal mask is noticable especially with a software/hardware breakpoint
that changes state of a process.

Mark these tests as failing.


# 1.88 15-Feb-2019 kamil

Add new ATF tests traceme_signal{ignored,masked}_crash* in t_ptrace_wait*

New tests verify that crashes (from trap signals) are delivered to tracer
regardless of the signal masking or signal ignoring option enabled in the
traced child.

All tests pass.

In close future these tests will obtain additional asserts.


# 1.87 15-Feb-2019 kamil

Add new ATF tests traceme_raisesignal_ignored in t_ptrace_wait*

Verify that ignoring (with SIG_IGN) in tracee
does not stop tracer from catching this raised signal.

Cover crash signals and already covered ones in other tests.

All tests pass.


# 1.86 14-Feb-2019 kamil

Replace signal2 in t_ptrace_wait* with new tests

Add new tests traceme_raisesignal_masked[1-8].

New tests to verify that masking (with SIG_BLOCK) signal in tracee
stops tracer from catching this raised signal. Masked crash signals are
invisible to tracer as well.

All tests pass.


# 1.85 14-Feb-2019 kamil

Add new regression scenarios for crash signals in t_ptrace_wait*

Verify correct behavior of crash signals (SIGTRAP, SIGBUS, SIGILL, SIGFPE,
SIGSEGV) in existing test scenarios:
- traceme_raise
- traceme_sendsignal_handle
- traceme_sendsignal_masked
- traceme_sendsignal_ignored
- traceme_sendsignal_simple
- traceme_vfork_raise

These tests verify signals out of the context of CPU trap. These new tests
will help to retain expected behavior in future changes in semantics of
the trapsignals in the kernel.


# 1.84 12-Feb-2019 kamil

Rename signal1 to signal_mask_unrelated in t_ptrace_wait*

No functional change intended.


# 1.83 12-Feb-2019 kamil

Refactor lwp_create1 and lwp_exit1 into trace_thread* in ptrace(2) tests

New tests:
- trace_thread1
- trace_thread2
- trace_thread3
- trace_thread4

These tests verify _lwp_create(2) and _lwp_exit(2) events. They are
currently skipped as not reliable.


# 1.82 11-Feb-2019 kamil

Rename the siginfo4 test in ATF t_ptrace_wait*

The siginfo group of ptrace(2) tests has been replaced with new individual
tests or merged into existing ones. This is the last siginfo* test that
has been renamed.

New name: traceme_exec.


# 1.81 11-Feb-2019 kamil

Merge siginfo6 into other PT_STEP tests in t_ptrace_wait*


# 1.80 11-Feb-2019 kamil

Drop siginfo5 from ATF tests in t_ptrace_wait*

siginfo5 duplicates older tests verifying PTRACE_FORK.


# 1.79 11-Feb-2019 kamil

Initial refactoring of siginfo* tests in t_ptrace_wait*

Drop test siginfo1 as duplicated with earlier tests.

Rework and rename siginfo2 and siginfo3 into a single test body.

New tests:
- siginfo_set_unmodified (replaces siginfo2)
- siginfo_set_faked (replaces siginfo3)

All new tests pass.


# 1.78 10-Feb-2019 kamil

Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.


# 1.77 10-Feb-2019 kamil

Add initial pthread(3) tests in ATF t_prace_wait* tests

There were tested few scenarios with native _lwp_create(2) functions, using
this interface is not needed and it's easier to manage tests with
high-level pthread(3) API.

Rewrite original lwpinfo1 and lwpinfo2 tests into 8 new tests:
- traceme_lwpinfo0 (0 spawned additional threads)
- traceme_lwpinfo1 (1 spawned additional thread)
- traceme_lwpinfo2 (2 spawned additional threads)
- traceme_lwpinfo3 (3 spawned additional threads)
- attach_lwpinfo0 (0 spawned additional threads)
- attach_lwpinfo1 (1 spawned additional thread)
- attach_lwpinfo2 (2 spawned additional threads)
- attach_lwpinfo3 (3 spawned additional threads)

These tests verify primarily the PT_LWPINFO interface.

Build the t_ptrace_wait* tests with -pthread.

All tests pass.


# 1.76 09-Feb-2019 scole

use HAVE_FPREGS not HAVE_FPGPREGS and move some register_t inside proper #define. fixes ia64 build. ok <kamil>


# 1.75 08-Feb-2019 kamil

Refactor kill* test in t_ptrace_wait*

Drop original scenario of kill1 (PT_CONTINUE(SIGKILL)) as it duplicates
traceme_sendsignal_simple1.

New kill tests:
- kill1: ptrace(PT_KILL) (previously kill2)
- kill2: kill(SIGKILL)
- kill3: killpg(SIGKILL)

All kill* tests share the same function body.

All tests pass.


# 1.74 08-Feb-2019 kamil

Correct a style in description of PT_STEP tests in t_ptrace_wait*


# 1.73 08-Feb-2019 kamil

Refactor definition of PT_STEP tests into single macro

No functional change intended.


# 1.72 07-Feb-2019 kamil

Refactor GPR and FPR tests in t_ptrace_wait* tests

This change deduplicates the code and puts all the test into shared
function body.

No functional change except ranaming tests regs* to access_regs* and
fpregs* to access_fpregs*.


# 1.71 07-Feb-2019 kamil

Enable 3 new ptrace(2) tests for SIGILL

Add missing code for SIGILL verification and enable new SIGILL tests:
- traceme_crash_ill
- traceme_vfork_crash_ill
- unrelated_tracer_sees_crash_ill

SIGILL is caused by a crash signal and needs special treatement that has
to be asserted to behave correctly.

In the unrelated_tracer_sees_crash* tests add additional check to catch
scenarios when a test dies due to abnormal condition and it's not caught
as the tracer is collected by initproc.

All tests pass on NetBSD/amd64, other ports have temporarily unimplemented
PTRACE_ILLEGAL_ASM.


# 1.70 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127
# 1.69 22-Jan-2019 kamil

Mark traceme_vfork_crash_bus as no longer failing

Fixed in src/sys/kern/core_elf32.c r. 1.58

Closes PR lib/53343


Revision tags: pgoyette-compat-20190118
# 1.68 13-Jan-2019 gson

Don't mark the traceme_vfork_crash_bus test case as an expected failure
when it is executing as part of the lib/libc/sys/t_ptrace_waitid test,
because that particular combination is not failing, at least not on amd64.
It is failing as part of other tests, so PR lib/53343 still applies.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906
# 1.67 13-Aug-2018 kamil

Add a new ATF ptrace(2) test: tracer_attach_to_unrelated_stopped_process

Reuse the body of tracer_sees_terminaton_before_the_parent_raw for a test
attaching to an unrelated stopped process.

This test passes.


# 1.66 13-Aug-2018 kamil

Add a new ATF test parent_attach_to_its_stopped_child

Reuse the body of parent_attach_to_its_child for a test attaching to a
stopped child.

This test passes.


# 1.65 13-Aug-2018 kamil

Add a new ATF ptrace(2) test: child_attach_to_its_stopped_parent

Reuse the body of child_attach_to_its_parent for a test attaching to a
stopped parent.

As a workaround to ATF framework (atf-run), run this test in a subprocess.
The raise(SIGSTOP) call breaks the pipe from atf-run, that is polling
whether a process is in order.
According to code inspection the poll(2) call in safe_poll() receives
EINTR and this tears down the test.

This test passes.


Revision tags: pgoyette-compat-0728
# 1.64 17-Jul-2018 martin

Comment out two tests that regularily hang on SMP machines (with unkillable
helper/child processes, so ATF timeout does not help).
Kamil knows about the SMP race in traced exit path and said he'll handle
it.
I would have skipped them on SMP machines only, but got lost in the
macro labyrinth - kamil, please feel free to improve ;-)


Revision tags: phil-wifi-base pgoyette-compat-0625
# 1.63 06-Jun-2018 kamil

branches: 1.63.2;
Fix previous

The failing tests are for vfork(2), not fork(2).


# 1.62 06-Jun-2018 kamil

Mark sigbus ATF tests in t_ptrace_wait as expected failure

They are breaking right now on all ports.

lib/53343


# 1.61 01-Jun-2018 kre

80 column police. Some KNF and whitespace corrections (until I got bored...)
NFCI.


# 1.60 30-May-2018 kre

The bytes_transfer_piod_read_auxv test uses 4096 for the size param
to bytes_transfer() which asserted that the size is < the size of 512 AuxInfo
structs. On a 32 bit system, an AuxInfo is 8 bytes, and 512 AuxInfo
structs is thus 4096 bytes, and 4096 is not < 4096, so the assertion
failed. It would probably work as a <= assert, but I am not confident
enough with this test case to make that call, so instead increase the
array size to be 513 instead, 4096 is < 513*8 so happiness should return
and all should be right with the world. At least for this one test.
(There was no problem on 64 bit systems as AuxInfo is bigger there.)


# 1.59 29-May-2018 kamil

Add new ATF ptrace(2) tests verifying crash signal handling

Add new tests:
- traceme_crash_trap
- traceme_crash_segv
- traceme_crash_ill (temporarily disabled)
- traceme_crash_fpe
- traceme_crash_bus
- unrelated_tracer_sees_crash_trap
- unrelated_tracer_sees_crash_segv
- unrelated_tracer_sees_crash_ill (temporarily disabled)
- unrelated_tracer_sees_crash_fpe
- unrelated_tracer_sees_crash_bus

These tests verify two subtle kernel paths that differ internally:
- for a tracer that is a parent of a traced program (and not vforked)
real parent == tracer
- for a tracer that is an unrelated process of a traced program
real parent != tracer

Regressions in the signal code can cause to break one of the scenarios, and
keep working the other one. It might be propagated to a scenario like:
- attaching to a process with a debugger (over pid)
- starting a process inside a debugger

We can assert on the ATF level that both will be functional.

While there, cover all the crash signals as testing is done practically
for free. While the Machine Independent signal routing code for crash
signals is mostly the same in the kernel, we can verify whether Machine
Dependent parts works as expected emitting the proper signal number and
signal code (si_code).

There have been already caught an unexpected behavior on Alpha, that
instead of SIGBUS we receive SIGSEGV.

Another benefit is that it's easier to catch races, as they pop up more
frequently. (This already helped to catch bugs more quickly)

These tests will help assert correctness of future kernel changes in the
signal routines.

All tests pass.

Sponsored by <The NetBSD Foundation>


# 1.58 28-May-2018 kamil

Correct the t_ptrace_wait*:signal5 ATF test case

This functionality now works.
Correct the code path in this test.
Add additional sanity check with PT_GET_SIGINFO and validating si_code.

Sponsored by <The NetBSD Foundation>


# 1.57 28-May-2018 kamil

Drop trailing white space


# 1.56 27-May-2018 kamil

Fix ATF ptrace(2) bytes_transfer_piod_read_auxv test

Make the initial buffer larger to stop triggering the runtime assert about
its size.

Its size is probably larger than all real use cases, but it's good enough
for the purpose of ATF tests and immune of potential AUXV size.

Sponsored by <The NetBSD Foundation>


# 1.55 27-May-2018 christos

alloca, bad; stack protector, good.


# 1.54 26-May-2018 kamil

Refactor the PT_WRITE*/PT_READ* and PIOD_* ATF ptrace(2) tests

Merge all the PT_WRITE*/PT_READ* and PIOD_* the test cases into the common
body.

Changes:
- treat D and I variations exactly the same
- stop testing 2-3-4 attempts to perform the same read/write operation
- stop testing interlocked (handshake) read/write operations
- rename the tests
- test write to .text section (with D and I type of operations)

New tests:
- bytes_transfer_piod_read_d_8
- bytes_transfer_piod_read_d_16
- bytes_transfer_piod_read_d_32
- bytes_transfer_piod_read_d_64
- bytes_transfer_piod_read_i_8
- bytes_transfer_piod_read_i_16
- bytes_transfer_piod_read_i_32
- bytes_transfer_piod_read_i_64
- bytes_transfer_piod_write_d_8
- bytes_transfer_piod_write_d_16
- bytes_transfer_piod_write_d_32
- bytes_transfer_piod_write_d_64
- bytes_transfer_piod_write_i_8
- bytes_transfer_piod_write_i_16
- bytes_transfer_piod_write_i_32
- bytes_transfer_piod_write_i_64
- bytes_transfer_read_d
- bytes_transfer_read_i
- bytes_transfer_write_d
- bytes_transfer_write_i
- bytes_transfer_piod_read_d_8_text
- bytes_transfer_piod_read_d_16_text
- bytes_transfer_piod_read_d_32_text
- bytes_transfer_piod_read_d_64_text
- bytes_transfer_piod_read_i_8_text
- bytes_transfer_piod_read_i_16_text
- bytes_transfer_piod_read_i_32_text
- bytes_transfer_piod_read_i_64_text
- bytes_transfer_piod_write_d_8_text
- bytes_transfer_piod_write_d_16_text
- bytes_transfer_piod_write_d_32_text
- bytes_transfer_piod_write_d_64_text
- bytes_transfer_piod_write_i_8_text
- bytes_transfer_piod_write_i_16_text
- bytes_transfer_piod_write_i_32_text
- bytes_transfer_piod_write_i_64_text
- bytes_transfer_read_d_text
- bytes_transfer_read_i_text
- bytes_transfer_write_d_text
- bytes_transfer_write_i_text
- bytes_transfer_piod_read_auxv

These tests are now covering all usual code paths.

All tests pass.
The PaX MPROTECT violating ones automatically detect whether to be skipped.

Eliminated 4x more code than removed.

Sponsored by <The NetBSD Foundation>


# 1.53 23-May-2018 kamil

Merge the eventmask[1-6] ATF ptrace(2) tests into a shared function body

While there, rename the tests to:
- eventmask_preserved_empty
- eventmask_preserved_fork
- eventmask_preserved_lwp_create
- eventmask_preserved_lwp_exit
- eventmask_preserved_vfork
- eventmask_preserved_vfork_done

Sponsored by <The NetBSD Foundation>


# 1.52 23-May-2018 kamil

Extend traceme_vfork_breakpoint in ATF ptrace(2) tests for more scenarios

traceme_vfork_breakpoint used to test SIGTRAP event. Reuse its code for:
SIGSEGV, SIGILL, SIGFPE and SIGBUS.

The SIGILL case is disabled as of now as it required addition of
PTRACE_ILLEGAL_ASM in MD ptrace(2) headers.

Added tests:
- traceme_vfork_crash_trap
- traceme_vfork_crash_segv (renamed from traceme_vfork_breakpoint)
- traceme_vfork_crash_ill (disabled)
- traceme_vfork_crash_fpe
- traceme_vfork_crash_bus

All enabled tests pass.

Sponsored by <The NetBSD Foundation>


# 1.51 23-May-2018 kamil

Refactor the attach[1-8] and race1 ATF t_ptrace_wait* tests

Share code in: attach1, attach2 and race1 in the same function body.
Rename thsee tests to more verbose names:
- tracer_sees_terminaton_before_the_parent
- tracer_sysctl_lookup_without_duplicates
- unrelated_tracer_sees_terminaton_before_the_parent

Rename attach3 to parent_attach_to_its_child.

Rename attach4 to child_attach_to_its_parent.

Share code in attach5, attach6 and attach7 in the same function body and
reanem the tests to:
- tracee_sees_its_original_parent_getppid
- tracee_sees_its_original_parent_sysctl_kinfo_proc2
- tracee_sees_its_original_parent_procfs_status

Reduce the code by around 50%.

No functional change intended. All tests pass.

Sponsored by <The NetBSD Foundation>


# 1.50 22-May-2018 kamil

Add new ATF ptrace(2) tests: traceme_sendsignal_{masked,ignored}[1-3]

These tests emit signal from a tracer/parent to the child and verify the
behavior in the case of SIG_BLOCK (masked) and SIG_IGN (ignored).

The signal is not reported by the child process.

These tests pass.

While there, rename for consistency with other tests:
- traceme_sighandler_catch[1-3] -> traceme_sendsignal_handle[1-3]
- traceme_signal_nohandler[1-5] -> traceme_sendsignal_simple[1-5]

Sponsored by <The NetBSD Foundation>


Revision tags: pgoyette-compat-0521
# 1.49 20-May-2018 kamil

Refactor and enable the signal3 ATF ptrace(2) test

Adapt the test to be independent from the software breakpoint trap
behavior, whether the Program Counter is moved or not. Just kill the
process after catching the expected signal, instead of pretending to resume
it.

This test passes.

Sponsored by <The NetBSD Foundation>


# 1.48 20-May-2018 kamil

Fix and enable traceme_signal_nohandler2 in ATF ptrace(2) tests

traceme_signal_nohandler2 checks emitting SIGSTOP to a traced process
with the PT_CONTINUE operation.

The expected behavior is to simulate a behavior of receiving SIGSTOP,
generating SIGCHLD to its parent (in this case the debugger) and ability
to call wait(2)-like function receiving the stopped child event.

The previous behavior was unstopping the process and it has been adjusted
in the kernel code.

FreeBSD keeps unstopping a process for emitting SIGSTOP.
Linux handles this scenario in the same way as NetBSD now.

While there, implement the missing bits in the userland ATF test for
traceme_signal_nohandler2: receiving and validating 2nd SIGSTOP event and
continuing the process, followed by its normal termination.

Sponsored by <The NetBSD Foundation>


# 1.47 19-May-2018 kamil

Cover SIGTSTP, SIGTTIN and SIGTTOU in traceme_vfork_raise ATF tests

SIGTSTP, SIGTTIN and SIGTTOU are special case signals ignored in a
vfork(2)ed child. Assert the behavior of raise(2) after calling
PT_TRACE_ME.

Renumber existing traceme_vfork_raise tests.

Sponsored by <The NetBSD Foundation>


# 1.46 19-May-2018 kamil

Enable traceme_vfork_raise2 in ATF ptrace(2) tests

raise(SIGSTOP) is now handled correctly by the kernel, in a child that
vfork(2)ed and called PT_TRACE_ME.

Implement a helper process emitting SIGKILL to a stopped child of a
vfork(2)ed process.

Sponsored by <The NetBSD Foundation>


# 1.45 16-May-2018 kamil

Add extra asserts in three ATF ptrace(2) tests

In traceme* tests after validate_status_stopped() include additional check
the verify the received signal with PT_GET_SIGINFO.

All tests passes.

Sponsored by <The NetBSD Foundation>


# 1.44 16-May-2018 kamil

Improve the description of traceme_vfork_breakpoint (ATF ptrace(2) test)

Sponsored by <The NetBSD Foundation>


# 1.43 16-May-2018 kamil

Add a new ATF ptrace(2) test: traceme_vfork_exec

Verify PT_TRACE_ME followed by exec(3) in a vfork(2)ed child.

This tests passes correctly.

Sponsored by <The NetBSD Foundation>


# 1.42 16-May-2018 kamil

Improve the description of traceme_vfork_raise in ATF ptrace(2) tests

Set new description to:
- "Verify PT_TRACE_ME followed by raise of " #sig " in a vfork(2)ed "
"child"

The previous one was copy pasted from a different ATF test and not changed.

Sponsored by <The NetBSD Foundation>


# 1.41 16-May-2018 kamil

Add a new ATF ptrace(2) test: traceme_vfork_breakpoint

Verify software breakpoint in a vfork(2)ed child.

The expected behavior is not to route this signal to the parent, even if
that parent is a tracer. The parent cannot handle it and it would lead to
the deadlock.

This test passes correctly.

Sponsored by <The NetBSD Foundation>


# 1.40 16-May-2018 kamil

Correct handling of: vfork(2) + PT_TRACE_ME + raise(2)

Follow the FreeBSD approach of not routing signals to the parent that is
a became tracer after calling PT_TRACE_ME by the vfork(2)ed child (before
exec(3)/exit(3)).

Now if a child calls raise(3), the signal is processed directly to this
child.

Add new ATF ptrace(2) tests:
- traceme_vfork_raise1 (SIGKILL)
- traceme_vfork_raise2 (SIGSTOP) // temporarily disabled
- traceme_vfork_raise3 (SIGABRT)
- traceme_vfork_raise4 (SIGHUP)
- traceme_vfork_raise5 (SIGCONT)

The FreeBSD implementation introduces P_PPTRACE for this special case.
Right know keep opencoding check of this case in the kernel. It might be
refactored in future.

The Linux kernel does not follow this approach and causes dead locking of
the processes (parent and child).

Defer handling SIGSTOP into future.

This is an intermediate step towards correct handling of fork(2) and
vfork(2) in the context of ptrace(2).

All new tests pass.
There are no regressions in existing ATF ptrace(2) tests.

Sponsored by <The NetBSD Foundation>


# 1.39 13-May-2018 kamil

Add a new ptrace(2) ATF exploit for: CVE-2018-8897 (POP SS debug exception)

The original expolit and mitigation have been developed by Maxime Villard.

I've reworked the shared code and adapted for the ATF context.
I've included PIE-aware version (RIP/EIP relative) and introduced
additional comments to the explanation how to trigger the flaw.

This test passes on NetBSD/8.99.17.

Sponsored by <The NetBSD Foundation>


Revision tags: pgoyette-compat-0502
# 1.38 01-May-2018 kamil

Implement PTRACE_VFORK

Add support for tracing vfork(2) events in the context of ptrace(2).

This API covers other frontends to fork1(9) like posix_spawn(2) or clone(2),
if they cause parent to wait for exec(2) or exit(2) of the child.

Changes:
- Add new argument to sigswitch() determining whether we need to acquire
the proc_lock or whether it's already held.
- Refactor fork1(9) for fork(2) and vfork(2)-like events.
Call sigswitch() from fork(1) for forking or vforking parent, instead of
emitting kpsignal(9). We need to emit the signal and suspend the parent,
returning to user and relock proc_lock.
- Add missing prototype for proc_stop_done() in kern_sig.c.
- Make sigswitch a public function accessible from other kernel code
including <sys/signalvar.h>.
- Remove an entry about unimplemented PTRACE_VFORK in the ptrace(2) man page.
- Permin PTRACE_VFORK in the ptrace(2) frontend for userland.
- Remove expected failure for unimplemented PTRACE_VFORK tests in the ATF
ptrace(2) test-suite.
- Relax signal routing constraints under a debugger for a vfork(2)ed child.
This intended to protect from signaling a parent of a vfork(2)ed child that
called PT_TRACE_ME, but wrongly misrouted other signals in vfork(2)
use-cases.

Add XXX comments about still existing problems and future enhancements:
- correct vfork(2) + PT_TRACE_ME handling.
- fork1(2) handling of scenarios when a process is collected in valid but
rare cases.

All ATF ptrace(2) fork[1-8] and vfork[1-8] tests pass.

Fix PR kern/51630 by Kamil Rytarowski (myself).

Sponsored by <The NetBSD Foundation>


# 1.37 29-Apr-2018 kamil

Add two new ptrace(2) ATF tests

Added:

- traceme_pid1_parent
Assert that a process cannot mark its parent a debugger twice

- traceme_twice
Verify that PT_TRACE_ME is not allowed when our parent is PID1

All tests pass.

Sponsored by <The NetBSD Foundation>


# 1.36 28-Apr-2018 kamil

Enable traceme_raise1 in the ATF ptrace(2) tests

This test checks raise(SIGKILL). If we enter the kernel with this signal
we report a signaled child in a debugger, not stopped with an option to
make an action.

FreeBSD behaves differently and allows intercepting this event in a tracer.
Follow the Linux behavior.

If we really want to prevent raise(SIGKILL) from signaling the tracee, we
still can breakpoint raise(3) and alter the syscall arguments (or use
the PT_SYSCALL mode). If we are already in the kernel, SIGKILL always means
killing the process, whether or not traced and the source of SIGKILL.

This tests passes on NetBSD without kernel changes.

Sponsored by <The NetBSD Foundation>


# 1.35 28-Apr-2018 kamil

Refactor the traceme3 ATF ptrace(2) test

Replace traceme3 with new ATF tests using diverse signals:

- traceme_signal_nohandler1 SIGKILL
- traceme_signal_nohandler2 SIGSTOP (temporarily disabled)
- traceme_signal_nohandler3 SIGABRT (emits core dump)
- traceme_signal_nohandler4 SIGHUP
- traceme_signal_nohandler5 SIGCONT

These SIGSTOP test does not work properly right now as it unstops the
traccee.

Sponsored by <The NetBSD Foundation>


# 1.34 28-Apr-2018 kamil

Refactor the traceme2 ATF ptrace(2) tests

Replace traceme2 with 3 tests:
- traceme_sighandler_catch1
- traceme_sighandler_catch2
- traceme_sighandler_catch3

These tests are verified with PT_TRACE_ME for: SIGHUP, SIGCONT and SIGABRT.

We don't want tests all signals (this is a domain for a fuzzer), but we want
to cover tests with signals from different groups.

All tests pass.

Sponsored by <The NetBSD Foundation>


# 1.33 27-Apr-2018 kamil

Refactor the traceme1 and traceme4 ATF ptrace(2) tests

Use common bode for these tests and a macro 1-liner to define a new test.

Test the same scenarios for 5 signals:
- SIGKILL (temporarily disabled)
- SIGSTOP
- SIGABRT
- SIGHUP
- SIGCONT

These tests call: raise(sig). It's actually important to assert their
behavior for tests that are from different kinds.

The SIGKILL test is work in progress. It can be caught by a debugger on the
FreeBSD kernel, but it's causing a signaled event in a debugger on Linux.

NetBSD is right now in one of the camps, but research whether this is a bug
or feature is in progress.

Sponsored by <The NetBSD Foundation>


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 1.32 15-Apr-2018 kamil

Refactor fork-like ATG tests in t_ptrace_wait*

Add CPP syntax sugare to define each fork-like test within a single line
of code with less than 80 columns.

This is a preparation for new fork-like scenarios where we detach either
child and/or parent with PT_DETACH.

The code could be still reduced to smaller number of columns, instead of:

FORK_TEST(fork1, DSCR(fork,0,0,0,0,0), fork, F, F, F, F, F)

we could perhaps need 50% of it, as the data is duplicated.

On the other hand the line is already short and taking only a single line.

No functional change intended.

Sponsored by <The NetBSD Foundation>


# 1.31 11-Apr-2018 kamil

Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.

Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>


# 1.30 10-Apr-2018 kamil

ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.

PR kern/51630

Sponsored by <The NetBSD Foundation>


# 1.29 10-Apr-2018 kamil

ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones

Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>


# 1.28 10-Apr-2018 kamil

Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.
Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>


# 1.27 09-Apr-2018 kamil

Improve documentation of the ATF test t_ptrace_wait*: traceme2

Set the description to:

Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315
# 1.26 13-Mar-2018 kamil

ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported

race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7).
A buggy kernel was asserting an error within this timeframe almost always.

The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>


# 1.25 07-Mar-2018 kamil

ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.

The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>


# 1.24 07-Mar-2018 kamil

ATF: Correct a race bug in attach2 (t_ptrace_wait*)

At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is being
investigated.

Sponsored by <The NetBSD Foundation>


Revision tags: pgoyette-compat-base
# 1.23 05-Mar-2018 kamil

branches: 1.23.2;
Remove PT_GET_SIGMASK / PT_SET_SIGMASK

These operations cloned Linux's specific PTRACE_GETSIGMASK / PTRACE_SETSIGMASK.
This feature was useful in applications like rr/criu/reptyr-like, where
the ptrace(2) interface is abused for the purpose of constructing an arbitrary
process. It's not reliable and not portable. For the NetBSD case it will be
better to invent something dedicated for serializing and deserializing a
process with threads.

Noted on tech-toolchain@ and blog entry

"LLDB restoration and return to ptrace(2)"
https://blog.netbsd.org/tnf/entry/lldb_restoration_and_return_to


# 1.22 28-Dec-2017 christos

mips panic should be fixed on head.


# 1.21 28-Dec-2017 kamil

atf: ptrace: Temporarily skip fpregs* tests on pmax

NetBSD/pmax 8.99.9 panics when attempting to use fpregs through ptrace(2).

Sponsored by <The NetBSD Foundation>


# 1.20 27-Dec-2017 kamil

atf: ptrace: Temporarily disable signal3 as it breaks now on some ports

This test is marked as failing with: PR kern/51918.


# 1.19 25-Dec-2017 kamil

atf: t_ptrace_wait: Mark attach2 as racy


# 1.18 23-Dec-2017 christos

report which errno failed


# 1.17 22-Dec-2017 kamil

ptrace atf: Clanup reports of failures

Mark resume* suspend* tests as expected failure and link with PR 51995.

Sponsored by <The NetBSD Foundation>


# 1.16 21-Dec-2017 kamil

t_ptrace_wait*: Disable suspend* tests

These tests can hang the system. These interfaces will be improved and
temporarily disable them.


# 1.15 18-Dec-2017 christos

make it fail instead of hang under qemu; XXX: need to investigate.


# 1.14 16-Dec-2017 christos

Add expected failures.


# 1.13 14-Dec-2017 christos

sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.


# 1.12 10-Dec-2017 christos

Remove expected failure (fixed in kern_sig.c 1.339)


# 1.11 04-Dec-2017 kamil

Temporarily disable t_ptrace_wait*::resume1 in ATF tests

It hangs forever on releng machines.

Sponsored by <The NetBSD Foundation>


# 1.10 18-Nov-2017 martin

PR kern/52167 strikes on sparc64 too.


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.9 03-May-2017 kamil

branches: 1.9.2;
Improve style of PT_SETSTEP and PT_CLEARSTEP tests in t_ptrace_wait*

No functional change.

Sponsored by <The NetBSD Foundation>


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.8 16-Apr-2017 kamil

branches: 1.8.2; 1.8.4; 1.8.6;
ATF test attach2/t_ptrace_wait* is unstable

Mark it broken with:

PR kern/52168 attach2:t_ptrace_wait* is unsable

In order to get reliable failure, abort this test at the end (if we get
there).


# 1.7 16-Apr-2017 kamil

Mark signal3/t_ptrace_wait* with timeout on sparc 32-bit

PR kern/52167 signal3/t_ptrace_wait* timeouts on sparc 32-bit

This test is also marked as failure on other platforms:

PR kern/51918 ptrace tracee can prevent tracer to get its signals by masking

Both issues are valid on sparc 32-bit, but the timeout one wins.


# 1.6 16-Apr-2017 kamil

Mark syscallemu1/t_ptrace_wait* broken on 32-bit sparc

PR kern/52166


# 1.5 16-Apr-2017 kamil

Restore atf_tc_expect_fail in signal4 of t_ptrace_wait*

Accidentally there was removed a PR, it was never fixed.

PR 51918 "ptrace tracee can prevent tracer to get its signals by masking"


# 1.4 12-Apr-2017 kamil

Add new macro PTRACE_BREAKPOINT_ASM in <sys/ptrace.h> MD part

This macro ships with a MD-specific assembly instruction triggering
a software breakpoint.

Missing instruction for powerpc targets.

This code is used in ATF tests (lib/libc/sys/t_ptrace_wait).

Original patch by Nick Hudson, thanks!


# 1.3 10-Apr-2017 kamil

fork1 and siginfo5 no longer fails on !x86 platforms in t_ptrace_wait*

The PTRACE_FORK operation has been fixed. Patch committed by <martin>

PR kern/52117


# 1.2 08-Apr-2017 kamil

Add new ptrace(2) API: PT_SETSTEP & PT_CLEARSTEP

These operations allow to mark thread as a single-stepping one.

This allows to i.a.:
- single step and emit a signal (PT_SETSTEP & PT_CONTINUE)
- single step and trace syscall entry and exit (PT_SETSTEP & PT_SYSCALL)

The former is useful for debuggers like GDB or LLDB. The latter can be used
to singlestep a usermode kernel. These examples don't limit use-cases of
this interface.

Define PT_*STEP only for platforms defining PT_STEP.

Add new ATF tests setstep[1234].

These ptrace(2) operations first appeared in FreeBSD.

Sponsored by <The NetBSD Foundation>


# 1.1 02-Apr-2017 kamil

Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>