xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/privs/tst.procpriv.ksh (revision b0f673c4626e4cb1db7785287eaeed2731dfefe8)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24#
25
26ppriv -s A=basic,dtrace_proc,dtrace_user $$
27
28#
29# When we have dtrace_proc (but lack dtrace_kernel), we expect to be able to
30# read certain curpsinfo/curlwpsinfo/curcpu fields even though they require
31# reading in-kernel state.  However, there are other fields in these translated
32# structures that we know we shouldn't be able to read, as they require reading
33# in-kernel state that we cannot read with only dtrace_proc.  Finally, there
34# are a few fields that we may or may not be able to read depending on the
35# specifics of context.  This test therefore asserts that we can read what we
36# think we should be able to, that we can't read what we think we shouldn't be
37# able to, and (for purposes of completeness) that we are indifferent about
38# what we cannot assert one way or the other.
39#
40/usr/sbin/dtrace -q -Cs /dev/stdin <<EOF
41
42#define CANREAD(what, field) \
43    BEGIN { errmsg = "can't read field from what"; printf("field: "); \
44	trace(what->field); printf("\n"); }
45
46#define CANTREAD(what, field) \
47    BEGIN { errmsg = ""; trace(what->field); \
48	printf("\nable to successfully read field from what!"); exit(1); }
49
50#define MIGHTREAD(what, field) \
51    BEGIN { errmsg = ""; printf("field: "); trace(what->field); printf("\n"); }
52
53#define CANREADVAR(vname) \
54    BEGIN { errmsg = "can't read vname"; printf("vname: "); \
55	trace(vname); printf("\n"); }
56
57#define CANTREADVAR(vname) \
58    BEGIN { errmsg = ""; trace(vname); \
59	printf("\nable to successfully read vname!"); exit(1); }
60
61#define MIGHTREADVAR(vname) \
62    BEGIN { errmsg = ""; printf("vname: "); trace(vname); printf("\n"); }
63
64CANREAD(curpsinfo, pr_pid)
65CANREAD(curpsinfo, pr_nlwp)
66CANREAD(curpsinfo, pr_ppid)
67CANREAD(curpsinfo, pr_uid)
68CANREAD(curpsinfo, pr_euid)
69CANREAD(curpsinfo, pr_gid)
70CANREAD(curpsinfo, pr_egid)
71CANREAD(curpsinfo, pr_addr)
72CANREAD(curpsinfo, pr_start)
73CANREAD(curpsinfo, pr_fname)
74CANREAD(curpsinfo, pr_psargs)
75CANREAD(curpsinfo, pr_argc)
76CANREAD(curpsinfo, pr_argv)
77CANREAD(curpsinfo, pr_envp)
78CANREAD(curpsinfo, pr_dmodel)
79
80/*
81 * If our p_pgidp points to the same pid structure as our p_pidp, we will
82 * be able to read pr_pgid -- but we won't if not.
83 */
84MIGHTREAD(curpsinfo, pr_pgid)
85
86CANTREAD(curpsinfo, pr_sid)
87CANTREAD(curpsinfo, pr_ttydev)
88CANTREAD(curpsinfo, pr_projid)
89CANTREAD(curpsinfo, pr_zoneid)
90CANTREAD(curpsinfo, pr_contract)
91
92CANREAD(curlwpsinfo, pr_flag)
93CANREAD(curlwpsinfo, pr_lwpid)
94CANREAD(curlwpsinfo, pr_addr)
95CANREAD(curlwpsinfo, pr_wchan)
96CANREAD(curlwpsinfo, pr_stype)
97CANREAD(curlwpsinfo, pr_state)
98CANREAD(curlwpsinfo, pr_sname)
99CANREAD(curlwpsinfo, pr_syscall)
100CANREAD(curlwpsinfo, pr_pri)
101CANREAD(curlwpsinfo, pr_onpro)
102CANREAD(curlwpsinfo, pr_bindpro)
103CANREAD(curlwpsinfo, pr_bindpset)
104
105CANTREAD(curlwpsinfo, pr_clname)
106CANTREAD(curlwpsinfo, pr_lgrp)
107
108CANREAD(curcpu, cpu_id)
109
110CANTREAD(curcpu, cpu_pset)
111CANTREAD(curcpu, cpu_chip)
112CANTREAD(curcpu, cpu_lgrp)
113CANTREAD(curcpu, cpu_info)
114
115/*
116 * We cannot assert one thing or another about the variable "root":  for those
117 * with only dtrace_proc, it will be readable in the global but not readable in
118 * the non-global.
119 */
120MIGHTREADVAR(root)
121
122CANREADVAR(cpu)
123CANTREADVAR(pset)
124CANTREADVAR(cwd)
125CANTREADVAR(chip)
126CANTREADVAR(lgrp)
127
128BEGIN
129{
130	exit(0);
131}
132
133ERROR
134/errmsg != ""/
135{
136	printf("fatal error: %s", errmsg);
137	exit(1);
138}
139