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.
|
|
|
|
*
|
1999-08-28 02:16:32 +00:00
|
|
|
* $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>
|
|
|
|
#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>
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2000-08-22 01:32:14 +00:00
|
|
|
#include <machine/../linux/linux.h>
|
|
|
|
#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;
|
|
|
|
};
|
|
|
|
|
|
|
|
SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
|
|
|
|
"Linux mode");
|
|
|
|
|
|
|
|
static char linux_osname[LINUX_MAX_UTSNAME] = "Linux";
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
linux_get_osname(req->td->td_proc, 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);
|
2001-11-08 02:13:18 +00:00
|
|
|
error = linux_set_osname(req->td->td_proc, osname);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, osname,
|
|
|
|
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON,
|
|
|
|
0, 0, linux_sysctl_osname, "A",
|
|
|
|
"Linux kernel OS name");
|
|
|
|
|
2001-09-08 19:07:04 +00:00
|
|
|
static char linux_osrelease[LINUX_MAX_UTSNAME] = "2.4.2";
|
1999-08-27 19:47:41 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
linux_get_osrelease(req->td->td_proc, 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);
|
2001-11-08 02:13:18 +00:00
|
|
|
error = linux_set_osrelease(req->td->td_proc, osrelease);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, osrelease,
|
|
|
|
CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON,
|
|
|
|
0, 0, linux_sysctl_osrelease, "A",
|
|
|
|
"Linux kernel OS release");
|
|
|
|
|
|
|
|
static int linux_oss_version = 0x030600;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-11-08 02:13:18 +00:00
|
|
|
oss_version = linux_get_oss_version(req->td->td_proc);
|
1999-08-27 19:47:41 +00:00
|
|
|
error = sysctl_handle_int(oidp, &oss_version, 0, req);
|
|
|
|
if (error || req->newptr == NULL)
|
|
|
|
return (error);
|
2001-11-08 02:13:18 +00:00
|
|
|
error = linux_set_oss_version(req->td->td_proc, oss_version);
|
1999-08-27 19:47:41 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_compat_linux, OID_AUTO, oss_version,
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON,
|
|
|
|
0, 0, linux_sysctl_oss_version, "I",
|
|
|
|
"Linux OSS version");
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Returns holding the prison mutex if return non-NULL.
|
|
|
|
*/
|
1999-08-27 19:47:41 +00:00
|
|
|
static struct linux_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
|
|
|
linux_get_prison(struct proc *p)
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
register struct prison *pr;
|
|
|
|
register struct linux_prison *lpr;
|
|
|
|
|
2001-02-21 06:39:57 +00:00
|
|
|
if (!jailed(p->p_ucred))
|
1999-08-27 19:47:41 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2001-02-21 06:39:57 +00:00
|
|
|
pr = p->p_ucred->cr_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
|
|
|
/*
|
|
|
|
* Rather than hold the prison mutex during allocation, check to
|
|
|
|
* see if we need to allocate while holding the mutex, release it,
|
|
|
|
* allocate, then once we've allocated the memory, check again to
|
|
|
|
* see if it's still needed, and set if appropriate. If it's not,
|
|
|
|
* we release the mutex again to FREE(), and grab it again so as
|
|
|
|
* to release holding the lock.
|
|
|
|
*/
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
if (pr->pr_linux == NULL) {
|
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
|
|
|
mtx_unlock(&pr->pr_mtx);
|
1999-08-27 19:47:41 +00:00
|
|
|
MALLOC(lpr, struct linux_prison *, sizeof *lpr,
|
2000-12-05 06:44:22 +00:00
|
|
|
M_PRISON, M_WAITOK|M_ZERO);
|
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
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
if (pr->pr_linux == NULL) {
|
|
|
|
pr->pr_linux = lpr;
|
|
|
|
} else {
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
FREE(lpr, M_PRISON);
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
}
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (pr->pr_linux);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
linux_get_osname(p, dst)
|
1999-08-27 19:47:41 +00:00
|
|
|
struct proc *p;
|
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
|
|
|
char *dst;
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
register struct prison *pr;
|
|
|
|
register 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
|
|
|
if (p->p_ucred->cr_prison == NULL) {
|
|
|
|
bcopy(linux_osname, dst, LINUX_MAX_UTSNAME);
|
|
|
|
return;
|
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
|
|
|
pr = p->p_ucred->cr_prison;
|
|
|
|
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
if (pr->pr_linux != NULL) {
|
|
|
|
lpr = (struct linux_prison *)pr->pr_linux;
|
|
|
|
if (lpr->pr_osname[0]) {
|
|
|
|
bcopy(lpr->pr_osname, dst, LINUX_MAX_UTSNAME);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
bcopy(linux_osname, dst, LINUX_MAX_UTSNAME);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_set_osname(p, osname)
|
|
|
|
struct proc *p;
|
|
|
|
char *osname;
|
|
|
|
{
|
|
|
|
register 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
|
|
|
lpr = linux_get_prison(p);
|
|
|
|
if (lpr != NULL) {
|
1999-08-27 19:47:41 +00:00
|
|
|
strcpy(lpr->pr_osname, osname);
|
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
|
|
|
mtx_unlock(&p->p_ucred->cr_prison->pr_mtx);
|
|
|
|
} else {
|
1999-08-27 19:47:41 +00:00
|
|
|
strcpy(linux_osname, osname);
|
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
|
|
|
}
|
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
|
|
|
|
linux_get_osrelease(p, dst)
|
1999-08-27 19:47:41 +00:00
|
|
|
struct proc *p;
|
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
|
|
|
char *dst;
|
1999-08-27 19:47:41 +00:00
|
|
|
{
|
|
|
|
register 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
|
|
|
|
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
|
|
|
if (p->p_ucred->cr_prison == NULL) {
|
|
|
|
bcopy(linux_osrelease, dst, LINUX_MAX_UTSNAME);
|
|
|
|
return;
|
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
|
|
|
pr = p->p_ucred->cr_prison;
|
|
|
|
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
if (pr->pr_linux != NULL) {
|
|
|
|
lpr = (struct linux_prison *) pr->pr_linux;
|
|
|
|
if (lpr->pr_osrelease[0]) {
|
|
|
|
bcopy(lpr->pr_osrelease, dst, LINUX_MAX_UTSNAME);
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&pr->pr_mtx);
|
|
|
|
bcopy(linux_osrelease, dst, LINUX_MAX_UTSNAME);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_set_osrelease(p, osrelease)
|
|
|
|
struct proc *p;
|
|
|
|
char *osrelease;
|
|
|
|
{
|
|
|
|
register 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
|
|
|
lpr = linux_get_prison(p);
|
|
|
|
if (lpr != NULL) {
|
1999-08-27 19:47:41 +00:00
|
|
|
strcpy(lpr->pr_osrelease, osrelease);
|
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
|
|
|
mtx_unlock(&p->p_ucred->cr_prison->pr_mtx);
|
|
|
|
} else {
|
1999-08-27 19:47:41 +00:00
|
|
|
strcpy(linux_osrelease, osrelease);
|
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
|
|
|
}
|
1999-08-27 19:47:41 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_get_oss_version(p)
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct prison *pr;
|
|
|
|
register 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;
|
|
|
|
|
|
|
|
if (p->p_ucred->cr_prison == NULL)
|
|
|
|
return (linux_oss_version);
|
1999-08-27 19:47:41 +00:00
|
|
|
|
2001-02-21 06:39:57 +00:00
|
|
|
pr = p->p_ucred->cr_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
|
|
|
|
|
|
|
mtx_lock(&pr->pr_mtx);
|
|
|
|
if (pr->pr_linux != NULL) {
|
|
|
|
lpr = (struct linux_prison *) pr->pr_linux;
|
|
|
|
if (lpr->pr_oss_version) {
|
|
|
|
version = lpr->pr_oss_version;
|
|
|
|
} else {
|
|
|
|
version = linux_oss_version;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
version = linux_oss_version;
|
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
|
|
|
mtx_unlock(&pr->pr_mtx);
|
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
|
|
|
return (version);
|
1999-08-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
linux_set_oss_version(p, oss_version)
|
|
|
|
struct proc *p;
|
|
|
|
int oss_version;
|
|
|
|
{
|
|
|
|
register 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
|
|
|
lpr = linux_get_prison(p);
|
|
|
|
if (lpr != NULL) {
|
1999-08-27 19:47:41 +00:00
|
|
|
lpr->pr_oss_version = oss_version;
|
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
|
|
|
mtx_unlock(&p->p_ucred->cr_prison->pr_mtx);
|
|
|
|
} else {
|
1999-08-27 19:47:41 +00:00
|
|
|
linux_oss_version = oss_version;
|
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
|
|
|
}
|
1999-08-27 19:47:41 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2001-02-16 16:40:43 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usage: sysctl -w linux.debug=<syscall_nr>.<0/1>
|
|
|
|
*
|
|
|
|
* E.g.: sysctl -w linux.debug=21.0
|
|
|
|
*
|
|
|
|
* 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");
|
|
|
|
|
|
|
|
#endif /* DEBUG */
|