1999-08-27 19:47:41 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 Marcel Moolenaar
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2000-08-25 07:32:24 +00:00
|
|
|
* derived from this software without specific prior written permission.
|
1999-08-27 19:47:41 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 21:29:12 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-08-27 19:47:41 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/malloc.h>
|
2009-05-07 18:36:47 +00:00
|
|
|
#include <sys/mount.h>
|
1999-08-27 19:47:41 +00:00
|
|
|
#include <sys/jail.h>
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2009-05-07 18:36:47 +00:00
|
|
|
#include <sys/sx.h>
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2006-03-19 11:10:33 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2005-01-14 04:44:56 +00:00
|
|
|
#ifdef COMPAT_LINUX32
|
2004-08-16 07:28:16 +00:00
|
|
|
#include <machine/../linux32/linux.h>
|
2005-01-14 04:44:56 +00:00
|
|
|
#else
|
|
|
|
#include <machine/../linux/linux.h>
|
2004-08-16 07:28:16 +00:00
|
|
|
#endif
|
2000-08-22 01:32:14 +00:00
|
|
|
#include <compat/linux/linux_mib.h>
|
1999-08-27 19:47:41 +00:00
|
|
|
|
|
|
|
struct linux_prison {
|
|
|
|
char pr_osname[LINUX_MAX_UTSNAME];
|
|
|
|
char pr_osrelease[LINUX_MAX_UTSNAME];
|
|
|
|
int pr_oss_version;
|
2009-05-10 18:27:20 +00:00
|
|
|
int pr_osrel;
|
1999-08-27 19:47:41 +00:00
|
|
|
};
|
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
static struct linux_prison lprison0 = {
|
|
|
|
.pr_osname = "Linux",
|
|
|
|
.pr_osrelease = "2.6.16",
|
|
|
|
.pr_oss_version = 0x030600,
|
|
|
|
.pr_osrel = 2006016
|
|
|
|
};
|
|
|
|
|
2009-05-07 18:36:47 +00:00
|
|
|
static unsigned linux_osd_jail_slot;
|
|
|
|
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
|
1999-08-27 19:47:41 +00:00
|
|
|
"Linux mode");
|
|
|
|
|
2011-03-15 13:40:47 +00:00
|
|
|
static int linux_set_osname(struct thread *td, char *osname);
|
|
|
|
static int linux_set_osrelease(struct thread *td, char *osrelease);
|
|
|
|
static int linux_set_oss_version(struct thread *td, int oss_version);
|
|
|
|
|
1999-08-27 19:47:41 +00:00
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
linux_sysctl_osname(SYSCTL_HANDLER_ARGS)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
char osname[LINUX_MAX_UTSNAME];
|
|
|
|
int error;
|
|
|
|
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_get_osname(req->td, osname);
|
1999-08-27 19:47:41 +00:00
|
|
|
error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req);
|
|
|
|
if (error || req->newptr == NULL)
|
|
|
|
return (error);
|
2003-03-13 22:45:43 +00:00
|
|
|
error = linux_set_osname(req->td, osname);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
|
2009-05-04 19:06:05 +00:00
|
|
|
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
|
1999-08-27 19:47:41 +00:00
|
|
|
0, 0, linux_sysctl_osname, "A",
|
|
|
|
"Linux kernel OS name");
|
|
|
|
|
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
char osrelease[LINUX_MAX_UTSNAME];
|
|
|
|
int error;
|
|
|
|
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_get_osrelease(req->td, osrelease);
|
1999-08-27 19:47:41 +00:00
|
|
|
error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
|
|
|
|
if (error || req->newptr == NULL)
|
|
|
|
return (error);
|
2003-03-13 22:45:43 +00:00
|
|
|
error = linux_set_osrelease(req->td, osrelease);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
|
2009-05-04 19:06:05 +00:00
|
|
|
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
|
1999-08-27 19:47:41 +00:00
|
|
|
0, 0, linux_sysctl_osrelease, "A",
|
|
|
|
"Linux kernel OS release");
|
|
|
|
|
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
linux_sysctl_oss_version(SYSCTL_HANDLER_ARGS)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
int oss_version;
|
|
|
|
int error;
|
|
|
|
|
2003-03-13 22:45:43 +00:00
|
|
|
oss_version = linux_get_oss_version(req->td);
|
1999-08-27 19:47:41 +00:00
|
|
|
error = sysctl_handle_int(oidp, &oss_version, 0, req);
|
|
|
|
if (error || req->newptr == NULL)
|
|
|
|
return (error);
|
2003-03-13 22:45:43 +00:00
|
|
|
error = linux_set_oss_version(req->td, oss_version);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
|
2009-05-04 19:06:05 +00:00
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
|
1999-08-27 19:47:41 +00:00
|
|
|
0, 0, linux_sysctl_oss_version, "I",
|
|
|
|
"Linux OSS version");
|
|
|
|
|
2009-05-10 18:27:20 +00:00
|
|
|
/*
|
|
|
|
* Map the osrelease into integer
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
linux_map_osrel(char *osrelease, int *osrel)
|
|
|
|
{
|
|
|
|
char *sep, *eosrelease;
|
|
|
|
int len, v0, v1, v2, v;
|
|
|
|
|
|
|
|
len = strlen(osrelease);
|
|
|
|
eosrelease = osrelease + len;
|
|
|
|
v0 = strtol(osrelease, &sep, 10);
|
|
|
|
if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.')
|
|
|
|
return (EINVAL);
|
|
|
|
osrelease = sep + 1;
|
|
|
|
v1 = strtol(osrelease, &sep, 10);
|
|
|
|
if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.')
|
|
|
|
return (EINVAL);
|
|
|
|
osrelease = sep + 1;
|
|
|
|
v2 = strtol(osrelease, &sep, 10);
|
|
|
|
if (osrelease == sep || sep != eosrelease)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
v = v0 * 1000000 + v1 * 1000 + v2;
|
|
|
|
if (v < 1000000)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
*osrel = v;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
/*
|
2009-05-27 14:11:23 +00:00
|
|
|
* Find a prison with Linux info.
|
|
|
|
* Return the Linux info and the (locked) prison.
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
*/
|
2009-05-07 18:36:47 +00:00
|
|
|
static struct linux_prison *
|
2009-05-27 14:11:23 +00:00
|
|
|
linux_find_prison(struct prison *spr, struct prison **prp)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2009-05-07 18:36:47 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
if (!linux_osd_jail_slot)
|
|
|
|
/* In case osd_register failed. */
|
|
|
|
spr = &prison0;
|
|
|
|
for (pr = spr;; pr = pr->pr_parent) {
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
lpr = (pr == &prison0)
|
|
|
|
? &lprison0
|
|
|
|
: osd_jail_get(pr, linux_osd_jail_slot);
|
|
|
|
if (lpr != NULL)
|
|
|
|
break;
|
2009-05-07 18:36:47 +00:00
|
|
|
mtx_unlock(&pr->pr_mtx);
|
2009-05-27 14:11:23 +00:00
|
|
|
}
|
|
|
|
*prp = pr;
|
2009-05-07 18:36:47 +00:00
|
|
|
return (lpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-05-27 14:11:23 +00:00
|
|
|
* Ensure a prison has its own Linux info. If lprp is non-null, point it to
|
|
|
|
* the Linux info and lock the prison.
|
2009-05-07 18:36:47 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
linux_alloc_prison(struct prison *pr, struct linux_prison **lprp)
|
|
|
|
{
|
2009-05-27 14:11:23 +00:00
|
|
|
struct prison *ppr;
|
2009-05-07 18:36:47 +00:00
|
|
|
struct linux_prison *lpr, *nlpr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* If this prison already has Linux info, return that. */
|
|
|
|
error = 0;
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(pr, &ppr);
|
|
|
|
if (ppr == pr)
|
2009-05-07 18:36:47 +00:00
|
|
|
goto done;
|
|
|
|
/*
|
|
|
|
* Allocate a new info record. Then check again, in case something
|
|
|
|
* changed during the allocation.
|
|
|
|
*/
|
2009-05-27 14:11:23 +00:00
|
|
|
mtx_unlock(&ppr->pr_mtx);
|
2009-05-07 18:36:47 +00:00
|
|
|
nlpr = malloc(sizeof(struct linux_prison), M_PRISON, M_WAITOK);
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(pr, &ppr);
|
|
|
|
if (ppr == pr) {
|
2009-05-07 18:36:47 +00:00
|
|
|
free(nlpr, M_PRISON);
|
|
|
|
goto done;
|
|
|
|
}
|
2009-05-27 14:11:23 +00:00
|
|
|
/* Inherit the initial values from the ancestor. */
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
2009-05-07 18:36:47 +00:00
|
|
|
error = osd_jail_set(pr, linux_osd_jail_slot, nlpr);
|
2009-05-27 14:11:23 +00:00
|
|
|
if (error == 0) {
|
|
|
|
bcopy(lpr, nlpr, sizeof(*lpr));
|
2009-05-07 18:36:47 +00:00
|
|
|
lpr = nlpr;
|
2009-05-27 14:11:23 +00:00
|
|
|
} else {
|
|
|
|
free(nlpr, M_PRISON);
|
|
|
|
lpr = NULL;
|
2009-05-07 18:36:47 +00:00
|
|
|
}
|
2009-05-27 14:11:23 +00:00
|
|
|
mtx_unlock(&ppr->pr_mtx);
|
|
|
|
done:
|
2009-05-07 18:36:47 +00:00
|
|
|
if (lprp != NULL)
|
|
|
|
*lprp = lpr;
|
2009-05-27 14:11:23 +00:00
|
|
|
else
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
2009-05-07 18:36:47 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Jail OSD methods for Linux prison data.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
linux_prison_create(void *obj, void *data)
|
|
|
|
{
|
|
|
|
struct prison *pr = obj;
|
|
|
|
struct vfsoptlist *opts = data;
|
2009-07-25 14:48:57 +00:00
|
|
|
int jsys;
|
2009-05-07 18:36:47 +00:00
|
|
|
|
2009-07-25 14:48:57 +00:00
|
|
|
if (vfs_copyopt(opts, "linux", &jsys, sizeof(jsys)) == 0 &&
|
|
|
|
jsys == JAIL_SYS_INHERIT)
|
2009-05-07 18:36:47 +00:00
|
|
|
return (0);
|
|
|
|
/*
|
|
|
|
* Inherit a prison's initial values from its parent
|
2009-07-25 14:48:57 +00:00
|
|
|
* (different from JAIL_SYS_INHERIT which also inherits changes).
|
2009-05-07 18:36:47 +00:00
|
|
|
*/
|
2009-05-27 14:11:23 +00:00
|
|
|
return linux_alloc_prison(pr, NULL);
|
2009-05-07 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
linux_prison_check(void *obj __unused, void *data)
|
|
|
|
{
|
|
|
|
struct vfsoptlist *opts = data;
|
|
|
|
char *osname, *osrelease;
|
2009-07-25 14:48:57 +00:00
|
|
|
int error, jsys, len, osrel, oss_version;
|
2009-05-07 18:36:47 +00:00
|
|
|
|
|
|
|
/* Check that the parameters are correct. */
|
2009-07-25 14:48:57 +00:00
|
|
|
error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
|
|
|
|
if (error != ENOENT) {
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2009-05-07 18:36:47 +00:00
|
|
|
error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
|
|
|
|
if (error != ENOENT) {
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (len == 0 || osname[len - 1] != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
if (len > LINUX_MAX_UTSNAME) {
|
|
|
|
vfs_opterror(opts, "linux.osname too long");
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
|
|
|
|
if (error != ENOENT) {
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (len == 0 || osrelease[len - 1] != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
if (len > LINUX_MAX_UTSNAME) {
|
|
|
|
vfs_opterror(opts, "linux.osrelease too long");
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
}
|
2009-05-27 14:11:23 +00:00
|
|
|
error = linux_map_osrel(osrelease, &osrel);
|
|
|
|
if (error != 0) {
|
|
|
|
vfs_opterror(opts, "linux.osrelease format error");
|
|
|
|
return (error);
|
|
|
|
}
|
2009-05-07 18:36:47 +00:00
|
|
|
}
|
|
|
|
error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
|
|
|
|
sizeof(oss_version));
|
|
|
|
return (error == ENOENT ? 0 : error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
linux_prison_set(void *obj, void *data)
|
|
|
|
{
|
|
|
|
struct linux_prison *lpr;
|
|
|
|
struct prison *pr = obj;
|
|
|
|
struct vfsoptlist *opts = data;
|
|
|
|
char *osname, *osrelease;
|
2009-07-25 14:48:57 +00:00
|
|
|
int error, gotversion, jsys, len, oss_version;
|
2009-05-07 18:36:47 +00:00
|
|
|
|
|
|
|
/* Set the parameters, which should be correct. */
|
2009-07-25 14:48:57 +00:00
|
|
|
error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
|
|
|
|
if (error == ENOENT)
|
|
|
|
jsys = -1;
|
2009-05-07 18:36:47 +00:00
|
|
|
error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
|
|
|
|
if (error == ENOENT)
|
|
|
|
osname = NULL;
|
|
|
|
else
|
2009-07-25 14:48:57 +00:00
|
|
|
jsys = JAIL_SYS_NEW;
|
2009-05-07 18:36:47 +00:00
|
|
|
error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
|
|
|
|
if (error == ENOENT)
|
|
|
|
osrelease = NULL;
|
|
|
|
else
|
2009-07-25 14:48:57 +00:00
|
|
|
jsys = JAIL_SYS_NEW;
|
2009-05-07 18:36:47 +00:00
|
|
|
error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
|
|
|
|
sizeof(oss_version));
|
2009-07-25 14:48:57 +00:00
|
|
|
if (error == ENOENT)
|
|
|
|
gotversion = 0;
|
|
|
|
else {
|
|
|
|
gotversion = 1;
|
|
|
|
jsys = JAIL_SYS_NEW;
|
|
|
|
}
|
|
|
|
switch (jsys) {
|
|
|
|
case JAIL_SYS_INHERIT:
|
|
|
|
/* "linux=inherit": inherit the parent's Linux info. */
|
2009-05-07 18:36:47 +00:00
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
osd_jail_del(pr, linux_osd_jail_slot);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
2009-07-25 14:48:57 +00:00
|
|
|
break;
|
|
|
|
case JAIL_SYS_NEW:
|
2003-03-13 22:45:43 +00:00
|
|
|
/*
|
2009-07-25 14:48:57 +00:00
|
|
|
* "linux=new" or "linux.*":
|
2009-05-07 18:36:47 +00:00
|
|
|
* the prison gets its own Linux info.
|
2003-03-13 22:45:43 +00:00
|
|
|
*/
|
2009-05-07 18:36:47 +00:00
|
|
|
error = linux_alloc_prison(pr, &lpr);
|
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (osrelease) {
|
2009-05-10 18:27:20 +00:00
|
|
|
error = linux_map_osrel(osrelease, &lpr->pr_osrel);
|
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
return (error);
|
|
|
|
}
|
2009-05-07 18:36:47 +00:00
|
|
|
strlcpy(lpr->pr_osrelease, osrelease,
|
|
|
|
LINUX_MAX_UTSNAME);
|
|
|
|
}
|
2009-05-10 18:27:20 +00:00
|
|
|
if (osname)
|
|
|
|
strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
|
2009-05-07 18:36:47 +00:00
|
|
|
if (gotversion)
|
|
|
|
lpr->pr_oss_version = oss_version;
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-07-25 14:48:57 +00:00
|
|
|
SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
|
2009-05-07 18:36:47 +00:00
|
|
|
SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
|
|
|
|
"Jail Linux kernel OS name");
|
|
|
|
SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
|
|
|
|
"Jail Linux kernel OS release");
|
|
|
|
SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
"I", "Jail Linux OSS version");
|
|
|
|
|
|
|
|
static int
|
|
|
|
linux_prison_get(void *obj, void *data)
|
|
|
|
{
|
|
|
|
struct linux_prison *lpr;
|
2009-05-27 14:11:23 +00:00
|
|
|
struct prison *ppr;
|
2009-05-07 18:36:47 +00:00
|
|
|
struct prison *pr = obj;
|
|
|
|
struct vfsoptlist *opts = data;
|
|
|
|
int error, i;
|
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
static int version0;
|
|
|
|
|
|
|
|
/* See if this prison is the one with the Linux info. */
|
|
|
|
lpr = linux_find_prison(pr, &ppr);
|
2009-07-25 14:48:57 +00:00
|
|
|
i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
|
2009-05-07 18:36:47 +00:00
|
|
|
error = vfs_setopt(opts, "linux", &i, sizeof(i));
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
2009-05-27 14:11:23 +00:00
|
|
|
if (i) {
|
2009-07-25 14:48:57 +00:00
|
|
|
error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
|
|
|
error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
|
|
|
error = vfs_setopt(opts, "linux.oss_version",
|
|
|
|
&lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
|
|
|
} else {
|
2009-05-27 14:11:23 +00:00
|
|
|
/*
|
|
|
|
* If this prison is inheriting its Linux info, report
|
|
|
|
* empty/zero parameters.
|
|
|
|
*/
|
|
|
|
error = vfs_setopts(opts, "linux.osname", "");
|
2009-05-07 18:36:47 +00:00
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
2009-05-27 14:11:23 +00:00
|
|
|
error = vfs_setopts(opts, "linux.osrelease", "");
|
2009-05-07 18:36:47 +00:00
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
2009-05-27 14:11:23 +00:00
|
|
|
error = vfs_setopt(opts, "linux.oss_version", &version0,
|
|
|
|
sizeof(lpr->pr_oss_version));
|
2009-05-07 18:36:47 +00:00
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
goto done;
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
2009-05-07 18:36:47 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
done:
|
2009-05-27 14:11:23 +00:00
|
|
|
mtx_unlock(&ppr->pr_mtx);
|
2009-05-07 18:36:47 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
linux_prison_destructor(void *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
free(data, M_PRISON);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
linux_osd_jail_register(void)
|
|
|
|
{
|
|
|
|
struct prison *pr;
|
|
|
|
osd_method_t methods[PR_MAXMETHOD] = {
|
|
|
|
[PR_METHOD_CREATE] = linux_prison_create,
|
|
|
|
[PR_METHOD_GET] = linux_prison_get,
|
|
|
|
[PR_METHOD_SET] = linux_prison_set,
|
|
|
|
[PR_METHOD_CHECK] = linux_prison_check
|
|
|
|
};
|
|
|
|
|
|
|
|
linux_osd_jail_slot =
|
|
|
|
osd_jail_register(linux_prison_destructor, methods);
|
|
|
|
if (linux_osd_jail_slot > 0) {
|
|
|
|
/* Copy the system linux info to any current prisons. */
|
|
|
|
sx_xlock(&allprison_lock);
|
2009-05-27 14:11:23 +00:00
|
|
|
TAILQ_FOREACH(pr, &allprison, pr_list)
|
2009-05-07 18:36:47 +00:00
|
|
|
(void)linux_alloc_prison(pr, NULL);
|
|
|
|
sx_xunlock(&allprison_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
linux_osd_jail_deregister(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (linux_osd_jail_slot)
|
|
|
|
osd_jail_deregister(linux_osd_jail_slot);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
void
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_get_osname(struct thread *td, char *dst)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2009-05-07 18:36:47 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 13:40:47 +00:00
|
|
|
static int
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_set_osname(struct thread *td, char *osname)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2003-03-13 22:45:43 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
void
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_get_osrelease(struct thread *td, char *dst)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2009-05-07 18:36:47 +00:00
|
|
|
struct prison *pr;
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
struct linux_prison *lpr;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2006-12-31 12:39:10 +00:00
|
|
|
int
|
2009-05-10 18:27:20 +00:00
|
|
|
linux_kernver(struct thread *td)
|
2006-12-31 12:39:10 +00:00
|
|
|
{
|
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
2009-05-10 18:27:20 +00:00
|
|
|
int osrel;
|
2006-12-31 12:39:10 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
osrel = lpr->pr_osrel;
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
2009-05-10 18:27:20 +00:00
|
|
|
return (osrel);
|
2006-12-31 12:39:10 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 13:40:47 +00:00
|
|
|
static int
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_set_osrelease(struct thread *td, char *osrelease)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2003-03-13 22:45:43 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
2009-05-10 18:27:20 +00:00
|
|
|
int error;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
error = linux_map_osrel(osrelease, &lpr->pr_osrel);
|
|
|
|
if (error == 0)
|
2009-05-07 18:36:47 +00:00
|
|
|
strlcpy(lpr->pr_osrelease, osrelease, LINUX_MAX_UTSNAME);
|
2009-05-27 14:11:23 +00:00
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
return (error);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_get_oss_version(struct thread *td)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2009-05-07 18:36:47 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
int version;
|
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
version = lpr->pr_oss_version;
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
o Introduce pr_mtx into struct prison, providing protection for the
mutable contents of struct prison (hostname, securelevel, refcount,
pr_linux, ...)
o Generally introduce mtx_lock()/mtx_unlock() calls throughout kern/
so as to enforce these protections, in particular, in kern_mib.c
protection sysctl access to the hostname and securelevel, as well as
kern_prot.c access to the securelevel for access control purposes.
o Rewrite linux emulator abstractions for accessing per-jail linux
mib entries (osname, osrelease, osversion) so that they don't return
a pointer to the text in the struct linux_prison, rather, a copy
to an array passed into the calls. Likewise, update linprocfs to
use these primitives.
o Update in_pcb.c to always use prison_getip() rather than directly
accessing struct prison.
Reviewed by: jhb
2001-12-03 16:12:27 +00:00
|
|
|
return (version);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 13:40:47 +00:00
|
|
|
static int
|
2003-03-13 22:45:43 +00:00
|
|
|
linux_set_oss_version(struct thread *td, int oss_version)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
2003-03-13 22:45:43 +00:00
|
|
|
struct prison *pr;
|
|
|
|
struct linux_prison *lpr;
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2009-05-27 14:11:23 +00:00
|
|
|
lpr = linux_find_prison(td->td_ucred->cr_prison, &pr);
|
|
|
|
lpr->pr_oss_version = oss_version;
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2001-02-16 16:40:43 +00:00
|
|
|
|
2009-05-07 10:01:05 +00:00
|
|
|
#if defined(DEBUG) || defined(KTR)
|
2001-02-16 16:40:43 +00:00
|
|
|
|
2001-06-15 08:18:24 +00:00
|
|
|
u_char linux_debug_map[howmany(LINUX_SYS_MAXSYSCALL, sizeof(u_char))];
|
2001-02-16 16:40:43 +00:00
|
|
|
|
2001-06-15 07:48:21 +00:00
|
|
|
static int
|
2001-02-16 16:40:43 +00:00
|
|
|
linux_debug(int syscall, int toggle, int global)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (global) {
|
|
|
|
char c = toggle ? 0 : 0xff;
|
|
|
|
|
|
|
|
memset(linux_debug_map, c, sizeof(linux_debug_map));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (syscall < 0 || syscall >= LINUX_SYS_MAXSYSCALL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (toggle)
|
|
|
|
clrbit(linux_debug_map, syscall);
|
|
|
|
else
|
|
|
|
setbit(linux_debug_map, syscall);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-05-11 06:06:11 +00:00
|
|
|
* Usage: sysctl linux.debug=<syscall_nr>.<0/1>
|
2001-02-16 16:40:43 +00:00
|
|
|
*
|
2002-05-11 06:06:11 +00:00
|
|
|
* E.g.: sysctl linux.debug=21.0
|
2001-02-16 16:40:43 +00:00
|
|
|
*
|
|
|
|
* As a special case, syscall "all" will apply to all syscalls globally.
|
|
|
|
*/
|
|
|
|
#define LINUX_MAX_DEBUGSTR 16
|
|
|
|
static int
|
|
|
|
linux_sysctl_debug(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
char value[LINUX_MAX_DEBUGSTR], *p;
|
|
|
|
int error, sysc, toggle;
|
|
|
|
int global = 0;
|
|
|
|
|
|
|
|
value[0] = '\0';
|
|
|
|
error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req);
|
|
|
|
if (error || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
for (p = value; *p != '\0' && *p != '.'; p++);
|
|
|
|
if (*p == '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
*p++ = '\0';
|
|
|
|
sysc = strtol(value, NULL, 0);
|
|
|
|
toggle = strtol(p, NULL, 0);
|
|
|
|
if (strcmp(value, "all") == 0)
|
|
|
|
global = 1;
|
|
|
|
error = linux_debug(sysc, toggle, global);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
|
|
|
|
CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
0, 0, linux_sysctl_debug, "A",
|
|
|
|
"Linux debugging control");
|
|
|
|
|
2009-05-07 10:01:05 +00:00
|
|
|
#endif /* DEBUG || KTR */
|