]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/privs/tst.kpriv.ksh
MFC r258903,r264487,r271699,r288415:
[FreeBSD/stable/10.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / privs / tst.kpriv.ksh
1 #
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
6 #
7 # A full copy of the text of the CDDL should have accompanied this
8 # source.  A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
10 #
11
12 #
13 # Copyright (c) 2015, Joyent, Inc. All rights reserved.
14 #
15
16 err=/tmp/err.$$
17
18 ppriv -s A=basic,dtrace_user $$
19
20 #
21 # When we lack dtrace_kernel, we expect to not be able to get at kernel memory
22 # via any subroutine or other vector.
23 #
24 #       trace(func((void *)&\`utsname)); }
25 /usr/sbin/dtrace -wq -Cs /dev/stdin 2> $err <<EOF
26
27 #define FAIL \
28         printf("able to read kernel memory via %s!\n", badsubr); \
29         exit(2);
30
31 #define CANTREAD1(func) \
32     BEGIN { badsubr = "func()"; func((void *)&\`utsname); FAIL }
33
34 #define CANTREAD2(func, arg1) \
35     BEGIN { badsubr = "func()"; func((void *)&\`utsname, arg1); FAIL }
36
37 #define CANTREAD2ARG1(func, arg0) \
38     BEGIN { badsubr = "func() (arg1)"; func(arg0, (void *)&\`utsname); FAIL }
39
40 #define CANTREAD3(func, arg1, arg2) \
41     BEGIN { badsubr = "func()"; func((void *)&\`utsname, arg1, arg2); FAIL }
42
43 CANTREAD1(mutex_owned)
44 CANTREAD1(mutex_owner)
45 CANTREAD1(mutex_type_adaptive)
46 CANTREAD1(mutex_type_spin)
47 CANTREAD1(rw_read_held)
48 CANTREAD1(rw_write_held)
49 CANTREAD1(rw_iswriter)
50 CANTREAD3(bcopy, alloca(1), 1)
51 CANTREAD1(msgsize)
52 CANTREAD1(msgdsize)
53 CANTREAD1(strlen)
54 CANTREAD2(strchr, '!')
55 CANTREAD2(strrchr, '!')
56 CANTREAD2(strstr, "doogle")
57 CANTREAD2ARG1(strstr, "doogle")
58 CANTREAD2(index, "bagnoogle")
59 CANTREAD2ARG1(index, "bagnoogle")
60 CANTREAD2(rindex, "bagnoogle")
61 CANTREAD2ARG1(rindex, "bagnoogle")
62 CANTREAD2(strtok, "doogle")
63 CANTREAD2ARG1(strtok, "doogle")
64 CANTREAD2(json, "doogle")
65 CANTREAD2ARG1(json, "doogle")
66 CANTREAD1(toupper)
67 CANTREAD1(tolower)
68 CANTREAD2(ddi_pathname, 1)
69 CANTREAD2(strjoin, "doogle")
70 CANTREAD2ARG1(strjoin, "doogle")
71 CANTREAD1(strtoll)
72 CANTREAD1(dirname)
73 CANTREAD1(basename)
74 CANTREAD1(cleanpath)
75
76 #if defined(__amd64)
77 CANTREAD3(copyout, uregs[R_R9], 1)
78 CANTREAD3(copyoutstr, uregs[R_R9], 1)
79 #else
80 #if defined(__i386)
81 CANTREAD3(copyout, uregs[R_ESP], 1)
82 CANTREAD3(copyoutstr, uregs[R_ESP], 1)
83 #endif
84 #endif
85
86 BEGIN
87 {
88         exit(0);
89 }
90
91 ERROR
92 /arg4 != DTRACEFLT_KPRIV/
93 {
94         printf("bad error code via %s (expected %d, found %d)\n",
95             badsubr, DTRACEFLT_KPRIV, arg4);
96         exit(3);
97 }
98
99 ERROR
100 /arg4 == DTRACEFLT_KPRIV/
101 {
102         printf("illegal kernel access properly prevented from %s\n", badsubr);
103 }
104 EOF
105
106 status=$?
107
108 if [[ $status -eq 1 ]]; then
109         cat $err
110 fi
111
112 exit $status