Print this page
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libproc/common/Putil.c
+++ new/usr/src/lib/libproc/common/Putil.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26 /*
27 27 * Copyright (c) 2013 by Delphix. All rights reserved.
28 28 */
29 29
30 30 #include <limits.h>
31 31 #include <string.h>
32 32 #include <stdarg.h>
33 33 #include <stdio.h>
34 34 #include <errno.h>
35 35
36 36 #include "Pcontrol.h"
37 37 #include "Putil.h"
38 38
39 39 /*
40 40 * Place the new element on the list prior to the existing element.
41 41 */
42 42 void
43 43 list_link(void *new, void *existing)
44 44 {
45 45 plist_t *p = new;
46 46 plist_t *q = existing;
47 47
48 48 if (q) {
49 49 p->list_forw = q;
50 50 p->list_back = q->list_back;
51 51 q->list_back->list_forw = p;
52 52 q->list_back = p;
53 53 } else {
54 54 p->list_forw = p->list_back = p;
55 55 }
56 56 }
57 57
58 58 /*
59 59 * Unchain the specified element from a list.
60 60 */
61 61 void
62 62 list_unlink(void *old)
63 63 {
64 64 plist_t *p = old;
65 65
66 66 if (p->list_forw != p) {
67 67 p->list_back->list_forw = p->list_forw;
68 68 p->list_forw->list_back = p->list_back;
69 69 }
70 70 p->list_forw = p->list_back = p;
71 71 }
72 72
73 73 /*
74 74 * Routines to manipulate sigset_t, fltset_t, or sysset_t. These routines
75 75 * are provided as equivalents for the <sys/procfs.h> macros prfillset,
76 76 * premptyset, praddset, and prdelset. These functions are preferable
77 77 * because they are not macros which rely on using sizeof (*sp), and thus
78 78 * can be used to create common code to manipulate event sets. The set
79 79 * size must be passed explicitly, e.g. : prset_fill(&set, sizeof (set));
80 80 */
81 81 void
82 82 prset_fill(void *sp, size_t size)
83 83 {
84 84 size_t i = size / sizeof (uint32_t);
85 85
86 86 while (i != 0)
87 87 ((uint32_t *)sp)[--i] = (uint32_t)0xFFFFFFFF;
88 88 }
89 89
90 90 void
91 91 prset_empty(void *sp, size_t size)
92 92 {
93 93 size_t i = size / sizeof (uint32_t);
94 94
95 95 while (i != 0)
96 96 ((uint32_t *)sp)[--i] = (uint32_t)0;
97 97 }
98 98
99 99 void
100 100 prset_add(void *sp, size_t size, uint_t flag)
101 101 {
102 102 if (flag - 1 < 32 * size / sizeof (uint32_t))
103 103 ((uint32_t *)sp)[(flag - 1) / 32] |= 1U << ((flag - 1) % 32);
104 104 }
105 105
106 106 void
107 107 prset_del(void *sp, size_t size, uint_t flag)
108 108 {
109 109 if (flag - 1 < 32 * size / sizeof (uint32_t))
110 110 ((uint32_t *)sp)[(flag - 1) / 32] &= ~(1U << ((flag - 1) % 32));
111 111 }
112 112
113 113 int
114 114 prset_ismember(void *sp, size_t size, uint_t flag)
115 115 {
116 116 return ((flag - 1 < 32 * size / sizeof (uint32_t)) &&
117 117 (((uint32_t *)sp)[(flag - 1) / 32] & (1U << ((flag - 1) % 32))));
118 118 }
119 119
120 120 /*
121 121 * If _libproc_debug is set, printf the debug message to stderr
122 122 * with an appropriate prefix.
123 123 */
124 124 /*PRINTFLIKE1*/
125 125 void
126 126 dprintf(const char *format, ...)
127 127 {
128 128 if (_libproc_debug) {
129 129 va_list alist;
130 130
131 131 va_start(alist, format);
132 132 (void) fputs("libproc DEBUG: ", stderr);
133 133 (void) vfprintf(stderr, format, alist);
134 134 va_end(alist);
135 135 }
136 136 }
137 137
138 138 /*
139 139 * Printf-style error reporting function. This is used to supplement the error
140 140 * return codes from various libproc functions with additional text. Since we
141 141 * are a library, and should not be spewing messages to stderr, we provide a
142 142 * default version of this function that does nothing, but by calling this
143 143 * function we allow the client program to define its own version of the
144 144 * function that will interpose on our empty default. This may be useful for
145 145 * clients that wish to display such messages to the user.
146 146 */
147 147 /*ARGSUSED*/
148 148 /*PRINTFLIKE2*/
149 149 void
150 150 Perror_printf(struct ps_prochandle *P, const char *format, ...)
151 151 {
152 152 /* nothing to do here */
153 153 }
154 154
155 155 /*
156 156 * Default operations.
157 157 */
158 158 static ssize_t
159 159 Pdefault_ssizet()
160 160 {
161 161 return (-1);
162 162 }
163 163
164 164 static int
165 165 Pdefault_int()
166 166 {
167 167 return (-1);
168 168 }
169 169
170 170 static void
171 171 Pdefault_void()
172 172 {
173 173 }
174 174
175 175 static void *
176 176 Pdefault_voidp()
177 177 {
178 178 return (NULL);
179 179 }
180 180
181 181 static const ps_ops_t P_default_ops = {
182 182 .pop_pread = (pop_pread_t)Pdefault_ssizet,
183 183 .pop_pwrite = (pop_pwrite_t)Pdefault_ssizet,
184 184 .pop_read_maps = (pop_read_maps_t)Pdefault_int,
185 185 .pop_read_aux = (pop_read_aux_t)Pdefault_void,
186 186 .pop_cred = (pop_cred_t)Pdefault_int,
↓ open down ↓ |
186 lines elided |
↑ open up ↑ |
187 187 .pop_priv = (pop_priv_t)Pdefault_int,
188 188 .pop_psinfo = (pop_psinfo_t)Pdefault_voidp,
189 189 .pop_status = (pop_status_t)Pdefault_void,
190 190 .pop_lstatus = (pop_lstatus_t)Pdefault_voidp,
191 191 .pop_lpsinfo = (pop_lpsinfo_t)Pdefault_voidp,
192 192 .pop_fini = (pop_fini_t)Pdefault_void,
193 193 .pop_platform = (pop_platform_t)Pdefault_voidp,
194 194 .pop_uname = (pop_uname_t)Pdefault_int,
195 195 .pop_zonename = (pop_zonename_t)Pdefault_voidp,
196 196 .pop_execname = (pop_execname_t)Pdefault_voidp,
197 + .pop_secflags = (pop_secflags_t)Pdefault_int,
197 198 #if defined(__i386) || defined(__amd64)
198 199 .pop_ldt = (pop_ldt_t)Pdefault_int
199 200 #endif
200 201 };
201 202
202 203 /*
203 204 * Initialize the destination ops vector with functions from the source.
204 205 * Functions which are NULL in the source ops vector are set to corresponding
205 206 * default function in the destination vector.
206 207 */
207 208 void
208 209 Pinit_ops(ps_ops_t *dst, const ps_ops_t *src)
209 210 {
210 211 *dst = P_default_ops;
211 212
212 213 if (src->pop_pread != NULL)
213 214 dst->pop_pread = src->pop_pread;
214 215 if (src->pop_pwrite != NULL)
215 216 dst->pop_pwrite = src->pop_pwrite;
216 217 if (src->pop_read_maps != NULL)
217 218 dst->pop_read_maps = src->pop_read_maps;
218 219 if (src->pop_read_aux != NULL)
219 220 dst->pop_read_aux = src->pop_read_aux;
220 221 if (src->pop_cred != NULL)
221 222 dst->pop_cred = src->pop_cred;
222 223 if (src->pop_priv != NULL)
223 224 dst->pop_priv = src->pop_priv;
224 225 if (src->pop_psinfo != NULL)
225 226 dst->pop_psinfo = src->pop_psinfo;
226 227 if (src->pop_status != NULL)
227 228 dst->pop_status = src->pop_status;
228 229 if (src->pop_lstatus != NULL)
229 230 dst->pop_lstatus = src->pop_lstatus;
230 231 if (src->pop_lpsinfo != NULL)
231 232 dst->pop_lpsinfo = src->pop_lpsinfo;
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
232 233 if (src->pop_fini != NULL)
233 234 dst->pop_fini = src->pop_fini;
234 235 if (src->pop_platform != NULL)
235 236 dst->pop_platform = src->pop_platform;
236 237 if (src->pop_uname != NULL)
237 238 dst->pop_uname = src->pop_uname;
238 239 if (src->pop_zonename != NULL)
239 240 dst->pop_zonename = src->pop_zonename;
240 241 if (src->pop_execname != NULL)
241 242 dst->pop_execname = src->pop_execname;
243 + if (src->pop_secflags != NULL)
244 + dst->pop_secflags = src->pop_secflags;
242 245 #if defined(__i386) || defined(__amd64)
243 246 if (src->pop_ldt != NULL)
244 247 dst->pop_ldt = src->pop_ldt;
245 248 #endif
246 249 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX