diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-09 12:19:31 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-09 12:19:31 -0500 |
| commit | a448c643bc49f14bb3aae68ee7085b4c7f6207d8 (patch) | |
| tree | 83aefc01fbb95e5f6edfb9c3f7444cd37c13bb72 | |
| parent | 2bb995405fe52dd893db57456556e8dc4fce35a7 (diff) | |
| parent | 0e27ded1159f62ab1a4e723796246bd5b1793b93 (diff) | |
Merge tag 'linux-kselftest-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest update fromShuah Khan:
- ir test compile warnings fixes
- seccomp test fixes and improvements from Tycho Andersen and Kees Cook
- ftrace fixes to non-POSIX-compliant constructs in colored output code
and handling absence of tput from Juerg Haefliger
* tag 'linux-kselftest-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests/ftrace: Handle the absence of tput
selftests/ftrace: Replace \e with \033
selftests/ftrace: Replace echo -e with printf
selftests: ir: skip when non-root user runs the test
selftests: ir: skip when lirc device doesn't exist.
selftests: ir: fix warning: "%s" directive output may be truncated ’ directive output may be truncated
selftests/seccomp: Actually sleep for 1/10th second
selftests/harness: Update named initializer syntax
selftests: unshare userns in seccomp pidns testcases
selftests: set NO_NEW_PRIVS bit in seccomp user tests
selftests: skip seccomp get_metadata test if not real root
selftest: include stdio.h in kselftest.h
selftests: fix typo in seccomp_bpf.c
selftests: don't kill child immediately in get_metadata() test
| -rwxr-xr-x | tools/testing/selftests/ftrace/ftracetest | 21 | ||||
| -rw-r--r-- | tools/testing/selftests/ir/ir_loopback.c | 6 | ||||
| -rwxr-xr-x | tools/testing/selftests/ir/ir_loopback.sh | 5 | ||||
| -rw-r--r-- | tools/testing/selftests/kselftest.h | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/kselftest_harness.h | 10 | ||||
| -rw-r--r-- | tools/testing/selftests/seccomp/seccomp_bpf.c | 47 |
6 files changed, 68 insertions, 22 deletions
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index 75244db70331..136387422b00 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest | |||
| @@ -154,17 +154,17 @@ fi | |||
| 154 | 154 | ||
| 155 | # Define text colors | 155 | # Define text colors |
| 156 | # Check available colors on the terminal, if any | 156 | # Check available colors on the terminal, if any |
| 157 | ncolors=`tput colors 2>/dev/null` | 157 | ncolors=`tput colors 2>/dev/null || echo 0` |
| 158 | color_reset= | 158 | color_reset= |
| 159 | color_red= | 159 | color_red= |
| 160 | color_green= | 160 | color_green= |
| 161 | color_blue= | 161 | color_blue= |
| 162 | # If stdout exists and number of colors is eight or more, use them | 162 | # If stdout exists and number of colors is eight or more, use them |
| 163 | if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then | 163 | if [ -t 1 -a "$ncolors" -ge 8 ]; then |
| 164 | color_reset="\e[0m" | 164 | color_reset="\033[0m" |
| 165 | color_red="\e[31m" | 165 | color_red="\033[31m" |
| 166 | color_green="\e[32m" | 166 | color_green="\033[32m" |
| 167 | color_blue="\e[34m" | 167 | color_blue="\033[34m" |
| 168 | fi | 168 | fi |
| 169 | 169 | ||
| 170 | strip_esc() { | 170 | strip_esc() { |
| @@ -173,8 +173,13 @@ strip_esc() { | |||
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | prlog() { # messages | 175 | prlog() { # messages |
| 176 | echo -e "$@" | 176 | newline="\n" |
| 177 | [ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE | 177 | if [ "$1" = "-n" ] ; then |
| 178 | newline= | ||
| 179 | shift | ||
| 180 | fi | ||
| 181 | printf "$*$newline" | ||
| 182 | [ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE | ||
| 178 | } | 183 | } |
| 179 | catlog() { #file | 184 | catlog() { #file |
| 180 | cat $1 | 185 | cat $1 |
diff --git a/tools/testing/selftests/ir/ir_loopback.c b/tools/testing/selftests/ir/ir_loopback.c index 858c19caf224..ff351bb7c163 100644 --- a/tools/testing/selftests/ir/ir_loopback.c +++ b/tools/testing/selftests/ir/ir_loopback.c | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | 27 | ||
| 28 | #define TEST_SCANCODES 10 | 28 | #define TEST_SCANCODES 10 |
| 29 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | 29 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 30 | #define SYSFS_PATH_MAX 256 | ||
| 31 | #define DNAME_PATH_MAX 256 | ||
| 30 | 32 | ||
| 31 | static const struct { | 33 | static const struct { |
| 32 | enum rc_proto proto; | 34 | enum rc_proto proto; |
| @@ -56,7 +58,7 @@ static const struct { | |||
| 56 | int lirc_open(const char *rc) | 58 | int lirc_open(const char *rc) |
| 57 | { | 59 | { |
| 58 | struct dirent *dent; | 60 | struct dirent *dent; |
| 59 | char buf[100]; | 61 | char buf[SYSFS_PATH_MAX + DNAME_PATH_MAX]; |
| 60 | DIR *d; | 62 | DIR *d; |
| 61 | int fd; | 63 | int fd; |
| 62 | 64 | ||
| @@ -74,7 +76,7 @@ int lirc_open(const char *rc) | |||
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | if (!dent) | 78 | if (!dent) |
| 77 | ksft_exit_fail_msg("cannot find lirc device for %s\n", rc); | 79 | ksft_exit_skip("cannot find lirc device for %s\n", rc); |
| 78 | 80 | ||
| 79 | closedir(d); | 81 | closedir(d); |
| 80 | 82 | ||
diff --git a/tools/testing/selftests/ir/ir_loopback.sh b/tools/testing/selftests/ir/ir_loopback.sh index 0a0b8dfa39be..b90dc9939f45 100755 --- a/tools/testing/selftests/ir/ir_loopback.sh +++ b/tools/testing/selftests/ir/ir_loopback.sh | |||
| @@ -4,6 +4,11 @@ | |||
| 4 | # Kselftest framework requirement - SKIP code is 4. | 4 | # Kselftest framework requirement - SKIP code is 4. |
| 5 | ksft_skip=4 | 5 | ksft_skip=4 |
| 6 | 6 | ||
| 7 | if [ $UID != 0 ]; then | ||
| 8 | echo "Please run ir_loopback test as root [SKIP]" | ||
| 9 | exit $ksft_skip | ||
| 10 | fi | ||
| 11 | |||
| 7 | if ! /sbin/modprobe -q -n rc-loopback; then | 12 | if ! /sbin/modprobe -q -n rc-loopback; then |
| 8 | echo "ir_loopback: module rc-loopback is not found [SKIP]" | 13 | echo "ir_loopback: module rc-loopback is not found [SKIP]" |
| 9 | exit $ksft_skip | 14 | exit $ksft_skip |
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index a3edb2c8e43d..47e1d995c182 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
| 14 | #include <unistd.h> | 14 | #include <unistd.h> |
| 15 | #include <stdarg.h> | 15 | #include <stdarg.h> |
| 16 | #include <stdio.h> | ||
| 16 | 17 | ||
| 17 | /* define kselftest exit codes */ | 18 | /* define kselftest exit codes */ |
| 18 | #define KSFT_PASS 0 | 19 | #define KSFT_PASS 0 |
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 76d654ef3234..2d90c98eeb67 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h | |||
| @@ -168,8 +168,8 @@ | |||
| 168 | #define __TEST_IMPL(test_name, _signal) \ | 168 | #define __TEST_IMPL(test_name, _signal) \ |
| 169 | static void test_name(struct __test_metadata *_metadata); \ | 169 | static void test_name(struct __test_metadata *_metadata); \ |
| 170 | static struct __test_metadata _##test_name##_object = \ | 170 | static struct __test_metadata _##test_name##_object = \ |
| 171 | { name: "global." #test_name, \ | 171 | { .name = "global." #test_name, \ |
| 172 | fn: &test_name, termsig: _signal }; \ | 172 | .fn = &test_name, .termsig = _signal }; \ |
| 173 | static void __attribute__((constructor)) _register_##test_name(void) \ | 173 | static void __attribute__((constructor)) _register_##test_name(void) \ |
| 174 | { \ | 174 | { \ |
| 175 | __register_test(&_##test_name##_object); \ | 175 | __register_test(&_##test_name##_object); \ |
| @@ -304,9 +304,9 @@ | |||
| 304 | } \ | 304 | } \ |
| 305 | static struct __test_metadata \ | 305 | static struct __test_metadata \ |
| 306 | _##fixture_name##_##test_name##_object = { \ | 306 | _##fixture_name##_##test_name##_object = { \ |
| 307 | name: #fixture_name "." #test_name, \ | 307 | .name = #fixture_name "." #test_name, \ |
| 308 | fn: &wrapper_##fixture_name##_##test_name, \ | 308 | .fn = &wrapper_##fixture_name##_##test_name, \ |
| 309 | termsig: signal, \ | 309 | .termsig = signal, \ |
| 310 | }; \ | 310 | }; \ |
| 311 | static void __attribute__((constructor)) \ | 311 | static void __attribute__((constructor)) \ |
| 312 | _register_##fixture_name##_##test_name(void) \ | 312 | _register_##fixture_name##_##test_name(void) \ |
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 7e632b465ab4..f69d2ee29742 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c | |||
| @@ -2611,6 +2611,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) | |||
| 2611 | { | 2611 | { |
| 2612 | long ret, sib; | 2612 | long ret, sib; |
| 2613 | void *status; | 2613 | void *status; |
| 2614 | struct timespec delay = { .tv_nsec = 100000000 }; | ||
| 2614 | 2615 | ||
| 2615 | ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { | 2616 | ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { |
| 2616 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | 2617 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); |
| @@ -2664,7 +2665,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) | |||
| 2664 | EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status); | 2665 | EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status); |
| 2665 | /* Poll for actual task death. pthread_join doesn't guarantee it. */ | 2666 | /* Poll for actual task death. pthread_join doesn't guarantee it. */ |
| 2666 | while (!kill(self->sibling[sib].system_tid, 0)) | 2667 | while (!kill(self->sibling[sib].system_tid, 0)) |
| 2667 | sleep(0.1); | 2668 | nanosleep(&delay, NULL); |
| 2668 | /* Switch to the remaining sibling */ | 2669 | /* Switch to the remaining sibling */ |
| 2669 | sib = !sib; | 2670 | sib = !sib; |
| 2670 | 2671 | ||
| @@ -2689,7 +2690,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) | |||
| 2689 | EXPECT_EQ(0, (long)status); | 2690 | EXPECT_EQ(0, (long)status); |
| 2690 | /* Poll for actual task death. pthread_join doesn't guarantee it. */ | 2691 | /* Poll for actual task death. pthread_join doesn't guarantee it. */ |
| 2691 | while (!kill(self->sibling[sib].system_tid, 0)) | 2692 | while (!kill(self->sibling[sib].system_tid, 0)) |
| 2692 | sleep(0.1); | 2693 | nanosleep(&delay, NULL); |
| 2693 | 2694 | ||
| 2694 | ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, | 2695 | ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, |
| 2695 | &self->apply_prog); | 2696 | &self->apply_prog); |
| @@ -2971,6 +2972,12 @@ TEST(get_metadata) | |||
| 2971 | struct seccomp_metadata md; | 2972 | struct seccomp_metadata md; |
| 2972 | long ret; | 2973 | long ret; |
| 2973 | 2974 | ||
| 2975 | /* Only real root can get metadata. */ | ||
| 2976 | if (geteuid()) { | ||
| 2977 | XFAIL(return, "get_metadata requires real root"); | ||
| 2978 | return; | ||
| 2979 | } | ||
| 2980 | |||
| 2974 | ASSERT_EQ(0, pipe(pipefd)); | 2981 | ASSERT_EQ(0, pipe(pipefd)); |
| 2975 | 2982 | ||
| 2976 | pid = fork(); | 2983 | pid = fork(); |
| @@ -2985,11 +2992,11 @@ TEST(get_metadata) | |||
| 2985 | }; | 2992 | }; |
| 2986 | 2993 | ||
| 2987 | /* one with log, one without */ | 2994 | /* one with log, one without */ |
| 2988 | ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, | 2995 | EXPECT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, |
| 2989 | SECCOMP_FILTER_FLAG_LOG, &prog)); | 2996 | SECCOMP_FILTER_FLAG_LOG, &prog)); |
| 2990 | ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)); | 2997 | EXPECT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)); |
| 2991 | 2998 | ||
| 2992 | ASSERT_EQ(0, close(pipefd[0])); | 2999 | EXPECT_EQ(0, close(pipefd[0])); |
| 2993 | ASSERT_EQ(1, write(pipefd[1], "1", 1)); | 3000 | ASSERT_EQ(1, write(pipefd[1], "1", 1)); |
| 2994 | ASSERT_EQ(0, close(pipefd[1])); | 3001 | ASSERT_EQ(0, close(pipefd[1])); |
| 2995 | 3002 | ||
| @@ -3062,6 +3069,11 @@ TEST(user_notification_basic) | |||
| 3062 | .filter = filter, | 3069 | .filter = filter, |
| 3063 | }; | 3070 | }; |
| 3064 | 3071 | ||
| 3072 | ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
| 3073 | ASSERT_EQ(0, ret) { | ||
| 3074 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | ||
| 3075 | } | ||
| 3076 | |||
| 3065 | pid = fork(); | 3077 | pid = fork(); |
| 3066 | ASSERT_GE(pid, 0); | 3078 | ASSERT_GE(pid, 0); |
| 3067 | 3079 | ||
| @@ -3077,7 +3089,7 @@ TEST(user_notification_basic) | |||
| 3077 | EXPECT_EQ(true, WIFEXITED(status)); | 3089 | EXPECT_EQ(true, WIFEXITED(status)); |
| 3078 | EXPECT_EQ(0, WEXITSTATUS(status)); | 3090 | EXPECT_EQ(0, WEXITSTATUS(status)); |
| 3079 | 3091 | ||
| 3080 | /* Add some no-op filters so for grins. */ | 3092 | /* Add some no-op filters for grins. */ |
| 3081 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); | 3093 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); |
| 3082 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); | 3094 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); |
| 3083 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); | 3095 | EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); |
| @@ -3143,6 +3155,11 @@ TEST(user_notification_kill_in_middle) | |||
| 3143 | struct seccomp_notif req = {}; | 3155 | struct seccomp_notif req = {}; |
| 3144 | struct seccomp_notif_resp resp = {}; | 3156 | struct seccomp_notif_resp resp = {}; |
| 3145 | 3157 | ||
| 3158 | ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
| 3159 | ASSERT_EQ(0, ret) { | ||
| 3160 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | ||
| 3161 | } | ||
| 3162 | |||
| 3146 | listener = user_trap_syscall(__NR_getpid, | 3163 | listener = user_trap_syscall(__NR_getpid, |
| 3147 | SECCOMP_FILTER_FLAG_NEW_LISTENER); | 3164 | SECCOMP_FILTER_FLAG_NEW_LISTENER); |
| 3148 | ASSERT_GE(listener, 0); | 3165 | ASSERT_GE(listener, 0); |
| @@ -3190,6 +3207,11 @@ TEST(user_notification_signal) | |||
| 3190 | struct seccomp_notif_resp resp = {}; | 3207 | struct seccomp_notif_resp resp = {}; |
| 3191 | char c; | 3208 | char c; |
| 3192 | 3209 | ||
| 3210 | ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
| 3211 | ASSERT_EQ(0, ret) { | ||
| 3212 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | ||
| 3213 | } | ||
| 3214 | |||
| 3193 | ASSERT_EQ(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair), 0); | 3215 | ASSERT_EQ(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair), 0); |
| 3194 | 3216 | ||
| 3195 | listener = user_trap_syscall(__NR_gettid, | 3217 | listener = user_trap_syscall(__NR_gettid, |
| @@ -3255,6 +3277,11 @@ TEST(user_notification_closed_listener) | |||
| 3255 | long ret; | 3277 | long ret; |
| 3256 | int status, listener; | 3278 | int status, listener; |
| 3257 | 3279 | ||
| 3280 | ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
| 3281 | ASSERT_EQ(0, ret) { | ||
| 3282 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | ||
| 3283 | } | ||
| 3284 | |||
| 3258 | listener = user_trap_syscall(__NR_getpid, | 3285 | listener = user_trap_syscall(__NR_getpid, |
| 3259 | SECCOMP_FILTER_FLAG_NEW_LISTENER); | 3286 | SECCOMP_FILTER_FLAG_NEW_LISTENER); |
| 3260 | ASSERT_GE(listener, 0); | 3287 | ASSERT_GE(listener, 0); |
| @@ -3287,7 +3314,7 @@ TEST(user_notification_child_pid_ns) | |||
| 3287 | struct seccomp_notif req = {}; | 3314 | struct seccomp_notif req = {}; |
| 3288 | struct seccomp_notif_resp resp = {}; | 3315 | struct seccomp_notif_resp resp = {}; |
| 3289 | 3316 | ||
| 3290 | ASSERT_EQ(unshare(CLONE_NEWPID), 0); | 3317 | ASSERT_EQ(unshare(CLONE_NEWUSER | CLONE_NEWPID), 0); |
| 3291 | 3318 | ||
| 3292 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); | 3319 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); |
| 3293 | ASSERT_GE(listener, 0); | 3320 | ASSERT_GE(listener, 0); |
| @@ -3324,6 +3351,10 @@ TEST(user_notification_sibling_pid_ns) | |||
| 3324 | struct seccomp_notif req = {}; | 3351 | struct seccomp_notif req = {}; |
| 3325 | struct seccomp_notif_resp resp = {}; | 3352 | struct seccomp_notif_resp resp = {}; |
| 3326 | 3353 | ||
| 3354 | ASSERT_EQ(prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0), 0) { | ||
| 3355 | TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); | ||
| 3356 | } | ||
| 3357 | |||
| 3327 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); | 3358 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); |
| 3328 | ASSERT_GE(listener, 0); | 3359 | ASSERT_GE(listener, 0); |
| 3329 | 3360 | ||
| @@ -3386,6 +3417,8 @@ TEST(user_notification_fault_recv) | |||
| 3386 | struct seccomp_notif req = {}; | 3417 | struct seccomp_notif req = {}; |
| 3387 | struct seccomp_notif_resp resp = {}; | 3418 | struct seccomp_notif_resp resp = {}; |
| 3388 | 3419 | ||
| 3420 | ASSERT_EQ(unshare(CLONE_NEWUSER), 0); | ||
| 3421 | |||
| 3389 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); | 3422 | listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); |
| 3390 | ASSERT_GE(listener, 0); | 3423 | ASSERT_GE(listener, 0); |
| 3391 | 3424 | ||
