linux_mib.c (8fa0b743820f61c661ba5f3ea0e3be0dc137910e) linux_mib.c (19e252baebe7a7466b33c27560420b7d95fe294d)
1/*-
2 * Copyright (c) 1999 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
1/*-
2 * Copyright (c) 1999 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include "opt_compat.h"
33#include "opt_kdtrace.h"
34
32#include <sys/param.h>
33#include <sys/kernel.h>
35#include <sys/param.h>
36#include <sys/kernel.h>
37#include <sys/sdt.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
36#include <sys/proc.h>
37#include <sys/malloc.h>
38#include <sys/mount.h>
39#include <sys/jail.h>
40#include <sys/lock.h>
41#include <sys/mutex.h>
42#include <sys/sx.h>
43
38#include <sys/systm.h>
39#include <sys/sysctl.h>
40#include <sys/proc.h>
41#include <sys/malloc.h>
42#include <sys/mount.h>
43#include <sys/jail.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/sx.h>
47
44#include "opt_compat.h"
45
46#ifdef COMPAT_LINUX32
47#include <machine/../linux32/linux.h>
48#else
49#include <machine/../linux/linux.h>
50#endif
48#ifdef COMPAT_LINUX32
49#include <machine/../linux32/linux.h>
50#else
51#include <machine/../linux/linux.h>
52#endif
53#include <compat/linux/linux_dtrace.h>
51#include <compat/linux/linux_mib.h>
52
54#include <compat/linux/linux_mib.h>
55
56/* DTrace init */
57LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
58
59/**
60 * DTrace probes in this module.
61 */
62LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osname, entry);
63LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, sysctl_string_error, "int");
64LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osname, return, "int");
65
66LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_osrelease, entry);
67LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, sysctl_string_error, "int");
68LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_osrelease, return, "int");
69LIN_SDT_PROBE_DEFINE0(mib, linux_sysctl_oss_version, entry);
70LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, sysctl_string_error,
71 "int");
72LIN_SDT_PROBE_DEFINE1(mib, linux_sysctl_oss_version, return, "int");
73LIN_SDT_PROBE_DEFINE2(mib, linux_map_osrel, entry, "char *", "int *");
74LIN_SDT_PROBE_DEFINE1(mib, linux_map_osrel, return, "int");
75LIN_SDT_PROBE_DEFINE2(mib, linux_get_prison, entry, "struct prison *",
76 "struct prison **");
77LIN_SDT_PROBE_DEFINE1(mib, linux_get_prison, return, "struct linux_prison *");
78LIN_SDT_PROBE_DEFINE2(mib, linux_alloc_prison, entry, "struct prison *",
79 "struct linux_prison **");
80LIN_SDT_PROBE_DEFINE1(mib, linux_alloc_prison, return, "int");
81LIN_SDT_PROBE_DEFINE2(mib, linux_prison_create, entry, "void *", "void *");
82LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, vfs_copyopt_error, "int");
83LIN_SDT_PROBE_DEFINE1(mib, linux_prison_create, return, "int");
84LIN_SDT_PROBE_DEFINE2(mib, linux_prison_check, entry, "void *", "void *");
85LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_copyopt_error, "int");
86LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, vfs_getopt_error, "int");
87LIN_SDT_PROBE_DEFINE1(mib, linux_prison_check, return, "int");
88LIN_SDT_PROBE_DEFINE2(mib, linux_prison_set, entry, "void *", "void *");
89LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_copyopt_error, "int");
90LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, vfs_getopt_error, "int");
91LIN_SDT_PROBE_DEFINE1(mib, linux_prison_set, return, "int");
92LIN_SDT_PROBE_DEFINE2(mib, linux_prison_get, entry, "void *", "void *");
93LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopt_error, "int");
94LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, vfs_setopts_error, "int");
95LIN_SDT_PROBE_DEFINE1(mib, linux_prison_get, return, "int");
96LIN_SDT_PROBE_DEFINE1(mib, linux_prison_destructor, entry, "void *");
97LIN_SDT_PROBE_DEFINE0(mib, linux_prison_destructor, return);
98LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, entry);
99LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_register, return);
100LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, entry);
101LIN_SDT_PROBE_DEFINE0(mib, linux_osd_jail_deregister, return);
102LIN_SDT_PROBE_DEFINE2(mib, linux_get_osname, entry, "struct thread *",
103 "char *");
104LIN_SDT_PROBE_DEFINE0(mib, linux_get_osname, return);
105LIN_SDT_PROBE_DEFINE2(mib, linux_set_osname, entry, "struct thread *",
106 "char *");
107LIN_SDT_PROBE_DEFINE1(mib, linux_set_osname, return, "int");
108LIN_SDT_PROBE_DEFINE2(mib, linux_get_osrelease, entry, "struct thread *",
109 "char *");
110LIN_SDT_PROBE_DEFINE0(mib, linux_get_osrelease, return);
111LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, entry, "struct thread *");
112LIN_SDT_PROBE_DEFINE1(mib, linux_kernver, return, "int");
113LIN_SDT_PROBE_DEFINE2(mib, linux_set_osrelease, entry, "struct thread *",
114 "char *");
115LIN_SDT_PROBE_DEFINE1(mib, linux_set_osrelease, return, "int");
116LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, entry, "struct thread *");
117LIN_SDT_PROBE_DEFINE1(mib, linux_get_oss_version, return, "int");
118
119LIN_SDT_PROBE_DEFINE2(mib, linux_set_oss_version, entry, "struct thread *",
120 "int");
121LIN_SDT_PROBE_DEFINE1(mib, linux_set_oss_version, return, "int");
122
53struct linux_prison {
54 char pr_osname[LINUX_MAX_UTSNAME];
55 char pr_osrelease[LINUX_MAX_UTSNAME];
56 int pr_oss_version;
57 int pr_osrel;
58};
59
60static struct linux_prison lprison0 = {

--- 13 unchanged lines hidden (view full) ---

74static int linux_set_oss_version(struct thread *td, int oss_version);
75
76static int
77linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
78{
79 char osname[LINUX_MAX_UTSNAME];
80 int error;
81
123struct linux_prison {
124 char pr_osname[LINUX_MAX_UTSNAME];
125 char pr_osrelease[LINUX_MAX_UTSNAME];
126 int pr_oss_version;
127 int pr_osrel;
128};
129
130static struct linux_prison lprison0 = {

--- 13 unchanged lines hidden (view full) ---

144static int linux_set_oss_version(struct thread *td, int oss_version);
145
146static int
147linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
148{
149 char osname[LINUX_MAX_UTSNAME];
150 int error;
151
152 LIN_SDT_PROBE0(mib, linux_sysctl_osname, entry);
153
82 linux_get_osname(req->td, osname);
83 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
154 linux_get_osname(req->td, osname);
155 error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
84 if (error || req->newptr == NULL)
156 if (error != 0 || req->newptr == NULL) {
157 LIN_SDT_PROBE1(mib, linux_sysctl_osname, sysctl_string_error,
158 error);
159 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
85 return (error);
160 return (error);
161 }
86 error = linux_set_osname(req->td, osname);
162 error = linux_set_osname(req->td, osname);
163
164 LIN_SDT_PROBE1(mib, linux_sysctl_osname, return, error);
87 return (error);
88}
89
90SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
91 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
92 0, 0, linux_sysctl_osname, "A",
93 "Linux kernel OS name");
94
95static int
96linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
97{
98 char osrelease[LINUX_MAX_UTSNAME];
99 int error;
100
165 return (error);
166}
167
168SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
169 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
170 0, 0, linux_sysctl_osname, "A",
171 "Linux kernel OS name");
172
173static int
174linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
175{
176 char osrelease[LINUX_MAX_UTSNAME];
177 int error;
178
179 LIN_SDT_PROBE0(mib, linux_sysctl_osrelease, entry);
180
101 linux_get_osrelease(req->td, osrelease);
102 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
181 linux_get_osrelease(req->td, osrelease);
182 error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
103 if (error || req->newptr == NULL)
183 if (error != 0 || req->newptr == NULL) {
184 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, sysctl_string_error,
185 error);
186 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
104 return (error);
187 return (error);
188 }
105 error = linux_set_osrelease(req->td, osrelease);
189 error = linux_set_osrelease(req->td, osrelease);
190
191 LIN_SDT_PROBE1(mib, linux_sysctl_osrelease, return, error);
106 return (error);
107}
108
109SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
110 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
111 0, 0, linux_sysctl_osrelease, "A",
112 "Linux kernel OS release");
113
114static int
115linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
116{
117 int oss_version;
118 int error;
119
192 return (error);
193}
194
195SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
196 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
197 0, 0, linux_sysctl_osrelease, "A",
198 "Linux kernel OS release");
199
200static int
201linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
202{
203 int oss_version;
204 int error;
205
206 LIN_SDT_PROBE0(mib, linux_sysctl_oss_version, entry);
207
120 oss_version = linux_get_oss_version(req->td);
121 error = sysctl_handle_int(oidp, &oss_version, 0, req);
208 oss_version = linux_get_oss_version(req->td);
209 error = sysctl_handle_int(oidp, &oss_version, 0, req);
122 if (error || req->newptr == NULL)
210 if (error != 0 || req->newptr == NULL) {
211 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version,
212 sysctl_string_error, error);
213 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
123 return (error);
214 return (error);
215 }
124 error = linux_set_oss_version(req->td, oss_version);
216 error = linux_set_oss_version(req->td, oss_version);
217
218 LIN_SDT_PROBE1(mib, linux_sysctl_oss_version, return, error);
125 return (error);
126}
127
128SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
129 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
130 0, 0, linux_sysctl_oss_version, "I",
131 "Linux OSS version");
132
133/*
134 * Map the osrelease into integer
135 */
136static int
137linux_map_osrel(char *osrelease, int *osrel)
138{
139 char *sep, *eosrelease;
140 int len, v0, v1, v2, v;
141
219 return (error);
220}
221
222SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
223 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
224 0, 0, linux_sysctl_oss_version, "I",
225 "Linux OSS version");
226
227/*
228 * Map the osrelease into integer
229 */
230static int
231linux_map_osrel(char *osrelease, int *osrel)
232{
233 char *sep, *eosrelease;
234 int len, v0, v1, v2, v;
235
236 LIN_SDT_PROBE2(mib, linux_map_osrel, entry, osrelease, osrel);
237
142 len = strlen(osrelease);
143 eosrelease = osrelease + len;
144 v0 = strtol(osrelease, &sep, 10);
238 len = strlen(osrelease);
239 eosrelease = osrelease + len;
240 v0 = strtol(osrelease, &sep, 10);
145 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.')
241 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
242 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
146 return (EINVAL);
243 return (EINVAL);
244 }
147 osrelease = sep + 1;
148 v1 = strtol(osrelease, &sep, 10);
245 osrelease = sep + 1;
246 v1 = strtol(osrelease, &sep, 10);
149 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.')
247 if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') {
248 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
150 return (EINVAL);
249 return (EINVAL);
250 }
151 osrelease = sep + 1;
152 v2 = strtol(osrelease, &sep, 10);
251 osrelease = sep + 1;
252 v2 = strtol(osrelease, &sep, 10);
153 if (osrelease == sep || sep != eosrelease)
253 if (osrelease == sep || sep != eosrelease) {
254 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
154 return (EINVAL);
255 return (EINVAL);
256 }
155
156 v = v0 * 1000000 + v1 * 1000 + v2;
257
258 v = v0 * 1000000 + v1 * 1000 + v2;
157 if (v < 1000000)
259 if (v < 1000000) {
260 LIN_SDT_PROBE1(mib, linux_map_osrel, return, EINVAL);
158 return (EINVAL);
261 return (EINVAL);
262 }
159
160 *osrel = v;
263
264 *osrel = v;
265
266 LIN_SDT_PROBE1(mib, linux_map_osrel, return, 0);
161 return (0);
162}
163
164/*
165 * Find a prison with Linux info.
166 * Return the Linux info and the (locked) prison.
167 */
168static struct linux_prison *
169linux_find_prison(struct prison *spr, struct prison **prp)
170{
171 struct prison *pr;
172 struct linux_prison *lpr;
173
267 return (0);
268}
269
270/*
271 * Find a prison with Linux info.
272 * Return the Linux info and the (locked) prison.
273 */
274static struct linux_prison *
275linux_find_prison(struct prison *spr, struct prison **prp)
276{
277 struct prison *pr;
278 struct linux_prison *lpr;
279
280 LIN_SDT_PROBE2(mib, linux_get_prison, entry, spr, prp);
281
174 if (!linux_osd_jail_slot)
175 /* In case osd_register failed. */
176 spr = &prison0;
177 for (pr = spr;; pr = pr->pr_parent) {
178 mtx_lock(&pr->pr_mtx);
179 lpr = (pr == &prison0)
180 ? &lprison0
181 : osd_jail_get(pr, linux_osd_jail_slot);
182 if (lpr != NULL)
183 break;
184 mtx_unlock(&pr->pr_mtx);
185 }
186 *prp = pr;
282 if (!linux_osd_jail_slot)
283 /* In case osd_register failed. */
284 spr = &prison0;
285 for (pr = spr;; pr = pr->pr_parent) {
286 mtx_lock(&pr->pr_mtx);
287 lpr = (pr == &prison0)
288 ? &lprison0
289 : osd_jail_get(pr, linux_osd_jail_slot);
290 if (lpr != NULL)
291 break;
292 mtx_unlock(&pr->pr_mtx);
293 }
294 *prp = pr;
295
296 LIN_SDT_PROBE1(mib, linux_get_prison, return, lpr);
187 return (lpr);
188}
189
190/*
191 * Ensure a prison has its own Linux info. If lprp is non-null, point it to
192 * the Linux info and lock the prison.
193 */
194static int
195linux_alloc_prison(struct prison *pr, struct linux_prison **lprp)
196{
197 struct prison *ppr;
198 struct linux_prison *lpr, *nlpr;
199 int error;
200
297 return (lpr);
298}
299
300/*
301 * Ensure a prison has its own Linux info. If lprp is non-null, point it to
302 * the Linux info and lock the prison.
303 */
304static int
305linux_alloc_prison(struct prison *pr, struct linux_prison **lprp)
306{
307 struct prison *ppr;
308 struct linux_prison *lpr, *nlpr;
309 int error;
310
311 LIN_SDT_PROBE2(mib, linux_alloc_prison, entry, pr, lprp);
312
201 /* If this prison already has Linux info, return that. */
202 error = 0;
203 lpr = linux_find_prison(pr, &ppr);
204 if (ppr == pr)
205 goto done;
206 /*
207 * Allocate a new info record. Then check again, in case something
208 * changed during the allocation.

--- 16 unchanged lines hidden (view full) ---

225 lpr = NULL;
226 }
227 mtx_unlock(&ppr->pr_mtx);
228 done:
229 if (lprp != NULL)
230 *lprp = lpr;
231 else
232 mtx_unlock(&pr->pr_mtx);
313 /* If this prison already has Linux info, return that. */
314 error = 0;
315 lpr = linux_find_prison(pr, &ppr);
316 if (ppr == pr)
317 goto done;
318 /*
319 * Allocate a new info record. Then check again, in case something
320 * changed during the allocation.

--- 16 unchanged lines hidden (view full) ---

337 lpr = NULL;
338 }
339 mtx_unlock(&ppr->pr_mtx);
340 done:
341 if (lprp != NULL)
342 *lprp = lpr;
343 else
344 mtx_unlock(&pr->pr_mtx);
345
346 LIN_SDT_PROBE1(mib, linux_alloc_prison, return, error);
233 return (error);
234}
235
236/*
237 * Jail OSD methods for Linux prison data.
238 */
239static int
240linux_prison_create(void *obj, void *data)
241{
242 struct prison *pr = obj;
243 struct vfsoptlist *opts = data;
347 return (error);
348}
349
350/*
351 * Jail OSD methods for Linux prison data.
352 */
353static int
354linux_prison_create(void *obj, void *data)
355{
356 struct prison *pr = obj;
357 struct vfsoptlist *opts = data;
244 int jsys;
358 int jsys, error;
245
359
246 if (vfs_copyopt(opts, "linux", &jsys, sizeof(jsys)) == 0 &&
247 jsys == JAIL_SYS_INHERIT)
360 LIN_SDT_PROBE2(mib, linux_prison_create, entry, obj, data);
361
362 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
363 if (error != 0) {
364 LIN_SDT_PROBE1(mib, linux_prison_create, vfs_copyopt_error,
365 error);
366 } else if (jsys == JAIL_SYS_INHERIT) {
367 LIN_SDT_PROBE1(mib, linux_prison_create, return, 0);
248 return (0);
368 return (0);
369 }
249 /*
250 * Inherit a prison's initial values from its parent
251 * (different from JAIL_SYS_INHERIT which also inherits changes).
252 */
370 /*
371 * Inherit a prison's initial values from its parent
372 * (different from JAIL_SYS_INHERIT which also inherits changes).
373 */
253 return linux_alloc_prison(pr, NULL);
374 error = linux_alloc_prison(pr, NULL);
375
376 LIN_SDT_PROBE1(mib, linux_prison_create, return, error);
377 return (error);
254}
255
256static int
257linux_prison_check(void *obj __unused, void *data)
258{
259 struct vfsoptlist *opts = data;
260 char *osname, *osrelease;
261 int error, jsys, len, osrel, oss_version;
262
378}
379
380static int
381linux_prison_check(void *obj __unused, void *data)
382{
383 struct vfsoptlist *opts = data;
384 char *osname, *osrelease;
385 int error, jsys, len, osrel, oss_version;
386
387 LIN_SDT_PROBE2(mib, linux_prison_check, entry, obj, data);
388
263 /* Check that the parameters are correct. */
264 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
389 /* Check that the parameters are correct. */
390 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
391 if (error != 0) {
392 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error,
393 error);
394 }
265 if (error != ENOENT) {
395 if (error != ENOENT) {
266 if (error != 0)
396 if (error != 0) {
397 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
267 return (error);
398 return (error);
268 if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT)
399 }
400 if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT) {
401 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
269 return (EINVAL);
402 return (EINVAL);
403 }
270 }
271 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
404 }
405 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
406 if (error != 0) {
407 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
408 error);
409 }
272 if (error != ENOENT) {
410 if (error != ENOENT) {
273 if (error != 0)
411 if (error != 0) {
412 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
274 return (error);
413 return (error);
275 if (len == 0 || osname[len - 1] != '\0')
414 }
415 if (len == 0 || osname[len - 1] != '\0') {
416 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
276 return (EINVAL);
417 return (EINVAL);
418 }
277 if (len > LINUX_MAX_UTSNAME) {
278 vfs_opterror(opts, "linux.osname too long");
419 if (len > LINUX_MAX_UTSNAME) {
420 vfs_opterror(opts, "linux.osname too long");
421 LIN_SDT_PROBE1(mib, linux_prison_check, return,
422 ENAMETOOLONG);
279 return (ENAMETOOLONG);
280 }
281 }
282 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
423 return (ENAMETOOLONG);
424 }
425 }
426 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
427 if (error != 0) {
428 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_getopt_error,
429 error);
430 }
283 if (error != ENOENT) {
431 if (error != ENOENT) {
284 if (error != 0)
432 if (error != 0) {
433 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
285 return (error);
434 return (error);
286 if (len == 0 || osrelease[len - 1] != '\0')
435 }
436 if (len == 0 || osrelease[len - 1] != '\0') {
437 LIN_SDT_PROBE1(mib, linux_prison_check, return, EINVAL);
287 return (EINVAL);
438 return (EINVAL);
439 }
288 if (len > LINUX_MAX_UTSNAME) {
289 vfs_opterror(opts, "linux.osrelease too long");
440 if (len > LINUX_MAX_UTSNAME) {
441 vfs_opterror(opts, "linux.osrelease too long");
442 LIN_SDT_PROBE1(mib, linux_prison_check, return,
443 ENAMETOOLONG);
290 return (ENAMETOOLONG);
291 }
292 error = linux_map_osrel(osrelease, &osrel);
293 if (error != 0) {
294 vfs_opterror(opts, "linux.osrelease format error");
444 return (ENAMETOOLONG);
445 }
446 error = linux_map_osrel(osrelease, &osrel);
447 if (error != 0) {
448 vfs_opterror(opts, "linux.osrelease format error");
449 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
295 return (error);
296 }
297 }
298 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
299 sizeof(oss_version));
450 return (error);
451 }
452 }
453 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
454 sizeof(oss_version));
300 return (error == ENOENT ? 0 : error);
455 if (error != 0)
456 LIN_SDT_PROBE1(mib, linux_prison_check, vfs_copyopt_error, error);
457
458 if (error == ENOENT)
459 error = 0;
460 LIN_SDT_PROBE1(mib, linux_prison_check, return, error);
461 return (error);
301}
302
303static int
304linux_prison_set(void *obj, void *data)
305{
306 struct linux_prison *lpr;
307 struct prison *pr = obj;
308 struct vfsoptlist *opts = data;
309 char *osname, *osrelease;
310 int error, gotversion, jsys, len, oss_version;
311
462}
463
464static int
465linux_prison_set(void *obj, void *data)
466{
467 struct linux_prison *lpr;
468 struct prison *pr = obj;
469 struct vfsoptlist *opts = data;
470 char *osname, *osrelease;
471 int error, gotversion, jsys, len, oss_version;
472
473 LIN_SDT_PROBE2(mib, linux_prison_set, entry, obj, data);
474
312 /* Set the parameters, which should be correct. */
313 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
475 /* Set the parameters, which should be correct. */
476 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
477 if (error != 0)
478 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
314 if (error == ENOENT)
315 jsys = -1;
316 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
479 if (error == ENOENT)
480 jsys = -1;
481 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
482 if (error != 0)
483 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
317 if (error == ENOENT)
318 osname = NULL;
319 else
320 jsys = JAIL_SYS_NEW;
321 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
484 if (error == ENOENT)
485 osname = NULL;
486 else
487 jsys = JAIL_SYS_NEW;
488 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
489 if (error != 0)
490 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_getopt_error, error);
322 if (error == ENOENT)
323 osrelease = NULL;
324 else
325 jsys = JAIL_SYS_NEW;
326 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
327 sizeof(oss_version));
491 if (error == ENOENT)
492 osrelease = NULL;
493 else
494 jsys = JAIL_SYS_NEW;
495 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
496 sizeof(oss_version));
497 if (error != 0)
498 LIN_SDT_PROBE1(mib, linux_prison_set, vfs_copyopt_error, error);
328 if (error == ENOENT)
329 gotversion = 0;
330 else {
331 gotversion = 1;
332 jsys = JAIL_SYS_NEW;
333 }
334 switch (jsys) {
335 case JAIL_SYS_INHERIT:

--- 5 unchanged lines hidden (view full) ---

341 case JAIL_SYS_NEW:
342 /*
343 * "linux=new" or "linux.*":
344 * the prison gets its own Linux info.
345 */
346 error = linux_alloc_prison(pr, &lpr);
347 if (error) {
348 mtx_unlock(&pr->pr_mtx);
499 if (error == ENOENT)
500 gotversion = 0;
501 else {
502 gotversion = 1;
503 jsys = JAIL_SYS_NEW;
504 }
505 switch (jsys) {
506 case JAIL_SYS_INHERIT:

--- 5 unchanged lines hidden (view full) ---

512 case JAIL_SYS_NEW:
513 /*
514 * "linux=new" or "linux.*":
515 * the prison gets its own Linux info.
516 */
517 error = linux_alloc_prison(pr, &lpr);
518 if (error) {
519 mtx_unlock(&pr->pr_mtx);
520 LIN_SDT_PROBE1(mib, linux_prison_set, return, error);
349 return (error);
350 }
351 if (osrelease) {
352 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
353 if (error) {
354 mtx_unlock(&pr->pr_mtx);
521 return (error);
522 }
523 if (osrelease) {
524 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
525 if (error) {
526 mtx_unlock(&pr->pr_mtx);
527 LIN_SDT_PROBE1(mib, linux_prison_set, return,
528 error);
355 return (error);
356 }
357 strlcpy(lpr->pr_osrelease, osrelease,
358 LINUX_MAX_UTSNAME);
359 }
360 if (osname)
361 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
362 if (gotversion)
363 lpr->pr_oss_version = oss_version;
364 mtx_unlock(&pr->pr_mtx);
365 }
529 return (error);
530 }
531 strlcpy(lpr->pr_osrelease, osrelease,
532 LINUX_MAX_UTSNAME);
533 }
534 if (osname)
535 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
536 if (gotversion)
537 lpr->pr_oss_version = oss_version;
538 mtx_unlock(&pr->pr_mtx);
539 }
540
541 LIN_SDT_PROBE1(mib, linux_prison_set, return, 0);
366 return (0);
367}
368
369SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
370SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
371 "Jail Linux kernel OS name");
372SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
373 "Jail Linux kernel OS release");

--- 6 unchanged lines hidden (view full) ---

380 struct linux_prison *lpr;
381 struct prison *ppr;
382 struct prison *pr = obj;
383 struct vfsoptlist *opts = data;
384 int error, i;
385
386 static int version0;
387
542 return (0);
543}
544
545SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
546SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
547 "Jail Linux kernel OS name");
548SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
549 "Jail Linux kernel OS release");

--- 6 unchanged lines hidden (view full) ---

556 struct linux_prison *lpr;
557 struct prison *ppr;
558 struct prison *pr = obj;
559 struct vfsoptlist *opts = data;
560 int error, i;
561
562 static int version0;
563
564 LIN_SDT_PROBE2(mib, linux_prison_get, entry, obj, data);
565
388 /* See if this prison is the one with the Linux info. */
389 lpr = linux_find_prison(pr, &ppr);
390 i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
391 error = vfs_setopt(opts, "linux", &i, sizeof(i));
566 /* See if this prison is the one with the Linux info. */
567 lpr = linux_find_prison(pr, &ppr);
568 i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
569 error = vfs_setopt(opts, "linux", &i, sizeof(i));
392 if (error != 0 && error != ENOENT)
393 goto done;
570 if (error != 0) {
571 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error, error);
572 if (error != ENOENT)
573 goto done;
574 }
394 if (i) {
395 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
575 if (i) {
576 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
396 if (error != 0 && error != ENOENT)
397 goto done;
577 if (error != 0) {
578 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
579 error);
580 if (error != ENOENT)
581 goto done;
582 }
398 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
583 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
399 if (error != 0 && error != ENOENT)
400 goto done;
584 if (error != 0) {
585 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
586 error);
587 if (error != ENOENT)
588 goto done;
589 }
401 error = vfs_setopt(opts, "linux.oss_version",
402 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
590 error = vfs_setopt(opts, "linux.oss_version",
591 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
403 if (error != 0 && error != ENOENT)
404 goto done;
592 if (error != 0) {
593 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
594 error);
595 if(error != ENOENT)
596 goto done;
597 }
405 } else {
406 /*
407 * If this prison is inheriting its Linux info, report
408 * empty/zero parameters.
409 */
410 error = vfs_setopts(opts, "linux.osname", "");
598 } else {
599 /*
600 * If this prison is inheriting its Linux info, report
601 * empty/zero parameters.
602 */
603 error = vfs_setopts(opts, "linux.osname", "");
411 if (error != 0 && error != ENOENT)
412 goto done;
604 if (error != 0) {
605 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
606 error);
607 if(error != ENOENT)
608 goto done;
609 }
413 error = vfs_setopts(opts, "linux.osrelease", "");
610 error = vfs_setopts(opts, "linux.osrelease", "");
414 if (error != 0 && error != ENOENT)
415 goto done;
611 if (error != 0) {
612 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopts_error,
613 error);
614 if(error != ENOENT)
615 goto done;
616 }
416 error = vfs_setopt(opts, "linux.oss_version", &version0,
417 sizeof(lpr->pr_oss_version));
617 error = vfs_setopt(opts, "linux.oss_version", &version0,
618 sizeof(lpr->pr_oss_version));
418 if (error != 0 && error != ENOENT)
419 goto done;
619 if (error != 0) {
620 LIN_SDT_PROBE1(mib, linux_prison_get, vfs_setopt_error,
621 error);
622 if(error != ENOENT)
623 goto done;
624 }
420 }
421 error = 0;
422
423 done:
424 mtx_unlock(&ppr->pr_mtx);
625 }
626 error = 0;
627
628 done:
629 mtx_unlock(&ppr->pr_mtx);
630
631 LIN_SDT_PROBE1(mib, linux_prison_get, return, error);
425 return (error);
426}
427
428static void
429linux_prison_destructor(void *data)
430{
431
632 return (error);
633}
634
635static void
636linux_prison_destructor(void *data)
637{
638
639 LIN_SDT_PROBE1(mib, linux_prison_destructor, entry, data);
432 free(data, M_PRISON);
640 free(data, M_PRISON);
641 LIN_SDT_PROBE0(mib, linux_prison_destructor, return);
433}
434
435void
436linux_osd_jail_register(void)
437{
438 struct prison *pr;
439 osd_method_t methods[PR_MAXMETHOD] = {
440 [PR_METHOD_CREATE] = linux_prison_create,
441 [PR_METHOD_GET] = linux_prison_get,
442 [PR_METHOD_SET] = linux_prison_set,
443 [PR_METHOD_CHECK] = linux_prison_check
444 };
445
642}
643
644void
645linux_osd_jail_register(void)
646{
647 struct prison *pr;
648 osd_method_t methods[PR_MAXMETHOD] = {
649 [PR_METHOD_CREATE] = linux_prison_create,
650 [PR_METHOD_GET] = linux_prison_get,
651 [PR_METHOD_SET] = linux_prison_set,
652 [PR_METHOD_CHECK] = linux_prison_check
653 };
654
655 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
656
446 linux_osd_jail_slot =
447 osd_jail_register(linux_prison_destructor, methods);
448 if (linux_osd_jail_slot > 0) {
449 /* Copy the system linux info to any current prisons. */
450 sx_xlock(&allprison_lock);
451 TAILQ_FOREACH(pr, &allprison, pr_list)
452 (void)linux_alloc_prison(pr, NULL);
453 sx_xunlock(&allprison_lock);
454 }
657 linux_osd_jail_slot =
658 osd_jail_register(linux_prison_destructor, methods);
659 if (linux_osd_jail_slot > 0) {
660 /* Copy the system linux info to any current prisons. */
661 sx_xlock(&allprison_lock);
662 TAILQ_FOREACH(pr, &allprison, pr_list)
663 (void)linux_alloc_prison(pr, NULL);
664 sx_xunlock(&allprison_lock);
665 }
666
667 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
455}
456
457void
458linux_osd_jail_deregister(void)
459{
460
668}
669
670void
671linux_osd_jail_deregister(void)
672{
673
674 LIN_SDT_PROBE0(mib, linux_osd_jail_register, entry);
675
461 if (linux_osd_jail_slot)
462 osd_jail_deregister(linux_osd_jail_slot);
676 if (linux_osd_jail_slot)
677 osd_jail_deregister(linux_osd_jail_slot);
678
679 LIN_SDT_PROBE0(mib, linux_osd_jail_register, return);
463}
464
465void
466linux_get_osname(struct thread *td, char *dst)
467{
468 struct prison *pr;
469 struct linux_prison *lpr;
470
680}
681
682void
683linux_get_osname(struct thread *td, char *dst)
684{
685 struct prison *pr;
686 struct linux_prison *lpr;
687
688 LIN_SDT_PROBE2(mib, linux_get_osname, entry, td, dst);
689
471 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
472 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
473 mtx_unlock(&pr->pr_mtx);
690 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
691 bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
692 mtx_unlock(&pr->pr_mtx);
693
694 LIN_SDT_PROBE0(mib, linux_get_osname, return);
474}
475
476static int
477linux_set_osname(struct thread *td, char *osname)
478{
479 struct prison *pr;
480 struct linux_prison *lpr;
481
695}
696
697static int
698linux_set_osname(struct thread *td, char *osname)
699{
700 struct prison *pr;
701 struct linux_prison *lpr;
702
703 LIN_SDT_PROBE2(mib, linux_set_osname, entry, td, osname);
704
482 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
483 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
484 mtx_unlock(&pr->pr_mtx);
705 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
706 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
707 mtx_unlock(&pr->pr_mtx);
708
709 LIN_SDT_PROBE1(mib, linux_set_osname, return, 0);
485 return (0);
486}
487
488void
489linux_get_osrelease(struct thread *td, char *dst)
490{
491 struct prison *pr;
492 struct linux_prison *lpr;
493
710 return (0);
711}
712
713void
714linux_get_osrelease(struct thread *td, char *dst)
715{
716 struct prison *pr;
717 struct linux_prison *lpr;
718
719 LIN_SDT_PROBE2(mib, linux_get_osrelease, entry, td, dst);
720
494 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
495 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
496 mtx_unlock(&pr->pr_mtx);
721 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
722 bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
723 mtx_unlock(&pr->pr_mtx);
724
725 LIN_SDT_PROBE0(mib, linux_get_osrelease, return);
497}
498
499int
500linux_kernver(struct thread *td)
501{
502 struct prison *pr;
503 struct linux_prison *lpr;
504 int osrel;
505
726}
727
728int
729linux_kernver(struct thread *td)
730{
731 struct prison *pr;
732 struct linux_prison *lpr;
733 int osrel;
734
735 LIN_SDT_PROBE1(mib, linux_kernver, entry, td);
736
506 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
507 osrel = lpr->pr_osrel;
508 mtx_unlock(&pr->pr_mtx);
737 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
738 osrel = lpr->pr_osrel;
739 mtx_unlock(&pr->pr_mtx);
740
741 LIN_SDT_PROBE1(mib, linux_kernver, return, osrel);
509 return (osrel);
510}
511
512static int
513linux_set_osrelease(struct thread *td, char *osrelease)
514{
515 struct prison *pr;
516 struct linux_prison *lpr;
517 int error;
518
742 return (osrel);
743}
744
745static int
746linux_set_osrelease(struct thread *td, char *osrelease)
747{
748 struct prison *pr;
749 struct linux_prison *lpr;
750 int error;
751
752 LIN_SDT_PROBE2(mib, linux_set_osrelease, entry, td, osrelease);
753
519 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
520 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
521 if (error == 0)
522 strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
523 mtx_unlock(&pr->pr_mtx);
754 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
755 error = linux_map_osrel(osrelease, &lpr->pr_osrel);
756 if (error == 0)
757 strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
758 mtx_unlock(&pr->pr_mtx);
759
760 LIN_SDT_PROBE1(mib, linux_set_osrelease, return, error);
524 return (error);
525}
526
527int
528linux_get_oss_version(struct thread *td)
529{
530 struct prison *pr;
531 struct linux_prison *lpr;
532 int version;
533
761 return (error);
762}
763
764int
765linux_get_oss_version(struct thread *td)
766{
767 struct prison *pr;
768 struct linux_prison *lpr;
769 int version;
770
771 LIN_SDT_PROBE1(mib, linux_get_oss_version, entry, td);
772
534 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
535 version = lpr->pr_oss_version;
536 mtx_unlock(&pr->pr_mtx);
773 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
774 version = lpr->pr_oss_version;
775 mtx_unlock(&pr->pr_mtx);
776
777 LIN_SDT_PROBE1(mib, linux_get_oss_version, return, version);
537 return (version);
538}
539
540static int
541linux_set_oss_version(struct thread *td, int oss_version)
542{
543 struct prison *pr;
544 struct linux_prison *lpr;
545
778 return (version);
779}
780
781static int
782linux_set_oss_version(struct thread *td, int oss_version)
783{
784 struct prison *pr;
785 struct linux_prison *lpr;
786
787 LIN_SDT_PROBE2(mib, linux_set_oss_version, entry, td, oss_version);
788
546 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
547 lpr->pr_oss_version = oss_version;
548 mtx_unlock(&pr->pr_mtx);
789 lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
790 lpr->pr_oss_version = oss_version;
791 mtx_unlock(&pr->pr_mtx);
792
793 LIN_SDT_PROBE1(mib, linux_set_oss_version, return, 0);
549 return (0);
550}
551
552#if defined(DEBUG) || defined(KTR)
794 return (0);
795}
796
797#if defined(DEBUG) || defined(KTR)
798/* XXX: can be removed when every ldebug(...) and KTR stuff are removed. */
553
554u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
555
556static int
557linux_debug(int syscall, int toggle, int global)
558{
559
560 if (global) {

--- 51 unchanged lines hidden ---
799
800u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
801
802static int
803linux_debug(int syscall, int toggle, int global)
804{
805
806 if (global) {

--- 51 unchanged lines hidden ---