linux-kselftest-5.1-rc1

This Kselftest update for Linux 5.1-rc1 consists of
 
 - 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
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEPZKym/RZuOCGeA/kCwJExA0NQxwFAlyAMs0ACgkQCwJExA0N
 Qxwmmg/9HNey+j6hxIz96UvaLPqTe0cwiIOs/vrU2OQ3fBQCH+th+m9zdh+bKZKc
 xGRKrlDsgwuw+u3f+sYy27IZHgMc4jzLvsdd2Abw5z6jJKaVw5EnT55LWarZu/R3
 xFhdWWx7+4F7XwpP9bUGTKXv1doPJoXt/VRZjuOA3h/D3PFaWklMYem7oZ0YAhQF
 +nVeMBv2s0iIG9sdGY7dBQ78WgZr14dyKuvrPseCKJ17ldO6R5xfT5kmziSbE5Ne
 Ys/LJujNaSCS9su0Ha3w/TednpOepsTiJ+4uinhJ3OBlVgRHKgjpM8g1emAm//Sf
 cqsT8XZbijkkvwyHLE18ccX2TmZ9HMByZTOJx4NUqR0MSzisR+Wy61AXk2RwmirF
 UGhjFk+ewMCAP/q5GnXgSunWmx3hGoKmMMRdIwhZIltrfC4tqESW4oucjbwVfvCA
 oeRlZv1LHeVLBzgWppQoUlqkZGyXeoV1HHj3AaIwqq18WsYkpm+mAAj6xaIM6Egj
 mdrxJLdwkmrMClaJFQYIzvAVArFBD7rh8eN12BDtifecF9tIj4WV4yYwqVx9nETd
 9zNaCHy1UJorgzgCkptkSBZt84tc3C0MWb33KQP+rF4FaReq735L/DUyFQCQcqCs
 q2ZtiRZ+BVGJyT1oCSeS95CaQeJ2L+1h0PeoBkNl6+I8QIWntEo=
 =1CrX
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2019-03-09 09:19:31 -08:00
commit a448c643bc
6 changed files with 68 additions and 22 deletions

View File

@ -154,17 +154,17 @@ fi
# Define text colors
# 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_red=
color_green=
color_blue=
# If stdout exists and number of colors is eight or more, use them
if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then
color_reset="\e[0m"
color_red="\e[31m"
color_green="\e[32m"
color_blue="\e[34m"
if [ -t 1 -a "$ncolors" -ge 8 ]; then
color_reset="\033[0m"
color_red="\033[31m"
color_green="\033[32m"
color_blue="\033[34m"
fi
strip_esc() {
@ -173,8 +173,13 @@ strip_esc() {
}
prlog() { # messages
echo -e "$@"
[ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE
newline="\n"
if [ "$1" = "-n" ] ; then
newline=
shift
fi
printf "$*$newline"
[ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE
}
catlog() { #file
cat $1

View File

@ -27,6 +27,8 @@
#define TEST_SCANCODES 10
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define SYSFS_PATH_MAX 256
#define DNAME_PATH_MAX 256
static const struct {
enum rc_proto proto;
@ -56,7 +58,7 @@ static const struct {
int lirc_open(const char *rc)
{
struct dirent *dent;
char buf[100];
char buf[SYSFS_PATH_MAX + DNAME_PATH_MAX];
DIR *d;
int fd;
@ -74,7 +76,7 @@ int lirc_open(const char *rc)
}
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);

View File

@ -4,6 +4,11 @@
# Kselftest framework requirement - SKIP code is 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
echo "ir_loopback: module rc-loopback is not found [SKIP]"
exit $ksft_skip

View File

@ -13,6 +13,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdio.h>
/* define kselftest exit codes */
#define KSFT_PASS 0

View File

@ -168,8 +168,8 @@
#define __TEST_IMPL(test_name, _signal) \
static void test_name(struct __test_metadata *_metadata); \
static struct __test_metadata _##test_name##_object = \
{ name: "global." #test_name, \
fn: &test_name, termsig: _signal }; \
{ .name = "global." #test_name, \
.fn = &test_name, .termsig = _signal }; \
static void __attribute__((constructor)) _register_##test_name(void) \
{ \
__register_test(&_##test_name##_object); \
@ -304,9 +304,9 @@
} \
static struct __test_metadata \
_##fixture_name##_##test_name##_object = { \
name: #fixture_name "." #test_name, \
fn: &wrapper_##fixture_name##_##test_name, \
termsig: signal, \
.name = #fixture_name "." #test_name, \
.fn = &wrapper_##fixture_name##_##test_name, \
.termsig = signal, \
}; \
static void __attribute__((constructor)) \
_register_##fixture_name##_##test_name(void) \

View File

@ -2611,6 +2611,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
{
long ret, sib;
void *status;
struct timespec delay = { .tv_nsec = 100000000 };
ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
@ -2664,7 +2665,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
EXPECT_EQ(SIBLING_EXIT_UNKILLED, (long)status);
/* Poll for actual task death. pthread_join doesn't guarantee it. */
while (!kill(self->sibling[sib].system_tid, 0))
sleep(0.1);
nanosleep(&delay, NULL);
/* Switch to the remaining sibling */
sib = !sib;
@ -2689,7 +2690,7 @@ TEST_F(TSYNC, two_siblings_not_under_filter)
EXPECT_EQ(0, (long)status);
/* Poll for actual task death. pthread_join doesn't guarantee it. */
while (!kill(self->sibling[sib].system_tid, 0))
sleep(0.1);
nanosleep(&delay, NULL);
ret = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC,
&self->apply_prog);
@ -2971,6 +2972,12 @@ TEST(get_metadata)
struct seccomp_metadata md;
long ret;
/* Only real root can get metadata. */
if (geteuid()) {
XFAIL(return, "get_metadata requires real root");
return;
}
ASSERT_EQ(0, pipe(pipefd));
pid = fork();
@ -2985,11 +2992,11 @@ TEST(get_metadata)
};
/* 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));
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(0, close(pipefd[1]));
@ -3062,6 +3069,11 @@ TEST(user_notification_basic)
.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();
ASSERT_GE(pid, 0);
@ -3077,7 +3089,7 @@ TEST(user_notification_basic)
EXPECT_EQ(true, WIFEXITED(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);
@ -3143,6 +3155,11 @@ TEST(user_notification_kill_in_middle)
struct seccomp_notif req = {};
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,
SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0);
@ -3190,6 +3207,11 @@ TEST(user_notification_signal)
struct seccomp_notif_resp resp = {};
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);
listener = user_trap_syscall(__NR_gettid,
@ -3255,6 +3277,11 @@ TEST(user_notification_closed_listener)
long ret;
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,
SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0);
@ -3287,7 +3314,7 @@ TEST(user_notification_child_pid_ns)
struct seccomp_notif req = {};
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);
ASSERT_GE(listener, 0);
@ -3324,6 +3351,10 @@ TEST(user_notification_sibling_pid_ns)
struct seccomp_notif req = {};
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);
ASSERT_GE(listener, 0);
@ -3386,6 +3417,8 @@ TEST(user_notification_fault_recv)
struct seccomp_notif req = {};
struct seccomp_notif_resp resp = {};
ASSERT_EQ(unshare(CLONE_NEWUSER), 0);
listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0);