2 * Check decoding of prctl operations which use arg2 as pointer to an integer
3 * value: PR_GET_CHILD_SUBREAPER, PR_GET_ENDIAN, PR_GET_FPEMU, and PR_GET_FPEXC.
5 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
6 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <asm/unistd.h>
35 #if defined __NR_prctl
40 # include <linux/prctl.h>
42 static const char *errstr;
45 prctl(kernel_ulong_t arg1, kernel_ulong_t arg2)
47 static const kernel_ulong_t bogus_arg =
48 (kernel_ulong_t) 0xdeadbeefbadc0dedULL;
49 long rc = syscall(__NR_prctl, arg1, arg2, bogus_arg);
50 errstr = sprintrc(rc);
57 static const kernel_ulong_t bogus_addr1 =
58 (kernel_ulong_t) 0x1e55c0de00000000ULL;
59 static const kernel_ulong_t bogus_addr2 =
60 (kernel_ulong_t) 0xfffffffffffffffdULL;
61 static const kernel_ulong_t bogus_op_bits =
62 (kernel_ulong_t) 0xbadc0ded00000000ULL;
67 { 37, "PR_GET_CHILD_SUBREAPER" },
68 { 19, "PR_GET_ENDIAN" },
69 { 9, "PR_GET_FPEMU" },
70 { 11, "PR_GET_FPEXC" },
73 unsigned int *ptr = tail_alloc(sizeof(*ptr));
77 for (i = 0; i < ARRAY_SIZE(options); ++i) {
78 prctl(options[i].val | bogus_op_bits, 0);
79 printf("prctl(%s, NULL) = %s\n", options[i].str, errstr);
82 prctl(options[i].val | bogus_op_bits, bogus_addr1);
83 printf("prctl(%s, %#llx) = %s\n", options[i].str,
84 (unsigned long long) bogus_addr1, errstr);
87 prctl(options[i].val | bogus_op_bits, bogus_addr2);
88 printf("prctl(%s, %#llx) = %s\n", options[i].str,
89 (unsigned long long) bogus_addr2, errstr);
91 prctl(options[i].val | bogus_op_bits, (uintptr_t) (ptr + 1));
92 printf("prctl(%s, %p) = %s\n", options[i].str,
95 rc = prctl(options[i].val | bogus_op_bits, (uintptr_t) ptr);
97 printf("prctl(%s, [%u]) = %s\n",
98 options[i].str, *ptr, errstr);
100 printf("prctl(%s, %p) = %s\n",
101 options[i].str, ptr, errstr);
104 if (F8ILL_KULONG_SUPPORTED) {
105 kernel_ulong_t bogus_addr3 = f8ill_ptr_to_kulong(ptr);
106 prctl(options[i].val | bogus_op_bits, bogus_addr3);
107 printf("prctl(%s, %#llx) = %s\n", options[i].str,
108 (unsigned long long) bogus_addr3, errstr);
112 puts("+++ exited with 0 +++");
118 SKIP_MAIN_UNDEFINED("__NR_prctl")