2020-12-14 19:55:51 +03:00
|
|
|
# $NetBSD: Makefile,v 1.68.2.2 2020/12/14 16:55:51 thorpej Exp $
|
2011-01-10 07:57:56 +03:00
|
|
|
|
|
|
|
MKMAN= no
|
|
|
|
|
|
|
|
.include <bsd.own.mk>
|
|
|
|
|
Add a simple test case to check executable mapping rights for mprotect(2).
- provide an exec_prot_support() routine so $ARCH can indicate whether
it supports execution protection or not, and skip test accordingly.
- have a trivial 'return_one' shellcode to copy anywhere in a page, and
call it. The decision to keep the assembly solution is mine, reasons are
twofold:
- all pure-C implementations cannot be controlled easily:
bounds detection (beginning/end) of return_one is unpredictable,
or requires the use of overkill solutions like libelf. Using
dlsym(3) was a good proposal, however I can't use it to know the
end address of the payload. It makes copying of the shellcode a bit
more difficult: using a constant may be too small (code has not been
entirely copied, and can lead to errors that can be erroneously
detected as "test passed"), or too big (depending on where it is mapped
in memory, copying past the end of the function may trigger SIGSEGV).
- I have to ensure that the resulting assembly is the most compact
possible, especially as it will be reused to test other parts of
memory (stack, data, rodata, etc.).
Only i386 and amd64 are implemented so far. Others will come in due time.
FWIW, writing the exec_prot_support() callback and the return_one payload
should be enough. Writing callback requires good knowledge of the platform,
depending on chip revision, CPU, board, MMU... the protection level may vary.
Current files are put under lib/libc/arch/* and lib/libc/common/. Feel free to
move them around the tests/ tree. Keep in mind that the common/ and arch/ code
will be used outside of libc, so please do not hide them too deep in the tree.
I checked a few architectures via build.sh cross-compile, and will keep an
eye on buildbot for potential build breakage. Feel free to contact me in
case you see any, of course.
2011-07-19 03:16:08 +04:00
|
|
|
.include "../arch/Makefile.exec_prot"
|
|
|
|
|
2011-01-10 07:57:56 +03:00
|
|
|
TESTSDIR= ${TESTSBASE}/lib/libc/sys
|
|
|
|
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_access
|
2015-04-05 09:36:52 +03:00
|
|
|
TESTS_C+= t_bind
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_chroot
|
2011-10-15 10:42:16 +04:00
|
|
|
TESTS_C+= t_clock_gettime
|
2016-11-11 18:30:44 +03:00
|
|
|
TESTS_C+= t_clock_nanosleep
|
2011-01-13 05:40:43 +03:00
|
|
|
TESTS_C+= t_clone
|
2011-11-05 22:19:01 +04:00
|
|
|
TESTS_C+= t_connect
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_dup
|
2020-12-14 19:01:38 +03:00
|
|
|
TESTS_C+= t_eventfd
|
2018-05-18 09:39:58 +03:00
|
|
|
TESTS_C+= t_fork
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_fsync
|
2020-04-26 21:53:31 +03:00
|
|
|
TESTS_C+= t_futex_ops
|
|
|
|
TESTS_C+= t_futex_robust
|
2011-07-07 11:06:21 +04:00
|
|
|
TESTS_C+= t_getcontext
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_getgroups
|
|
|
|
TESTS_C+= t_getitimer
|
|
|
|
TESTS_C+= t_getlogin
|
|
|
|
TESTS_C+= t_getpid
|
New system call getrandom() compatible with Linux and others.
Three ways to call:
getrandom(p, n, 0) Blocks at boot until full entropy.
Returns up to n bytes at p; guarantees
up to 256 bytes even if interrupted
after blocking. getrandom(0,0,0)
serves as an entropy barrier: return
only after system has full entropy.
getrandom(p, n, GRND_INSECURE) Never blocks. Guarantees up to 256
bytes even if interrupted. Equivalent
to /dev/urandom. Safe only after
successful getrandom(...,0),
getrandom(...,GRND_RANDOM), or read
from /dev/random.
getrandom(p, n, GRND_RANDOM) May block at any time. Returns up to n
bytes at p, but no guarantees about how
many -- may return as short as 1 byte.
Equivalent to /dev/random. Legacy.
Provided only for source compatibility
with Linux.
Can also use flags|GRND_NONBLOCK to fail with EWOULDBLOCK/EAGAIN
without producing any output instead of blocking.
- The combination GRND_INSECURE|GRND_NONBLOCK is the same as
GRND_INSECURE, since GRND_INSECURE never blocks anyway.
- The combinations GRND_INSECURE|GRND_RANDOM and
GRND_INSECURE|GRND_RANDOM|GRND_NONBLOCK are nonsensical and fail
with EINVAL.
As proposed on tech-userlevel, tech-crypto, tech-security, and
tech-kern, and subsequently adopted by core (minus the getentropy part
of the proposal, because other operating systems and participants in
the discussion couldn't come to an agreement about getentropy and
blocking semantics):
https://mail-index.netbsd.org/tech-userlevel/2020/05/02/msg012333.html
2020-08-14 03:53:15 +03:00
|
|
|
TESTS_C+= t_getrandom
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_getrusage
|
|
|
|
TESTS_C+= t_getsid
|
2016-07-30 14:03:54 +03:00
|
|
|
TESTS_C+= t_getsockname
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_gettimeofday
|
|
|
|
TESTS_C+= t_issetugid
|
2011-11-17 05:14:12 +04:00
|
|
|
TESTS_C+= t_kevent
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_kill
|
|
|
|
TESTS_C+= t_link
|
2011-11-05 22:19:01 +04:00
|
|
|
TESTS_C+= t_listen
|
2012-03-17 21:23:34 +04:00
|
|
|
TESTS_C+= t_lwp_ctl
|
2012-05-21 18:15:16 +04:00
|
|
|
TESTS_C+= t_lwp_create
|
2014-07-18 16:34:52 +04:00
|
|
|
TESTS_C+= t_minherit
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_mincore
|
2011-10-15 10:26:33 +04:00
|
|
|
TESTS_C+= t_mkdir
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_mkfifo
|
|
|
|
TESTS_C+= t_mknod
|
2012-04-20 16:11:29 +04:00
|
|
|
TESTS_C+= t_mlock
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_mmap
|
|
|
|
TESTS_C+= t_mprotect
|
2011-11-05 11:45:40 +04:00
|
|
|
TESTS_C+= t_msgctl
|
|
|
|
TESTS_C+= t_msgget
|
|
|
|
TESTS_C+= t_msgrcv
|
|
|
|
TESTS_C+= t_msgsnd
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_msync
|
|
|
|
TESTS_C+= t_nanosleep
|
2011-10-15 10:17:02 +04:00
|
|
|
TESTS_C+= t_pipe
|
2011-10-31 19:41:31 +04:00
|
|
|
TESTS_C+= t_pipe2
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_poll
|
2020-07-17 18:34:16 +03:00
|
|
|
TESTS_C+= t_pollts
|
2015-02-01 02:06:57 +03:00
|
|
|
TESTS_C+= t_posix_fallocate
|
2020-07-17 18:34:16 +03:00
|
|
|
TESTS_C+= t_ppoll
|
2017-04-03 00:44:00 +03:00
|
|
|
TESTS_C+= t_ptrace
|
2020-03-06 21:32:35 +03:00
|
|
|
TESTS_C+= t_ptrace_sigchld
|
2017-04-03 00:44:00 +03:00
|
|
|
TESTS_C+= t_ptrace_wait
|
|
|
|
TESTS_C+= t_ptrace_wait3
|
|
|
|
TESTS_C+= t_ptrace_wait4
|
|
|
|
TESTS_C+= t_ptrace_wait6
|
|
|
|
TESTS_C+= t_ptrace_waitid
|
|
|
|
TESTS_C+= t_ptrace_waitpid
|
2012-06-22 22:45:23 +04:00
|
|
|
TESTS_C+= t_recvmmsg
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_revoke
|
|
|
|
TESTS_C+= t_select
|
2018-08-21 13:38:09 +03:00
|
|
|
TESTS_C+= t_sendmmsg
|
|
|
|
TESTS_C+= t_sendrecv
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_setrlimit
|
|
|
|
TESTS_C+= t_setuid
|
2011-10-15 11:00:48 +04:00
|
|
|
TESTS_C+= t_sigaction
|
2020-04-30 14:03:29 +03:00
|
|
|
TESTS_C+= t_sigaltstack
|
2011-01-13 06:09:54 +03:00
|
|
|
TESTS_C+= t_sigqueue
|
2013-03-08 21:01:54 +04:00
|
|
|
TESTS_C+= t_sigtimedwait
|
2011-11-05 22:19:01 +04:00
|
|
|
TESTS_C+= t_socketpair
|
2012-09-12 06:00:51 +04:00
|
|
|
TESTS_C+= t_swapcontext
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_stat
|
2018-05-25 18:42:30 +03:00
|
|
|
TESTS_C+= t_syscall
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_timer_create
|
2020-12-14 19:55:51 +03:00
|
|
|
TESTS_C+= t_timerfd
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_truncate
|
2011-10-15 10:54:52 +04:00
|
|
|
TESTS_C+= t_ucontext
|
2011-07-07 10:57:53 +04:00
|
|
|
TESTS_C+= t_umask
|
|
|
|
TESTS_C+= t_unlink
|
2018-05-18 09:39:58 +03:00
|
|
|
TESTS_C+= t_vfork
|
2016-04-06 03:45:53 +03:00
|
|
|
TESTS_C+= t_wait
|
2016-11-06 18:03:30 +03:00
|
|
|
TESTS_C+= t_wait_noproc
|
|
|
|
TESTS_C+= t_wait_noproc_wnohang
|
2011-10-15 10:50:52 +04:00
|
|
|
TESTS_C+= t_write
|
2011-07-07 10:57:53 +04:00
|
|
|
|
2020-04-18 20:44:53 +03:00
|
|
|
SRCS.t_mprotect= t_mprotect.c ${SRCS_EXEC_PROT} t_mprotect_helper.c
|
Add a simple test case to check executable mapping rights for mprotect(2).
- provide an exec_prot_support() routine so $ARCH can indicate whether
it supports execution protection or not, and skip test accordingly.
- have a trivial 'return_one' shellcode to copy anywhere in a page, and
call it. The decision to keep the assembly solution is mine, reasons are
twofold:
- all pure-C implementations cannot be controlled easily:
bounds detection (beginning/end) of return_one is unpredictable,
or requires the use of overkill solutions like libelf. Using
dlsym(3) was a good proposal, however I can't use it to know the
end address of the payload. It makes copying of the shellcode a bit
more difficult: using a constant may be too small (code has not been
entirely copied, and can lead to errors that can be erroneously
detected as "test passed"), or too big (depending on where it is mapped
in memory, copying past the end of the function may trigger SIGSEGV).
- I have to ensure that the resulting assembly is the most compact
possible, especially as it will be reused to test other parts of
memory (stack, data, rodata, etc.).
Only i386 and amd64 are implemented so far. Others will come in due time.
FWIW, writing the exec_prot_support() callback and the return_one payload
should be enough. Writing callback requires good knowledge of the platform,
depending on chip revision, CPU, board, MMU... the protection level may vary.
Current files are put under lib/libc/arch/* and lib/libc/common/. Feel free to
move them around the tests/ tree. Keep in mind that the common/ and arch/ code
will be used outside of libc, so please do not hide them too deep in the tree.
I checked a few architectures via build.sh cross-compile, and will keep an
eye on buildbot for potential build breakage. Feel free to contact me in
case you see any, of course.
2011-07-19 03:16:08 +04:00
|
|
|
|
2020-12-14 19:01:38 +03:00
|
|
|
LDADD.t_eventfd+= -lpthread
|
2011-07-07 10:57:53 +04:00
|
|
|
LDADD.t_getpid+= -lpthread
|
2020-12-14 19:55:51 +03:00
|
|
|
LDADD.t_timerfd+= -lpthread
|
2012-08-08 17:57:05 +04:00
|
|
|
|
2020-03-06 21:32:35 +03:00
|
|
|
LDADD.t_ptrace_sigchld+= -pthread -lm
|
|
|
|
|
2019-07-01 00:20:04 +03:00
|
|
|
LDADD.t_ptrace_wait+= -pthread -lm -lelf
|
|
|
|
LDADD.t_ptrace_wait3+= -pthread -lm -lelf
|
|
|
|
LDADD.t_ptrace_wait4+= -pthread -lm -lelf
|
|
|
|
LDADD.t_ptrace_wait6+= -pthread -lm -lelf
|
|
|
|
LDADD.t_ptrace_waitid+= -pthread -lm -lelf
|
|
|
|
LDADD.t_ptrace_waitpid+= -pthread -lm -lelf
|
2019-02-10 05:13:45 +03:00
|
|
|
|
2015-06-22 03:05:23 +03:00
|
|
|
.if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
|
2016-01-24 00:22:45 +03:00
|
|
|
CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES
|
2012-08-08 17:57:05 +04:00
|
|
|
TESTS_C+= t_posix_fadvise
|
2020-03-01 23:24:07 +03:00
|
|
|
LDADD.t_posix_fadvise+= ${LIBRUMPBASE}
|
2012-08-08 17:57:05 +04:00
|
|
|
.endif
|
2011-07-07 10:57:53 +04:00
|
|
|
|
2020-04-26 21:53:31 +03:00
|
|
|
CPPFLAGS.t_futex_ops.c += -I${.CURDIR}/../../../../lib
|
|
|
|
CPPFLAGS.t_futex_robust.c += -I${.CURDIR}/../../../../lib
|
|
|
|
|
2017-04-03 00:44:00 +03:00
|
|
|
CPPFLAGS.t_lwp_create.c += -D_KERNTYPES
|
2020-06-18 01:07:21 +03:00
|
|
|
CPPFLAGS.t_ptrace_sigchld.c += -D__TEST_FENV
|
2019-04-25 22:15:23 +03:00
|
|
|
CPPFLAGS.t_ptrace_wait.c += -D_KERNTYPES -D__TEST_FENV
|
|
|
|
CPPFLAGS.t_ptrace_wait3.c += -D_KERNTYPES -D__TEST_FENV
|
|
|
|
CPPFLAGS.t_ptrace_wait4.c += -D_KERNTYPES -D__TEST_FENV
|
|
|
|
CPPFLAGS.t_ptrace_wait6.c += -D_KERNTYPES -D__TEST_FENV
|
|
|
|
CPPFLAGS.t_ptrace_waitid.c += -D_KERNTYPES -D__TEST_FENV
|
|
|
|
CPPFLAGS.t_ptrace_waitpid.c += -D_KERNTYPES -D__TEST_FENV
|
2018-02-25 17:27:07 +03:00
|
|
|
CPPFLAGS.t_ucontext.c += -D_KERNTYPES
|
2016-01-24 18:11:08 +03:00
|
|
|
|
2020-02-22 22:44:07 +03:00
|
|
|
.if ${MKSANITIZER:Uno} != "yes" && ${MKLIBCSANITIZER:Uno} != "yes"
|
|
|
|
CPPFLAGS.t_ptrace_wait.c += -DENABLE_TESTS
|
|
|
|
CPPFLAGS.t_ptrace_wait3.c += -DENABLE_TESTS
|
|
|
|
CPPFLAGS.t_ptrace_wait4.c += -DENABLE_TESTS
|
|
|
|
CPPFLAGS.t_ptrace_wait6.c += -DENABLE_TESTS
|
|
|
|
CPPFLAGS.t_ptrace_waitid.c += -DENABLE_TESTS
|
|
|
|
CPPFLAGS.t_ptrace_waitpid.c += -DENABLE_TESTS
|
|
|
|
.endif
|
|
|
|
|
2017-01-13 23:03:51 +03:00
|
|
|
FILES= truncate_test.root_owned
|
2017-01-14 06:59:58 +03:00
|
|
|
FILESBUILD= yes
|
2017-02-01 13:18:27 +03:00
|
|
|
FILESDIR_truncate_test.root_owned= ${TESTSDIR}
|
|
|
|
FILESMODE_truncate_test.root_owned= 0600
|
|
|
|
FILESOWNER_truncate_test.root_owned= root
|
|
|
|
FILESGRP_truncate_test.root_owned= wheel
|
2017-01-13 23:03:51 +03:00
|
|
|
|
|
|
|
CLEANFILES= truncate_test.root_owned
|
|
|
|
truncate_test.root_owned:
|
|
|
|
dd if=/dev/null bs=1 count=1 of=${.TARGET}
|
|
|
|
|
2011-07-07 10:57:53 +04:00
|
|
|
WARNS= 4
|
2011-01-10 07:57:56 +03:00
|
|
|
|
2020-09-06 10:20:26 +03:00
|
|
|
CWARNFLAGS.gcc+= ${GCC_NO_ADDR_OF_PACKED_MEMBER} \
|
|
|
|
${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-error=deprecated :}
|
|
|
|
|
2011-01-10 07:57:56 +03:00
|
|
|
.include <bsd.test.mk>
|