diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-08-14 03:27:44 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2021-08-14 01:27:44 +0000 |
commit | 4d5e2904e9096e992b2bc8bd6eb7d686c3b3a719 (patch) | |
tree | a57d34362089b0097945557f41745f21c226aede | |
parent | 9c0a53ac66a80d957ad025683d34ab68199f4083 (diff) | |
download | strace-4d5e2904e9096e992b2bc8bd6eb7d686c3b3a719.tar.gz |
tests: convert prctl-fp-mode and prctl-spec-inject into generated tests
And also avoid injecting values into prctl() calls issued by libc during
process startup.
* tests/Makefile.am (DECODER_TESTS): Remove prctl-fp-mode.test
and prctl-spec-inject.test.
* tests/gen_tests.in (prctl-fp-mode, prctl-spec-inject): New tests.
* tests/prctl-fp-mode.test: Remove.
* tests/prctl-spec-inject.test: Likewise.
* tests/prctl-fp-mode.c: Implement injected return value locking sequence.
* tests/prctl-spec-inject.c: Likewise.
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/gen_tests.in | 2 | ||||
-rw-r--r-- | tests/prctl-fp-mode.c | 28 | ||||
-rwxr-xr-x | tests/prctl-fp-mode.test | 32 | ||||
-rw-r--r-- | tests/prctl-spec-inject.c | 28 | ||||
-rwxr-xr-x | tests/prctl-spec-inject.test | 35 |
6 files changed, 48 insertions, 79 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index ce3014df8..274cc3bf3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -435,9 +435,7 @@ DECODER_TESTS = \ pipe.test \ poll-P.test \ poll.test \ - prctl-fp-mode.test \ prctl-seccomp-strict.test \ - prctl-spec-inject.test \ qual_fault-exit_group.test \ readv.test \ rt_sigaction.test \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index c5a1fbd94..bb5410892 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -584,6 +584,7 @@ prctl-arg2-intptr +prctl.sh -a25 prctl-cap-ambient +prctl.sh -a21 prctl-capbset +prctl.sh -a21 prctl-dumpable +prctl.sh -a23 +prctl-fp-mode +prctl-success.sh PRCTL_INJECT_RETVALS="error=ENOTTY 0 1 2 3 32 35" -a21 prctl-mce-kill +prctl.sh -a21 prctl-name +prctl.sh -a23 prctl-no-args +prctl.sh -a21 @@ -603,6 +604,7 @@ prctl-securebits-success +prctl-success.sh PRCTL_INJECT_RETVALS="0 1 42 255 256 prctl-securebits-success-Xabbrev +prctl-success.sh PRCTL_INJECT_RETVALS="0 1 42 255 256 511" -a25 -Xabbrev prctl-securebits-success-Xraw +prctl-success.sh PRCTL_INJECT_RETVALS="0 1 42 255 256 511" -a12 -Xraw prctl-securebits-success-Xverbose +prctl-success.sh PRCTL_INJECT_RETVALS="0 1 42 255 256 511" -a36 -Xverbose +prctl-spec-inject +prctl-success.sh PRCTL_INJECT_RETVALS="error=ENOTTY 0 1 3 8 16 32 42" -a53 prctl-sve +prctl.sh -a21 prctl-syscall-user-dispatch +prctl.sh -a68 prctl-tagged-addr +prctl.sh -a43 diff --git a/tests/prctl-fp-mode.c b/tests/prctl-fp-mode.c index fd354e4db..6ec60dde0 100644 --- a/tests/prctl-fp-mode.c +++ b/tests/prctl-fp-mode.c @@ -9,6 +9,7 @@ #include "tests.h" #include "scno.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -62,15 +63,32 @@ main(int argc, char **argv) }; long rc; + unsigned long num_skip; const char *str = NULL; + bool locked = false; - if (argc < 2) - error_msg_and_fail("Usage: %s INJECTED_VAL", argv[0]); + if (argc < 3) + error_msg_and_fail("Usage: %s NUM_SKIP INJECT_RETVAL", argv[0]); - injected_val = strtol(argv[1], NULL, 0); + num_skip = strtoul(argv[1], NULL, 0); + injected_val = strtol(argv[2], NULL, 0); - syscall(__NR_prctl, -1U, (unsigned long) -2U, (unsigned long) -3U, - (unsigned long) -4U, (unsigned long) -5U); + for (size_t i = 0; i < num_skip; i++) { + long ret = syscall(__NR_prctl, -1U, (unsigned long) -2U, + (unsigned long) -3U, (unsigned long) -4U, + (unsigned long) -5U); + + if ((ret != injected_val) || + ((injected_val == -1) && (errno != ENOTTY))) + continue; + + locked = true; + break; + } + + if (!locked) + error_msg_and_fail("Have not locked on prctl(-1, -2, -3, -4" + ", -5) returning %ld", injected_val); /* PR_GET_FP_MODE */ rc = do_prctl(PR_GET_FP_MODE, bogus_arg2, bogus_arg3); diff --git a/tests/prctl-fp-mode.test b/tests/prctl-fp-mode.test deleted file mode 100755 index ce6c786b9..000000000 --- a/tests/prctl-fp-mode.test +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -efu -# -# Check decoding of prctl PR_GET_FP_MODE/PR_SET_FP_MODE operations. -# -# Copyright (c) 2021 The strace developers. -# All rights reserved. -# -# SPDX-License-Identifier: GPL-2.0-or-later - -. "${srcdir=.}/scno_tampering.sh" - -fault_args='-a21 -e trace=prctl -e inject=prctl:' -prog="../$NAME" - -test_run_rval() -{ - local rval injexpr - rval="$1"; shift - injexpr="$1"; shift - - run_strace $fault_args$injexpr $prog $rval > "$EXP" - sed '0,/^prctl(0xffffffff \/\* PR_??? \*\/, 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb) = .\+ (INJECTED)/d' < "$LOG" > "$OUT" - match_diff "$OUT" "$EXP" -} - -test_run_rval -1 "error=ENOTTY" -test_run_rval 0 "retval=0" -test_run_rval 1 "retval=1" -test_run_rval 2 "retval=2" -test_run_rval 3 "retval=3" -test_run_rval 32 "retval=32" -test_run_rval 35 "retval=35" diff --git a/tests/prctl-spec-inject.c b/tests/prctl-spec-inject.c index d18864cfd..455ce2f31 100644 --- a/tests/prctl-spec-inject.c +++ b/tests/prctl-spec-inject.c @@ -11,6 +11,7 @@ #include "tests.h" #include "scno.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -79,15 +80,32 @@ main(int argc, char **argv) }; long rc; + unsigned long num_skip; const char *str = NULL; + bool locked = false; - if (argc < 2) - error_msg_and_fail("Usage: %s INJECTED_VAL", argv[0]); + if (argc < 3) + error_msg_and_fail("Usage: %s NUM_SKIP INJECT_RETVAL", argv[0]); - injected_val = strtol(argv[1], NULL, 0); + num_skip = strtoul(argv[1], NULL, 0); + injected_val = strtol(argv[2], NULL, 0); - syscall(__NR_prctl, -1U, (unsigned long) -2U, (unsigned long) -3U, - (unsigned long) -4U, (unsigned long) -5U); + for (size_t i = 0; i < num_skip; i++) { + long ret = syscall(__NR_prctl, -1U, (unsigned long) -2U, + (unsigned long) -3U, (unsigned long) -4U, + (unsigned long) -5U); + + if ((ret != injected_val) || + ((injected_val == -1) && (errno != ENOTTY))) + continue; + + locked = true; + break; + } + + if (!locked) + error_msg_and_fail("Have not locked on prctl(-1, -2, -3, -4" + ", -5) returning %ld", injected_val); /* PR_GET_SPECULATION_CTRL */ rc = do_prctl(52, 2, bogus_arg3); diff --git a/tests/prctl-spec-inject.test b/tests/prctl-spec-inject.test deleted file mode 100755 index 4f0c556ed..000000000 --- a/tests/prctl-spec-inject.test +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -efu -# -# Check decoding of PR_SET_SPECULATION_CTRL and PR_GET_SPECULATION_CTRL -# prctl operations. -# -# Copyright (c) 2018-2021 The strace developers. -# All rights reserved. -# -# SPDX-License-Identifier: GPL-2.0-or-later - -. "${srcdir=.}/scno_tampering.sh" - -fault_args='-a53 -e trace=prctl -e inject=prctl:' -prog="../$NAME" - -test_run_rval() -{ - local run rval injexpr - run="$1"; shift - rval="$1"; shift - injexpr="$1"; shift - - run_strace $fault_args$injexpr $prog $rval > "$EXP" - sed '0,/^prctl(0xffffffff \/\* PR_??? \*\/, 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb) = .\+ (INJECTED)/d' < "$LOG" > "$OUT" - match_diff "$OUT" "$EXP" -} - -test_run_rval 0 -1 "error=ENOTTY" -test_run_rval 1 0 "retval=0" -test_run_rval 2 1 "retval=1" -test_run_rval 3 3 "retval=3" -test_run_rval 4 8 "retval=8" -test_run_rval 5 16 "retval=16" -test_run_rval 6 32 "retval=32" -test_run_rval 7 42 "retval=42" |