FreeBSD kernel kern code
kern_priv.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/sdt.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <security/mac/mac_framework.h>
Include dependency graph for kern_priv.c:

Go to the source code of this file.

Functions

 __FBSDID ("$FreeBSD$")
 
static bool suser_enabled (struct ucred *cred)
 
static int sysctl_kern_suser_enabled (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_security_bsd, OID_AUTO, suser_enabled, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_PRISON|CTLFLAG_MPSAFE, 0, 0, &sysctl_kern_suser_enabled, "I", "Processes with uid 0 have privilege")
 
 SYSCTL_INT (_security_bsd, OID_AUTO, unprivileged_mlock, CTLFLAG_RWTUN, &unprivileged_mlock, 0, "Allow non-root users to call mlock(2)")
 
 SYSCTL_INT (_security_bsd, OID_AUTO, unprivileged_read_msgbuf, CTLFLAG_RW, &unprivileged_read_msgbuf, 0, "Unprivileged processes may read the kernel message buffer")
 
 SDT_PROVIDER_DEFINE (priv)
 
 SDT_PROBE_DEFINE1 (priv, kernel, priv_check, priv__ok, "int")
 
 SDT_PROBE_DEFINE1 (priv, kernel, priv_check, priv__err, "int")
 
static __always_inline int priv_check_cred_pre (struct ucred *cred, int priv)
 
static __always_inline int priv_check_cred_post (struct ucred *cred, int priv, int error, bool handled)
 
int priv_check_cred (struct ucred *cred, int priv)
 
int priv_check (struct thread *td, int priv)
 
static int __noinline priv_check_cred_vfs_lookup_slow (struct ucred *cred)
 
int priv_check_cred_vfs_lookup (struct ucred *cred)
 
int priv_check_cred_vfs_lookup_nomac (struct ucred *cred)
 
static int __noinline priv_check_cred_vfs_generation_slow (struct ucred *cred)
 
int priv_check_cred_vfs_generation (struct ucred *cred)
 

Variables

static int unprivileged_mlock = 1
 
static int unprivileged_read_msgbuf = 1
 

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ priv_check()

◆ priv_check_cred()

◆ priv_check_cred_post()

static __always_inline int priv_check_cred_post ( struct ucred *  cred,
int  priv,
int  error,
bool  handled 
)
static

Definition at line 115 of file kern_priv.c.

References priv_check().

Referenced by priv_check_cred(), priv_check_cred_vfs_generation_slow(), and priv_check_cred_vfs_lookup_slow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priv_check_cred_pre()

static __always_inline int priv_check_cred_pre ( struct ucred *  cred,
int  priv 
)
static

Definition at line 102 of file kern_priv.c.

Referenced by priv_check_cred(), priv_check_cred_vfs_generation_slow(), and priv_check_cred_vfs_lookup_slow().

Here is the caller graph for this function:

◆ priv_check_cred_vfs_generation()

int priv_check_cred_vfs_generation ( struct ucred *  cred)

Definition at line 355 of file kern_priv.c.

References priv_check_cred_vfs_generation_slow(), and suser_enabled().

Referenced by kern_do_statfs(), kern_getfsstat(), and priv_check_cred().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priv_check_cred_vfs_generation_slow()

static int __noinline priv_check_cred_vfs_generation_slow ( struct ucred *  cred)
static

Definition at line 330 of file kern_priv.c.

References priv_check_cred_post(), priv_check_cred_pre(), and suser_enabled().

Referenced by priv_check_cred_vfs_generation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priv_check_cred_vfs_lookup()

int priv_check_cred_vfs_lookup ( struct ucred *  cred)

Definition at line 300 of file kern_priv.c.

References priv_check_cred_vfs_lookup_slow(), and suser_enabled().

Referenced by priv_check_cred().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priv_check_cred_vfs_lookup_nomac()

int priv_check_cred_vfs_lookup_nomac ( struct ucred *  cred)

Definition at line 315 of file kern_priv.c.

References suser_enabled().

Referenced by vaccess_vexec_smr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priv_check_cred_vfs_lookup_slow()

static int __noinline priv_check_cred_vfs_lookup_slow ( struct ucred *  cred)
static

Definition at line 280 of file kern_priv.c.

References priv_check_cred_post(), priv_check_cred_pre(), and suser_enabled().

Referenced by priv_check_cred_vfs_lookup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SDT_PROBE_DEFINE1() [1/2]

SDT_PROBE_DEFINE1 ( priv  ,
kernel  ,
priv_check  ,
priv__err  ,
"int"   
)

◆ SDT_PROBE_DEFINE1() [2/2]

SDT_PROBE_DEFINE1 ( priv  ,
kernel  ,
priv_check  ,
priv__ok  ,
"int"   
)

◆ SDT_PROVIDER_DEFINE()

SDT_PROVIDER_DEFINE ( priv  )

◆ suser_enabled()

static bool suser_enabled ( struct ucred *  cred)
static

Definition at line 63 of file kern_priv.c.

References prison_allow().

Referenced by priv_check_cred(), priv_check_cred_vfs_generation(), priv_check_cred_vfs_generation_slow(), priv_check_cred_vfs_lookup(), priv_check_cred_vfs_lookup_nomac(), priv_check_cred_vfs_lookup_slow(), and sysctl_kern_suser_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _security_bsd  ,
OID_AUTO  ,
unprivileged_mlock  ,
CTLFLAG_RWTUN  ,
unprivileged_mlock,
,
"Allow non-root users to call mlock(2)"   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _security_bsd  ,
OID_AUTO  ,
unprivileged_read_msgbuf  ,
CTLFLAG_RW  ,
unprivileged_read_msgbuf,
,
"Unprivileged processes may read the kernel message buffer"   
)

◆ sysctl_kern_suser_enabled()

static int sysctl_kern_suser_enabled ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 70 of file kern_priv.c.

References prison_set_allow(), suser_enabled(), and sysctl_handle_int().

Here is the call graph for this function:

◆ SYSCTL_PROC()

SYSCTL_PROC ( _security_bsd  ,
OID_AUTO  ,
suser_enabled  ,
CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_PRISON|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_suser_enabled,
"I"  ,
"Processes with uid 0 have privilege"   
)

Variable Documentation

◆ unprivileged_mlock

int unprivileged_mlock = 1
static

Definition at line 88 of file kern_priv.c.

Referenced by priv_check_cred().

◆ unprivileged_read_msgbuf

int unprivileged_read_msgbuf = 1
static

Definition at line 92 of file kern_priv.c.

Referenced by priv_check_cred().