• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Check decoding of prctl operations without arguments and return code parsing:
3  * PR_GET_KEEPCAPS, PR_GET_SECCOMP, PR_GET_TIMERSLACK, PR_GET_TIMING,
4  * PR_TASK_PERF_EVENTS_DISABLE, and PR_TASK_PERF_EVENTS_ENABLE.
5  *
6  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
7  * Copyright (c) 2016-2017 The strace developers.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "tests.h"
34 #include <asm/unistd.h>
35 
36 #if defined __NR_prctl
37 
38 # include <stdio.h>
39 # include <unistd.h>
40 # include <linux/prctl.h>
41 
42 int
main(void)43 main(void)
44 {
45 	static const kernel_ulong_t bogus_op_bits =
46 		(kernel_ulong_t) 0xbadc0ded00000000ULL;
47 	static const kernel_ulong_t bogus_arg =
48 		(kernel_ulong_t) 0xfacefeeddeadbeefULL;
49 	static const struct {
50 		kernel_ulong_t val;
51 		const char *str;
52 	} options[] = {
53 		{  7, "PR_GET_KEEPCAPS" },
54 		{ 13, "PR_GET_TIMING" },
55 		{ 21, "PR_GET_SECCOMP" },
56 		{ 30, "PR_GET_TIMERSLACK" },
57 		{ 31, "PR_TASK_PERF_EVENTS_DISABLE" },
58 		{ 32, "PR_TASK_PERF_EVENTS_ENABLE" },
59 	};
60 
61 	TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, ptr);
62 	unsigned int i;
63 
64 	for (i = 0; i < ARRAY_SIZE(options); i++) {
65 		long rc = syscall(__NR_prctl, options[i].val | bogus_op_bits,
66 				  bogus_arg);
67 		printf("prctl(%s) = %s\n", options[i].str, sprintrc(rc));
68 	}
69 
70 	puts("+++ exited with 0 +++");
71 	return 0;
72 }
73 
74 #else
75 
76 SKIP_MAIN_UNDEFINED("__NR_prctl")
77 
78 #endif
79