Commit a448c643 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-5.1-rc1' of...

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
parents 2bb99540 0e27ded1
...@@ -154,17 +154,17 @@ fi ...@@ -154,17 +154,17 @@ fi
# Define text colors # Define text colors
# Check available colors on the terminal, if any # Check available colors on the terminal, if any
ncolors=`tput colors 2>/dev/null` ncolors=`tput colors 2>/dev/null || echo 0`
color_reset= color_reset=
color_red= color_red=
color_green= color_green=
color_blue= color_blue=
# If stdout exists and number of colors is eight or more, use them # If stdout exists and number of colors is eight or more, use them
if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then if [ -t 1 -a "$ncolors" -ge 8 ]; then
color_reset="\e[0m" color_reset="\033[0m"
color_red="\e[31m" color_red="\033[31m"
color_green="\e[32m" color_green="\033[32m"
color_blue="\e[34m" color_blue="\033[34m"
fi fi
strip_esc() { strip_esc() {
...@@ -173,8 +173,13 @@ strip_esc() { ...@@ -173,8 +173,13 @@ strip_esc() {
} }
prlog() { # messages prlog() { # messages
echo -e "$@" newline="\n"
[ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE if [ "$1" = "-n" ] ; then
newline=
shift
fi
printf "$*$newline"
[ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE
} }
catlog() { #file catlog() { #file
cat $1 cat $1
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#define TEST_SCANCODES 10 #define TEST_SCANCODES 10
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define SYSFS_PATH_MAX 256
#define DNAME_PATH_MAX 256
static const struct { static const struct {
enum rc_proto proto; enum rc_proto proto;
...@@ -56,7 +58,7 @@ static const struct { ...@@ -56,7 +58,7 @@ static const struct {
int lirc_open(const char *rc) int lirc_open(const char *rc)
{ {
struct dirent *dent; struct dirent *dent;
char buf[100]; char buf[SYSFS_PATH_MAX + DNAME_PATH_MAX];
DIR *d; DIR *d;
int fd; int fd;
...@@ -74,7 +76,7 @@ int lirc_open(const char *rc) ...@@ -74,7 +76,7 @@ int lirc_open(const char *rc)
} }
if (!dent) if (!dent)
ksft_exit_fail_msg("cannot find lirc device for %s\n", rc); ksft_exit_skip("cannot find lirc device for %s\n", rc);
closedir(d); closedir(d);
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
# Kselftest framework requirement - SKIP code is 4. # Kselftest framework requirement - SKIP code is 4.
ksft_skip=4 ksft_skip=4
if [ $UID != 0 ]; then
echo "Please run ir_loopback test as root [SKIP]"
exit $ksft_skip
fi
if ! /sbin/modprobe -q -n rc-loopback; then if ! /sbin/modprobe -q -n rc-loopback; then
echo "ir_loopback: module rc-loopback is not found [SKIP]" echo "ir_loopback: module rc-loopback is not found [SKIP]"
exit $ksft_skip exit $ksft_skip
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
/* define kselftest exit codes */ /* define kselftest exit codes */
#define KSFT_PASS 0 #define KSFT_PASS 0
......
...@@ -168,8 +168,8 @@ ...@@ -168,8 +168,8 @@
#define __TEST_IMPL(test_name, _signal) \ #define __TEST_IMPL(test_name, _signal) \
static void test_name(struct __test_metadata *_metadata); \ static void test_name(struct __test_metadata *_metadata); \
static struct __test_metadata _##test_name##_object = \ static struct __test_metadata _##test_name##_object = \
{ name: "global." #test_name, \ { .name = "global." #test_name, \
fn: &test_name, termsig: _signal }; \ .fn = &test_name, .termsig = _signal }; \
static void __attribute__((constructor)) _register_##test_name(void) \ static void __attribute__((constructor)) _register_##test_name(void) \
{ \ { \
__register_test(&_##test_name##_object); \ __register_test(&_##test_name##_object); \
...@@ -304,9 +304,9 @@ ...@@ -304,9 +304,9 @@
} \ } \
static struct __test_metadata \ static struct __test_metadata \
_##fixture_name##_##test_name##_object = { \ _##fixture_name##_##test_name##_object = { \
name: #fixture_name "." #test_name, \ .name = #fixture_name "." #test_name, \
fn: &wrapper_##fixture_name##_##test_name, \ .fn = &wrapper_##fixture_name##_##test_name, \
termsig: signal, \ .termsig = signal, \
}; \ }; \
static void __attribute__((constructor)) \ static void __attribute__((constructor)) \
_register_##fixture_name##_##test_name(void) \ _register_##fixture_name##_##test_name(void) \
......
...@@ -2611,6 +2611,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) ...@@ -2611,6 +2611,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
{ {
long ret, sib; long ret, sib;
void *status; void *status;
struct timespec delay = { .tv_nsec = 100000000 };
ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
...@@ -2664,7 +2665,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) ...@@ -2664,7 +2665,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status); EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status);
/* Poll for actual task death. pthread_join doesn't guarantee it. */ /* Poll for actual task death. pthread_join doesn't guarantee it. */
while (!kill(self->sibling[sib].system_tid, 0)) while (!kill(self->sibling[sib].system_tid, 0))
sleep(0.1); nanosleep(&delay, NULL);
/* Switch to the remaining sibling */ /* Switch to the remaining sibling */
sib = !sib; sib = !sib;
...@@ -2689,7 +2690,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter) ...@@ -2689,7 +2690,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
EXPECT_EQ(0, (long)status); EXPECT_EQ(0, (long)status);
/* Poll for actual task death. pthread_join doesn't guarantee it. */ /* Poll for actual task death. pthread_join doesn't guarantee it. */
while (!kill(self->sibling[sib].system_tid, 0)) while (!kill(self->sibling[sib].system_tid, 0))
sleep(0.1); nanosleep(&delay, NULL);
ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC,
&self->apply_prog); &self->apply_prog);
...@@ -2971,6 +2972,12 @@ TEST(get_metadata) ...@@ -2971,6 +2972,12 @@ TEST(get_metadata)
struct seccomp_metadata md; struct seccomp_metadata md;
long ret; long ret;
/* Only real root can get metadata. */
if (geteuid()) {
XFAIL(return, "get_metadata requires real root");
return;
}
ASSERT_EQ(0, pipe(pipefd)); ASSERT_EQ(0, pipe(pipefd));
pid = fork(); pid = fork();
...@@ -2985,11 +2992,11 @@ TEST(get_metadata) ...@@ -2985,11 +2992,11 @@ TEST(get_metadata)
}; };
/* one with log, one without */ /* one with log, one without */
ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, EXPECT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER,
SECCOMP_FILTER_FLAG_LOG, &prog)); SECCOMP_FILTER_FLAG_LOG, &prog));
ASSERT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)); EXPECT_EQ(0, seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog));
ASSERT_EQ(0, close(pipefd[0])); EXPECT_EQ(0, close(pipefd[0]));
ASSERT_EQ(1, write(pipefd[1], "1", 1)); ASSERT_EQ(1, write(pipefd[1], "1", 1));
ASSERT_EQ(0, close(pipefd[1])); ASSERT_EQ(0, close(pipefd[1]));
...@@ -3062,6 +3069,11 @@ TEST(user_notification_basic) ...@@ -3062,6 +3069,11 @@ TEST(user_notification_basic)
.filter = filter, .filter = filter,
}; };
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
ASSERT_EQ(0, ret) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
}
pid = fork(); pid = fork();
ASSERT_GE(pid, 0); ASSERT_GE(pid, 0);
...@@ -3077,7 +3089,7 @@ TEST(user_notification_basic) ...@@ -3077,7 +3089,7 @@ TEST(user_notification_basic)
EXPECT_EQ(true, WIFEXITED(status)); EXPECT_EQ(true, WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status)); EXPECT_EQ(0, WEXITSTATUS(status));
/* Add some no-op filters so for grins. */ /* Add some no-op filters for grins. */
EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0);
EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0);
EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0); EXPECT_EQ(seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog), 0);
...@@ -3143,6 +3155,11 @@ TEST(user_notification_kill_in_middle) ...@@ -3143,6 +3155,11 @@ TEST(user_notification_kill_in_middle)
struct seccomp_notif req = {}; struct seccomp_notif req = {};
struct seccomp_notif_resp resp = {}; struct seccomp_notif_resp resp = {};
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
ASSERT_EQ(0, ret) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
}
listener = user_trap_syscall(__NR_getpid, listener = user_trap_syscall(__NR_getpid,
SECCOMP_FILTER_FLAG_NEW_LISTENER); SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0); ASSERT_GE(listener, 0);
...@@ -3190,6 +3207,11 @@ TEST(user_notification_signal) ...@@ -3190,6 +3207,11 @@ TEST(user_notification_signal)
struct seccomp_notif_resp resp = {}; struct seccomp_notif_resp resp = {};
char c; char c;
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
ASSERT_EQ(0, ret) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
}
ASSERT_EQ(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair), 0); ASSERT_EQ(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair), 0);
listener = user_trap_syscall(__NR_gettid, listener = user_trap_syscall(__NR_gettid,
...@@ -3255,6 +3277,11 @@ TEST(user_notification_closed_listener) ...@@ -3255,6 +3277,11 @@ TEST(user_notification_closed_listener)
long ret; long ret;
int status, listener; int status, listener;
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
ASSERT_EQ(0, ret) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
}
listener = user_trap_syscall(__NR_getpid, listener = user_trap_syscall(__NR_getpid,
SECCOMP_FILTER_FLAG_NEW_LISTENER); SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0); ASSERT_GE(listener, 0);
...@@ -3287,7 +3314,7 @@ TEST(user_notification_child_pid_ns) ...@@ -3287,7 +3314,7 @@ TEST(user_notification_child_pid_ns)
struct seccomp_notif req = {}; struct seccomp_notif req = {};
struct seccomp_notif_resp resp = {}; struct seccomp_notif_resp resp = {};
ASSERT_EQ(unshare(CLONE_NEWPID), 0); ASSERT_EQ(unshare(CLONE_NEWUSER | CLONE_NEWPID), 0);
listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0); ASSERT_GE(listener, 0);
...@@ -3324,6 +3351,10 @@ TEST(user_notification_sibling_pid_ns) ...@@ -3324,6 +3351,10 @@ TEST(user_notification_sibling_pid_ns)
struct seccomp_notif req = {}; struct seccomp_notif req = {};
struct seccomp_notif_resp resp = {}; struct seccomp_notif_resp resp = {};
ASSERT_EQ(prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0), 0) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
}
listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0); ASSERT_GE(listener, 0);
...@@ -3386,6 +3417,8 @@ TEST(user_notification_fault_recv) ...@@ -3386,6 +3417,8 @@ TEST(user_notification_fault_recv)
struct seccomp_notif req = {}; struct seccomp_notif req = {};
struct seccomp_notif_resp resp = {}; struct seccomp_notif_resp resp = {};
ASSERT_EQ(unshare(CLONE_NEWUSER), 0);
listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0); ASSERT_GE(listener, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment