Commit Graph

262 Commits

Author SHA1 Message Date
kamil 6abbe0506f Add a comment for the workaround in trigger_bus()
Explain PROT_READ|PROT_WRITE.
2018-05-30 17:48:13 +00:00
kamil 398835f368 Make the trigger_bus() test compatible with more CPUs (at least ALPHA)
If we write a byte character into a pointer, a compiler can emit a
read-modify-write operation, especially when a CPU cannot access directly
a character wide address.

In this scenario calling mmap(2) with PROT_WRITE, without PROT_READ will
emit unexpected trap.

There are two possible workarounds for this issue:
 - write register wide memory without rmw sequence,
 - mark the region with additional protection PROT_READ

Both work for NetBSD/alpha.

Go for the latter as perhaps more safe for dump compilers emitting rmw
sequences.

Investigated by <martin>
2018-05-30 17:31:34 +00:00
kamil 49994bfcd7 Handle FPE and BUS scenarios in the ATF t_trapsignal tests
These crash signals are crucial for proper handling of abnormal conditions
in a program. The additional purpose of these tests it to assure the proper
handling of these signals for the coming ptrace(2)-related changes in the
signal routing code.

Add a stub for ILL scenarios.

All tests pass (on amd64).

The shell ATF script contains duplicated code. There should be a way to
deduplicate it, without rewrite to C.

Sponsored by <The NetBSD Foundation>
2018-05-27 17:04:45 +00:00
kamil aaef92583a Extend ATF tests in t_trapsignal.sh to verify software breakpoint traps
There are at least four types of SIGTRAP events:
 - software/hardware single step (trace trap)
 - software breakpoint
 - hardware breakpoint/watchpoint
 - kernel event (exec, fork, vfork, vfork-done, lwp-create, lwp-exit)

A program can execute software breakpoint without the context of being
traced and this is a regular crash signal emitting SIGTRAP (TRAP_BRKPT).

Rename original trap_* tests (trap_simple, trap_handle, trap_mask,
trap_handle_recurse and trap_ignore) to segv_* tests and restrict them for
SIGSEGV.

Add new tests: trap_* testing the same scenarios as segv_ ones, however
verifying the software breakpoint trap (SIGTRAP).

Keep the original name of h_segv.c, and extend it for software breakpoint
events.

The purpose of these tests is to verify SIGTRAP kernel paths without the
ptrace(2) context.

All tests pass.

Sponsored by <The NetBSD Foundation>
2018-05-22 04:32:56 +00:00
kamil 5607b39231 Add new ATF test: t_trapsignal:trap_ignore
Test ignored trap with right exit code.

This test passes.

Sponsored by <The NetBSD Foundation>
2018-05-21 08:49:03 +00:00
kamil ed68aafd9d Correct assert in ATF t_zombie test
A failure is reported with -1, not 1.

Sponsored by <The NetBSD Foundation>
2018-05-18 00:25:30 +00:00
kamil ce34db38fd Add new ATF tests: kernel/t_zombie
New tests attempting to kill, stop, drop or revive a zombie:
 - signal1 (SIGKILL)
 - signal2 (SIGSTOP)
 - signal3 (SIGABRT)
 - signal4 (SIGHUP)
 - signal5 (SIGCONT)

New test race1 verifying whether there are any kernel races when processing
signals to zombies, executing in a loop for 5 seconds.

These tests were inspired by a kernel unexpected behavior when a lookup
of a dying process could result in two detected entities once as an alive
process and once as a zombie.

race1 is similar to t_ptrace_wait* race1, however without ptrace(2) involved.

Sponsored by <The NetBSD Foundation>
2018-03-14 02:13:47 +00:00
pgoyette 96bdb2f1f0 * Use 'struct testmsg' rather than 'struct mymsg' (avoids a conflict
with FreeBSD)
* Fix a broken call to open(2) with O_CREAT and no permission argument.
* ANSIfy function definitions.
* Improve failure messages.

From freebsd.org via Brooks Davis - Thanks!
2018-02-03 02:57:15 +00:00
martin cea0645f8c Add EVFILT_FS 2018-01-09 17:35:29 +00:00
martin 35cce3cf1f Double the nanosleep() time to make the test work more reliably on my
dual CPU alpha (where previously we sometimes ended up with no delay
at all).
2017-12-30 17:06:27 +00:00
nakayama 036e3ece76 Use SCRIPTS instead of PROGS to avoid strip(1) if STRIPFLAG=-s. 2017-12-14 14:38:17 +00:00
christos 3fd3ffc3a1 PR/52812: scole_mail: src/tests/kernel/t_timeleft.c doesn't compile with MKRUMP=no
It needs libpthread regardless MKRUMP..
2017-12-12 18:19:45 +00:00
christos f765c47147 Add tests to make sure that the program name is what it is supposed to be. 2017-12-10 15:37:54 +00:00
christos 0b33a75d8f fix usage. 2017-12-08 14:40:45 +00:00
christos 85bf85b701 make _lwp_park return the remaining time to sleep in the "ts" argument
if it is a relative timestamp, as discussed in tech-kern.
XXX: pullup-8
2017-12-08 01:19:29 +00:00
christos 962d0d23f1 Add trapsignal tests that make sure that traps don't end up spinning
indefinitely, discussed in tech-kern.
2017-12-07 19:46:40 +00:00
christos f2c3026d0a add a test to check that the interpreter is preserved when executing scripts. 2017-12-06 13:54:26 +00:00
riastradh 894367af71 Stress rump hyperentropy a little harder. 2017-04-16 18:24:23 +00:00
kamil 97a670fdb7 Remove tests/kernel/t_ptrace* from the tree
ptrace(2) tests have been moved to tests/lib/libc/sys

Sponsored by <The NetBSD Foundation>
2017-04-03 05:06:28 +00:00
kamil cc4260326d Remove kernel/arch/{amd64,i386,x86} tests
These files were merged with kernel/t_ptrace_wait*

This removes MD test files.

Sponsored by <The NetBSD Foundation>
2017-04-02 01:49:51 +00:00
kamil 8021fa5d7a Merge kernel/t_ptrace_wait with kernel/arch/amd64/t_ptrace_wait
This aims to remove MD-specific tests files for ptrace(2).

Prefix i386 and amd64 tests with unique strings "i386_" and "x86_64_".
This removes conflicts with generic tests.

Sponsored by <The NetBSD Foundation>
2017-04-02 01:14:35 +00:00
kamil 558f1d1e36 Merge kernel/t_ptrace_wait with kernel/arch/i386/t_ptrace_wait
This aims to remove MD-specific tests files for ptrace(2).

Sponsored by <The NetBSD Foundation>
2017-04-02 00:40:12 +00:00
kamil c2be869a55 Merge kernel/t_ptrace_wait with kernel/arch/x86/t_ptrace_wait
This aims to remove MD-specific tests files for ptrace(2).

Sponsored by <The NetBSD Foundation>
2017-04-02 00:29:07 +00:00
kamil e884bc2dfc Correct another string about securelevel in t_ptrace
Change:
    Test must be run with securelevel >= 1

To:
    Test must be run with securelevel >= 0

In attach_pid1_securelevel.

Sponsored by <The NetBSD Foundation>
2017-04-02 00:06:09 +00:00
kamil bce52e0028 Deduplicate code in step* tests in t_ptrace_wait*
No functional change.

Sponsored by <The NetBSD Foundation>
2017-04-02 00:03:40 +00:00
kamil 5ab466b502 Correct securelevel in attach_pid1_securelevel
Assert that a debugger cannot attach to PID 1 with securelevel >= 0
(as root) instead of >= 1.

Sponsored by <The NetBSD Foundation>
2017-04-01 23:51:27 +00:00
kamil c0d49dc8aa Try to fix Clang/LLVM build
Initialize a local variable.
2017-04-01 23:28:02 +00:00
kamil d412f5ec32 Refactor dbregs_dr*_dont_inherit_execve ATF tests for x86/
Eliminate duplicated code.

Sponsored by <The NetBSD Foundation>
2017-04-01 23:25:08 +00:00
kamil 0a45c98ca6 Remove deuplicated code in dbregs_dr[01234]_dont_inherit_lwp
Currently remove tests for dbregs_dr[67]_dont_inherit_lwp.

Sponsored by <The NetBSD Foundation>
2017-03-30 20:24:35 +00:00
kamil 04aac12dac Eliminate code duplication in the x86 dbregs_dr[0123]_trap_variable* tests
This is work in progress to remove no longer needed code overhead shared
between tests.

Sponsored by <The NetBSD Foundation>
2017-03-30 02:17:38 +00:00
kamil f0df2ef69f Deduplicate shared code in dbregs_preserve_dr[0123]{,_yield,_continued}
Move common function code into shared subroutine.

While there remove checks for defined(HAVE_DBREGS). All x86 ports offer
debug register accessors.

Sponsored by <The NetBSD Foundation>
2017-03-29 23:50:09 +00:00
kamil a730799971 Explain expected behavior for PTRACE_FORK events in t_ptrace_wait*
PR kern/52117 ptrace(2) PTRACE_FORK fails on some platforms

Add message similar to:
    We expect two SIGTRAP events, for child 22199 (TRAP_CHLD,
    pe_report_event=PTRACE_FORK, state.pe_other_pid=child2) and for child2
    (TRAP_CHLD, pe_report_event=PTRACE_FORK, state.pe_other_pid=child)

This should make the expected behavior more clear.

Sponsored by <The NetBSD Foundation>
2017-03-28 13:16:30 +00:00
kamil 203a7bc419 Mark PT_STEP tests in t_ptrace_wait* as broken on ARM
There is a definition of PT_STEP for userland, but no implementation
in the kernel.

PR kern/52119 PT_STEP not supported on arm 32-bit

Sponsored by <The NetBSD Foundation>
2017-03-28 12:39:07 +00:00
kamil 5f3e805bbe Set timeout expected in resume1 (t_ptrace_wait*)
Mark timeout for this test 5 sec. It sometimes works sometimes does not.

Add a local sleep(3) at the end to get consisten report about timeouting
always.

PR kern/51995

Sponsored by <The NetBSD Foundation>
2017-03-28 03:19:20 +00:00
kamil b97ce90e99 Mark fork1 and siginfo5 as broken on sparc, sparc64, evbarm and alpha
PR kern/52117 ptrace(2) PTRACE_FORK fails on some platforms

These tests work on amd64, i386 and xen.

They are part of t_ptrace_wait*.

Sponsored by <The NetBSD Foundation>
2017-03-28 03:03:15 +00:00
kamil 501e6bc911 Optimize signal6 in t_ptrace_wait
Reduce timeout to 5 seconds. This tests timeouts and this change saves
time.

PR kern/51918

Sponsored by <The NetBSD Foundation>
2017-03-28 01:40:39 +00:00
kamil c6dfd176d2 Mark signal6 as failing due to timeout not regular failure
This test is marked as PR kern/51918.

Timeout has been reported on i386, amd64, alpha, sparc, sparc64, evbarm.
xen.

Sponsored by <The NetBSD Foundation>
2017-03-28 01:00:33 +00:00
skrll 8ff4d6477a kern/52012 kern/52018 kern/52019 were all fixed by christos 2017-03-25 10:07:55 +00:00
kre 1cd3fe6ea7 Since it is unlikely that any of this really wants to test whether
[v]fork() produces pid==1 (init) (if it were useful to test that, an
entirely different test would be appropriate) change the tests so
they check for [v]fork() failure, as probably intended, instead.
2017-03-03 12:23:26 +00:00
kamil 81ccb321cb Mark syscall1 broken in t_ptrace_wait*
Mark this test broken with kern/52012 as the tracee does not stop on syscall
entry. Check for siginfo(2) in syscall1 and unveil two new bugs.

PR kern/52012: PT_SYSCALL does not stop on syscall entry
PR kern/52018: ptrace(2) PT_SYSCALL generates SIGTRAP without si_code
PR kern/52019: ptrace(2) PT_SYSCALL generate SIGTRAP to the parent but
               returns SIGSTOP in PT_GET_SIGINFO

Sponsored by <The NetBSD Foundation>
2017-03-01 08:05:15 +00:00
kamil ad0426b8f6 Mark resume1 and syscallemu1 tests broken in t_ptrace_wait*
resume1:
    PR kern/51995 ptrace(2) PT_RESUME is not reliable

syscallemu1:
    PR kern/52012 PT_SYSCALL does not stop on syscall entry

Sponsored by <The NetBSD Foundation>
2017-02-28 13:29:52 +00:00
kamil d2c80310bc Add new test syscallemu1 in t_ptrace_wait*
syscallemu1:
    Verify that exit(2) can be intercepted with PT_SYSCALLEMU

This test is failing as PT_SYSCALL does not stop the process on syscall
entry. This renders PT_SYSCALL broken on NetBSD.

Sponsored by <The NetBSD Foundation>
2017-02-28 13:19:50 +00:00
christos e89750009c kill stray q 2017-02-25 18:18:29 +00:00
christos 5661ffc1f0 make bitfields unsigned 2017-02-25 16:45:24 +00:00
kamil 5447864424 Add new test syscall1 in t_ptrace_wait*
syscall1:
    Verify that getpid(2) can be traced with PT_SYSCALL

Enforce usage of syscall(2), it should prevent failing on any possible
optimizations in future as a libc can ship this information not through
syscall (shared struct with kernel or similar).

Sponsored by <The NetBSD Foundation>
2017-02-24 06:17:48 +00:00
kamil fb0af2ac33 Improve PT_SET_SIGMASK and PT_GET_SIGMASK API in ptrace(2)
Use proper check for LW_SYSTEM, don't depend on PT_GETREGS/PT_SETREGS.
Don't allow to mask SA_CANTMASK signals with PT_SET_SIGMASK (this covers
SIGSTOP and SIGKILL).

Add new ATF tests:
 - setsigmask5
   Verify that sigmask cannot be set to SIGKILL

 - setsigmask6
   Verify that sigmask cannot be set to SIGSTOP

Sponsored by <The NetBSD Foundation>
2017-02-23 00:50:09 +00:00
kamil f9b2093d06 Introduce new ptrace(2) API to allow/prevent exection of LWP
Introduce new API for debuggers to allow/prevent execution of the specified
thread.

New ptrace(2) operations:

     PT_RESUME     Allow execution of a specified thread, change its state
                   from suspended to continued.  The addr argument is unused.
                   The data argument specifies the LWP ID.

                   This call is equivalent to _lwp_continue(2) called by a
                   traced process.  This call does not change the general
                   process state from stopped to continued.

     PT_SUSPEND    Prevent execution of a specified thread, change its state
                   from continued to suspended.  The addr argument is unused.
                   The data argument specifies the requested LWP ID.

                   This call is equivalent to _lwp_suspend(2) called by a
                   traced process.  This call does not change the general
                   process state from continued to stopped.

This interface is modeled after FreeBSD, however with NetBSD specific arguments
passed to ptrace(2) -- FreeBSD passes only thread id, NetBSD passes process and
thread id.

Extend PT_LWPINFO operation in ptrace(2) to report suspended threads. In the
ptrace_lwpinfo structure in pl_event next to PL_EVENT_NONE and PL_EVENT_SIGNAL
add new value PL_EVENT_SUSPENDED.

Add new errno(2) value EDEADLK that might be returned by ptrace(2). It prevents
dead-locking in a scenario of resuming a process or thread that is prevented
from execution. This fixes bug that old API was vulnerable to this scenario.

Kernel bump delayed till introduction of PT_GETDBREGS/PT_SETDBREGS soon.

Add new ATF tests:
 - resume1
   Verify that a thread can be suspended by a debugger and later
   resumed by the debugger

 - suspend1
   Verify that a thread can be suspended by a debugger and later
   resumed by a tracee

 - suspend2
   Verify that the while the only thread within a process is
   suspended, the whole process cannot be unstopped

Sponsored by <The NetBSD Foundation>
2017-02-22 23:43:43 +00:00
kamil b4bf2c1aa5 Add kernel/arch/x86 ATF tests for CPU Debug Registers for amd64 and i386
This moves kernel/arch/amd64 tests, the ones to be shared between amd64 and
i386, into kernel/arch/x86. This covers all Debug Register tests.

kernel/arch/amd64 is reduced to regs1
kernel/arch/i386 is reduced to regs1

kernel/arch/x86 tests:
 - dbregs_print
 - dbregs_preserve_dr0
 - dbregs_preserve_dr1
 - dbregs_preserve_dr2
 - dbregs_preserve_dr3
 - dbregs_preserve_dr0_yield
 - dbregs_preserve_dr1_yield
 - dbregs_preserve_dr2_yield
 - dbregs_preserve_dr3_yield
 - dbregs_preserve_dr0_continued
 - dbregs_preserve_dr1_continued
 - dbregs_preserve_dr2_continued
 - dbregs_preserve_dr3_continued
 - dbregs_dr0_trap_variable_writeonly_byte
 - dbregs_dr1_trap_variable_writeonly_byte
 - dbregs_dr2_trap_variable_writeonly_byte
 - dbregs_dr3_trap_variable_writeonly_byte
 - dbregs_dr0_trap_variable_writeonly_2bytes
 - dbregs_dr1_trap_variable_writeonly_2bytes
 - dbregs_dr2_trap_variable_writeonly_2bytes
 - dbregs_dr3_trap_variable_writeonly_2bytes
 - dbregs_dr0_trap_variable_writeonly_4bytes
 - dbregs_dr1_trap_variable_writeonly_4bytes
 - dbregs_dr2_trap_variable_writeonly_4bytes
 - dbregs_dr3_trap_variable_writeonly_4bytes
 - dbregs_dr0_trap_variable_readwrite_write_byte
 - dbregs_dr1_trap_variable_readwrite_write_byte
 - dbregs_dr2_trap_variable_readwrite_write_byte
 - dbregs_dr3_trap_variable_readwrite_write_byte
 - dbregs_dr0_trap_variable_readwrite_write_2bytes
 - dbregs_dr1_trap_variable_readwrite_write_2bytes
 - dbregs_dr2_trap_variable_readwrite_write_2bytes
 - dbregs_dr3_trap_variable_readwrite_write_2bytes
 - dbregs_dr0_trap_variable_readwrite_write_4bytes
 - dbregs_dr1_trap_variable_readwrite_write_4bytes
 - dbregs_dr2_trap_variable_readwrite_write_4bytes
 - dbregs_dr3_trap_variable_readwrite_write_4bytes
 - dbregs_dr0_trap_variable_readwrite_read_byte
 - dbregs_dr1_trap_variable_readwrite_read_byte
 - dbregs_dr2_trap_variable_readwrite_read_byte
 - dbregs_dr3_trap_variable_readwrite_read_byte
 - dbregs_dr0_trap_variable_readwrite_read_2bytes
 - dbregs_dr1_trap_variable_readwrite_read_2bytes
 - dbregs_dr2_trap_variable_readwrite_read_2bytes
 - dbregs_dr3_trap_variable_readwrite_read_2bytes
 - dbregs_dr0_trap_variable_readwrite_read_4bytes
 - dbregs_dr1_trap_variable_readwrite_read_4bytes
 - dbregs_dr2_trap_variable_readwrite_read_4bytes
 - dbregs_dr3_trap_variable_readwrite_read_4bytes
 - dbregs_dr0_trap_code
 - dbregs_dr1_trap_code
 - dbregs_dr2_trap_code
 - dbregs_dr3_trap_code
 - dbregs_dr0_dont_inherit_lwp
 - dbregs_dr1_dont_inherit_lwp
 - dbregs_dr2_dont_inherit_lwp
 - dbregs_dr3_dont_inherit_lwp
 - dbregs_dr6_dont_inherit_lwp
 - dbregs_dr7_dont_inherit_lwp
 - dbregs_dr0_dont_inherit_execve
 - dbregs_dr1_dont_inherit_execve
 - dbregs_dr2_dont_inherit_execve
 - dbregs_dr3_dont_inherit_execve
 - dbregs_dr6_dont_inherit_execve
 - dbregs_dr7_dont_inherit_execve

Sponsored by <The NetBSD Foundation>
2017-02-22 01:07:13 +00:00
kamil 10e522e132 Add new tests dbregs_dr*_dont_inherit_execve in arch/amd64
Added tests:
 - dbregs_dr0_dont_inherit_execve
 - dbregs_dr1_dont_inherit_execve
 - dbregs_dr2_dont_inherit_execve
 - dbregs_dr3_dont_inherit_execve
 - dbregs_dr6_dont_inherit_execve
 - dbregs_dr7_dont_inherit_execve

Debug Registers must no be inherited after exec() call.

Sponsored by <The NetBSD Foundation>
2017-02-21 08:40:16 +00:00
kamil 2473483dae Protect dbregs_dr*_dont_inherit_lwp in arch/amd64 with HAVE_DBREGS
The code for debug registers isn't in HEAD and it might break the build.

Sponsored by <The NetBSD Foundation>
2017-02-20 06:48:49 +00:00