* tests/.gitignore: Add delete_nodule, finit_module, init_module. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add delete_module.test, finit_module.test, init_module.test. (EXTRA_DIST): Add init_delete_module.h. * tests/delete_module.c: New file. * tests/delete_module.test: Likewise. * tests/finit_module.c: Likewise. * tests/finit_module.test: Likewise. * tests/init_delete_module.c: Likewise. * tests/init_module.c: Likewise. * tests/init_module.test: Likewise. --- tests/.gitignore | 3 ++ tests/Makefile.am | 7 +++ tests/delete_module.c | 118 +++++++++++++++++++++++++++++++++++++++++ tests/delete_module.test | 6 +++ tests/finit_module.c | 124 ++++++++++++++++++++++++++++++++++++++++++++ tests/finit_module.test | 6 +++ tests/init_delete_module.h | 37 +++++++++++++ tests/init_module.c | 113 ++++++++++++++++++++++++++++++++++++++++ tests/init_module.test | 6 +++ 9 files changed, 420 insertions(+) create mode 100644 tests/delete_module.c create mode 100755 tests/delete_module.test create mode 100644 tests/finit_module.c create mode 100755 tests/finit_module.test create mode 100644 tests/init_delete_module.h create mode 100644 tests/init_module.c create mode 100755 tests/init_module.test
diff --git a/tests/.gitignore b/tests/.gitignore index 85798bb..191bb6f 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -31,6 +31,7 @@ clock_xettime copy_file_range count-f creat +delete_module dup dup2 dup3 @@ -61,6 +62,7 @@ fdatasync file_handle file_ioctl filter-unavailable +finit_module flock fork-f fstat @@ -101,6 +103,7 @@ getuid getuid32 getxxid inet-cmsg +init_module inotify inotify_init1 ioctl diff --git a/tests/Makefile.am b/tests/Makefile.am index c5ebb69..e3adfbf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -91,6 +91,7 @@ check_PROGRAMS = \ copy_file_range \ count-f \ creat \ + delete_module \ dup \ dup2 \ dup3 \ @@ -121,6 +122,7 @@ check_PROGRAMS = \ file_handle \ file_ioctl \ filter-unavailable \ + finit_module \ flock \ fork-f \ fstat \ @@ -161,6 +163,7 @@ check_PROGRAMS = \ getuid32 \ getxxid \ inet-cmsg \ + init_module \ inotify \ inotify_init1 \ ioctl \ @@ -449,6 +452,7 @@ DECODER_TESTS = \ clock_xettime.test \ copy_file_range.test \ creat.test \ + delete_module.test \ dup.test \ dup2.test \ dup3.test \ @@ -478,6 +482,7 @@ DECODER_TESTS = \ fdatasync.test \ file_handle.test \ file_ioctl.test \ + finit_module.test \ flock.test \ fstat.test \ fstat64.test \ @@ -517,6 +522,7 @@ DECODER_TESTS = \ getuid32.test \ getxxid.test \ inet-cmsg.test \ + init_module.test \ inotify.test \ inotify_init1.test \ ioctl.test \ @@ -787,6 +793,7 @@ EXTRA_DIST = init.sh run.sh match.awk \ fstatat.c \ fstatx.c \ getresugid.c \ + init_delete_module.h \ ipc.sh \ ipc_msgbuf.expected \ ksysent.sed \ diff --git a/tests/delete_module.c b/tests/delete_module.c new file mode 100644 index 0000000..7e3de20 --- /dev/null +++ b/tests/delete_module.c @@ -0,0 +1,118 @@ +/* + * Check decoding of delete_module syscall. + * + * Copyright (c) 2016 Eugene Syromyatnikov <evg...@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" + +#include <asm/unistd.h> + +#if defined(__NR_delete_module) + +# include <errno.h> +# include <stdio.h> +# include <unistd.h> + +# include "init_delete_module.h" + +int +main(void) +{ + static const struct { + kernel_ulong_t val; + const char *str; + } flags[] = { + { ARG_STR(0) }, + { (kernel_ulong_t) 0xffffffff00000800ULL, "O_NONBLOCK" }, + { (kernel_ulong_t) 0xbadc0dedfacef157ULL, + "0xfacef157 /* O_??? */" }, + { (kernel_ulong_t) 0xfacef157deade71cULL, + "O_TRUNC|0xdeade51c" }, + { -1LL, "O_NONBLOCK|O_TRUNC|0xfffff5ff" }, + }; + + long rc; + char *bogus_param1 = tail_alloc(PARAM1_LEN); + char *bogus_param2 = tail_alloc(PARAM2_LEN); + int saved_errno; + + fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN); + fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN); + + rc = syscall(__NR_delete_module, NULL, bogus_zero); + printf("delete_module(NULL, 0) = %s\n", sprintrc(rc)); + + rc = syscall(__NR_delete_module, bogus_param1, flags[0].val); + saved_errno = errno; + + printf("delete_module(\""); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\"..., %s) = %s\n", flags[0].str, sprintrc(rc)); + + bogus_param1[PARAM1_LEN - 1] = '\0'; + + rc = syscall(__NR_delete_module, bogus_param1, flags[1].val); + saved_errno = errno; + + printf("delete_module(\""); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\", %s) = %s\n", flags[1].str, sprintrc(rc)); + + rc = syscall(__NR_delete_module, bogus_param2 + PARAM2_LEN, + flags[2].val); + printf("delete_module(%p, %s) = %s\n", + bogus_param2 + PARAM2_LEN, flags[2].str, sprintrc(rc)); + + rc = syscall(__NR_delete_module, bogus_param2, flags[3].val); + printf("delete_module(%p, %s) = %s\n", + bogus_param2, flags[3].str, sprintrc(rc)); + + bogus_param2[PARAM2_LEN - 1] = '\0'; + + rc = syscall(__NR_delete_module, bogus_param2, flags[4].val); + saved_errno = errno; + + printf("delete_module(\""); + print_str(PARAM2_BASE, PARAM2_LEN - 1, true); + + saved_errno = errno; + printf("\", %s) = %s\n", flags[4].str, sprintrc(rc)); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_delete_module"); + +#endif diff --git a/tests/delete_module.test b/tests/delete_module.test new file mode 100755 index 0000000..4cee71a --- /dev/null +++ b/tests/delete_module.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check decoding of delete_module syscall. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a1 diff --git a/tests/finit_module.c b/tests/finit_module.c new file mode 100644 index 0000000..1c626dc --- /dev/null +++ b/tests/finit_module.c @@ -0,0 +1,124 @@ +/* + * Check decoding of finit_module syscall. + * + * Copyright (c) 2016 Eugene Syromyatnikov <evg...@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" + +#include <asm/unistd.h> + +#if defined(__NR_finit_module) + +# include <errno.h> +# include <stdio.h> +# include <unistd.h> + +# include "init_delete_module.h" + +int +main(void) +{ + static const kernel_ulong_t bogus_fd = + (kernel_ulong_t) 0xdeb0d1edbeeff00dULL; + + static const struct { + kernel_ulong_t val; + const char *str; + } flags[] = { + { ARG_STR(0) }, + { (kernel_ulong_t) 0xffffffff00000002ULL, + "MODULE_INIT_IGNORE_VERMAGIC" }, + { (kernel_ulong_t) 0xbadc0deddefaced0ULL, + "0xdefaced0 /* MODULE_INIT_??? */" }, + { (kernel_ulong_t) 0xfacef157dec0ded1ULL, + "MODULE_INIT_IGNORE_MODVERSIONS|0xdec0ded0" }, + { -1LL, "MODULE_INIT_IGNORE_MODVERSIONS|" + "MODULE_INIT_IGNORE_VERMAGIC|0xfffffffc" }, + }; + + long rc; + char *bogus_param1 = tail_alloc(PARAM1_LEN); + char *bogus_param2 = tail_alloc(PARAM2_LEN); + int saved_errno; + + fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN); + fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN); + + rc = syscall(__NR_finit_module, bogus_zero, NULL, bogus_zero); + printf("finit_module(0, NULL, 0) = %s\n", sprintrc(rc)); + + rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[0].val); + saved_errno = errno; + + printf("finit_module(%d, \"", (int) bogus_fd); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\"..., %s) = %s\n", flags[0].str, sprintrc(rc)); + + bogus_param1[PARAM1_LEN - 1] = '\0'; + + rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[1].val); + saved_errno = errno; + + printf("finit_module(%d, \"", (int) bogus_fd); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\", %s) = %s\n", flags[1].str, sprintrc(rc)); + + rc = syscall(__NR_finit_module, bogus_fd, bogus_param2 + PARAM2_LEN, + flags[2].val); + printf("finit_module(%d, %p, %s) = %s\n", + (int) bogus_fd, bogus_param2 + PARAM2_LEN, flags[2].str, + sprintrc(rc)); + + rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[3].val); + printf("finit_module(%d, %p, %s) = %s\n", + (int) bogus_fd, bogus_param2, flags[3].str, sprintrc(rc)); + + bogus_param2[PARAM2_LEN - 1] = '\0'; + + rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[4].val); + saved_errno = errno; + + printf("finit_module(%d, \"", (int) bogus_fd); + print_str(PARAM2_BASE, PARAM2_LEN - 1, true); + + saved_errno = errno; + printf("\", %s) = %s\n", flags[4].str, sprintrc(rc)); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_finit_module"); + +#endif diff --git a/tests/finit_module.test b/tests/finit_module.test new file mode 100755 index 0000000..f56cf0d --- /dev/null +++ b/tests/finit_module.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check decoding of finit_module syscall. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a1 diff --git a/tests/init_delete_module.h b/tests/init_delete_module.h new file mode 100644 index 0000000..109f32e --- /dev/null +++ b/tests/init_delete_module.h @@ -0,0 +1,37 @@ +#ifndef STRACE_TESTS_INIT_DELETE_MODULE_H +#define STRACE_TESTS_INIT_DELETE_MODULE_H + +# include <stdbool.h> +# include <stdio.h> + +# include "kernel_types.h" + + +enum { + PARAM1_LEN = 33, + PARAM2_LEN = 8, + PARAM1_BASE = 0x30, + PARAM2_BASE = 0x80, + MAX_STRLEN = 32, +}; + +static const kernel_ulong_t bogus_zero = + (kernel_ulong_t) 0xffffffff00000000ULL; + +static void +print_str(unsigned int base, unsigned int len, bool escape) +{ + unsigned int i; + + if (!escape) { + for (i = base; i < (base + len); i++) + putc(i, stdout); + + return; + } + + for (i = base; i < (base + len); i++) + printf("\\%u%u%u", (i >> 6) & 0x3, (i >> 3) & 0x7, i & 0x7); +} + +#endif /* !STRACE_TESTS_INIT_DELETE_MODULE_H */ diff --git a/tests/init_module.c b/tests/init_module.c new file mode 100644 index 0000000..9ac8c19 --- /dev/null +++ b/tests/init_module.c @@ -0,0 +1,113 @@ +/* + * Check decoding of init_module syscall. + * + * Copyright (c) 2016 Eugene Syromyatnikov <evg...@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" + +#include <asm/unistd.h> + +#if defined(__NR_init_module) + +# include <errno.h> +# include <stdio.h> +# include <unistd.h> + +# include "init_delete_module.h" + +int +main(void) +{ + + static const kernel_ulong_t bogus_addr = + (kernel_ulong_t) 0xfffffeedfffffaceULL; + static const kernel_ulong_t bogus_len = + (kernel_ulong_t) 0xfffffca7ffffc0deULL; + + long rc; + char *bogus_param1 = tail_alloc(PARAM1_LEN); + char *bogus_param2 = tail_alloc(PARAM2_LEN); + int saved_errno; + + fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN); + fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN); + + rc = syscall(__NR_init_module, NULL, bogus_zero, NULL); + printf("init_module(NULL, %llu, NULL) = %s\n", + (unsigned long long) bogus_zero, sprintrc(rc)); + + rc = syscall(__NR_init_module, bogus_addr, 0, bogus_param1); + saved_errno = errno; + + printf("init_module(%#llx, 0, \"", (unsigned long long) bogus_addr); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\"...) = %s\n", sprintrc(rc)); + + bogus_param1[PARAM1_LEN - 1] = '\0'; + + rc = syscall(__NR_init_module, bogus_addr, 0, bogus_param1); + saved_errno = errno; + + printf("init_module(%#llx, 0, \"", (unsigned long long) bogus_addr); + print_str(PARAM1_BASE, MAX_STRLEN, false); + + errno = saved_errno; + printf("\") = %s\n", sprintrc(rc)); + + rc = syscall(__NR_init_module, bogus_addr, bogus_len, + bogus_param2 + PARAM2_LEN); + printf("init_module(%#llx, %llu, %p) = %s\n", + (unsigned long long) bogus_addr, (unsigned long long) bogus_len, + bogus_param2 + PARAM2_LEN, sprintrc(rc)); + + rc = syscall(__NR_init_module, NULL, bogus_len, bogus_param2); + printf("init_module(NULL, %llu, %p) = %s\n", + (unsigned long long) bogus_len, bogus_param2, sprintrc(rc)); + + bogus_param2[PARAM2_LEN - 1] = '\0'; + + rc = syscall(__NR_init_module, NULL, bogus_len, bogus_param2); + saved_errno = errno; + + printf("init_module(NULL, %llu, \"", (unsigned long long) bogus_len); + print_str(PARAM2_BASE, PARAM2_LEN - 1, true); + + saved_errno = errno; + printf("\") = %s\n", sprintrc(rc)); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_init_module"); + +#endif diff --git a/tests/init_module.test b/tests/init_module.test new file mode 100755 index 0000000..2c507e2 --- /dev/null +++ b/tests/init_module.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check decoding of init_module syscall. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a1 -- 1.7.10.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel