]> granicus.if.org Git - strace/blob - tests/finit_module.c
tests: use scno.h in finit_module, kcmp, renameat2 tests
[strace] / tests / finit_module.c
1 /*
2  * Check decoding of finit_module syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "tests.h"
31
32 #include <asm/unistd.h>
33 #include "scno.h"
34
35 #if defined(__NR_finit_module)
36
37 # include <stdio.h>
38 # include <unistd.h>
39
40 # include "init_delete_module.h"
41
42 int
43 main(void)
44 {
45         static const kernel_ulong_t bogus_fd =
46                 (kernel_ulong_t) 0xdeb0d1edbeeff00dULL;
47
48         static const struct {
49                 kernel_ulong_t val;
50                 const char *str;
51         } flags[] = {
52                 { ARG_STR(0) },
53                 { (kernel_ulong_t) 0xffffffff00000002ULL,
54                         "MODULE_INIT_IGNORE_VERMAGIC" },
55                 { (kernel_ulong_t) 0xbadc0deddefaced0ULL,
56                         "0xdefaced0 /* MODULE_INIT_??? */" },
57                 { (kernel_ulong_t) 0xfacef157dec0ded1ULL,
58                         "MODULE_INIT_IGNORE_MODVERSIONS|0xdec0ded0" },
59                 { -1LL, "MODULE_INIT_IGNORE_MODVERSIONS|"
60                         "MODULE_INIT_IGNORE_VERMAGIC|0xfffffffc" },
61         };
62
63         long rc;
64         char *bogus_param1 = tail_alloc(PARAM1_LEN);
65         char *bogus_param2 = tail_alloc(PARAM2_LEN);
66         const char *errstr;
67
68         fill_memory_ex(bogus_param1, PARAM1_LEN, PARAM1_BASE, PARAM1_LEN);
69         fill_memory_ex(bogus_param2, PARAM2_LEN, PARAM2_BASE, PARAM2_LEN);
70
71         rc = syscall(__NR_finit_module, bogus_zero, NULL, bogus_zero);
72         printf("finit_module(0, NULL, 0) = %s\n", sprintrc(rc));
73
74         rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[0].val);
75         errstr = sprintrc(rc);
76
77         printf("finit_module(%d, \"", (int) bogus_fd);
78         print_str(PARAM1_BASE, MAX_STRLEN, false);
79         printf("\"..., %s) = %s\n", flags[0].str, errstr);
80
81         bogus_param1[PARAM1_LEN - 1] = '\0';
82
83         rc = syscall(__NR_finit_module, bogus_fd, bogus_param1, flags[1].val);
84         errstr = sprintrc(rc);
85
86         printf("finit_module(%d, \"", (int) bogus_fd);
87         print_str(PARAM1_BASE, MAX_STRLEN, false);
88         printf("\", %s) = %s\n", flags[1].str, errstr);
89
90         rc = syscall(__NR_finit_module, bogus_fd, bogus_param2 + PARAM2_LEN,
91                 flags[2].val);
92         printf("finit_module(%d, %p, %s) = %s\n",
93                (int) bogus_fd, bogus_param2 + PARAM2_LEN, flags[2].str,
94                sprintrc(rc));
95
96         rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[3].val);
97         printf("finit_module(%d, %p, %s) = %s\n",
98                (int) bogus_fd, bogus_param2, flags[3].str, sprintrc(rc));
99
100         bogus_param2[PARAM2_LEN - 1] = '\0';
101
102         rc = syscall(__NR_finit_module, bogus_fd, bogus_param2, flags[4].val);
103         errstr = sprintrc(rc);
104
105         printf("finit_module(%d, \"", (int) bogus_fd);
106         print_str(PARAM2_BASE, PARAM2_LEN - 1, true);
107         printf("\", %s) = %s\n", flags[4].str, errstr);
108
109         puts("+++ exited with 0 +++");
110
111         return 0;
112 }
113
114 #else
115
116 SKIP_MAIN_UNDEFINED("__NR_finit_module");
117
118 #endif