FreeBSD kernel kern code
imgact_binmisc.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/ctype.h>
#include <sys/exec.h>
#include <sys/imgact.h>
#include <sys/imgact_binmisc.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <machine/atomic.h>
Include dependency graph for imgact_binmisc.c:

Go to the source code of this file.

Data Structures

struct  imgact_binmisc_entry
 

Macros

#define IBC_ADD   1 /* Add given entry. */
 
#define IBC_REMOVE   2 /* Remove entry for a given name. */
 
#define IBC_DISABLE   3 /* Disable entry for a given name. */
 
#define IBC_ENABLE   4 /* Enable entry for a given name. */
 
#define IBC_LOOKUP   5 /* Lookup and return entry for given name. */
 
#define IBC_LIST   6 /* Get a snapshot of the interpretor list. */
 
#define ISM_POUND   '#' /* "##" is the escape sequence for single #. */
 
#define ISM_OLD_ARGV0   'a' /* "#a" is replaced with the old argv0. */
 
#define INTERP_LIST_WLOCK()   sx_xlock(&interp_list_sx)
 
#define INTERP_LIST_RLOCK()   sx_slock(&interp_list_sx)
 
#define INTERP_LIST_WUNLOCK()   sx_xunlock(&interp_list_sx)
 
#define INTERP_LIST_RUNLOCK()   sx_sunlock(&interp_list_sx)
 
#define INTERP_LIST_LOCK_INIT()   sx_init(&interp_list_sx, KMOD_NAME)
 
#define INTERP_LIST_LOCK_DESTROY()   sx_destroy(&interp_list_sx)
 
#define INTERP_LIST_ASSERT_LOCKED()   sx_assert(&interp_list_sx, SA_LOCKED)
 

Typedefs

typedef struct imgact_binmisc_entry imgact_binmisc_entry_t
 

Functions

 __FBSDID ("$FreeBSD$")
 
 MALLOC_DEFINE (M_BINMISC, KMOD_NAME, "misc binary image activator")
 
static SLIST_HEAD (imgact_binmisc_entry)
 
static imgact_binmisc_entry_timgact_binmisc_new_entry (ximgact_binmisc_entry_t *xbe, ssize_t interp_offset, int argv0_cnt)
 
static void imgact_binmisc_destroy_entry (imgact_binmisc_entry_t *ibe)
 
static imgact_binmisc_entry_timgact_binmisc_find_entry (char *name)
 
static int imgact_binmisc_add_entry (ximgact_binmisc_entry_t *xbe)
 
static int imgact_binmisc_remove_entry (char *name)
 
static int imgact_binmisc_disable_entry (char *name)
 
static int imgact_binmisc_enable_entry (char *name)
 
static int imgact_binmisc_populate_xbe (ximgact_binmisc_entry_t *xbe, imgact_binmisc_entry_t *ibe)
 
static int imgact_binmisc_lookup_entry (char *name, ximgact_binmisc_entry_t *xbe)
 
static int imgact_binmisc_get_all_entries (struct sysctl_req *req)
 
static int sysctl_kern_binmisc (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_NODE (_kern, OID_AUTO, binmisc, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Image activator for miscellaneous binaries")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, add, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_WR, NULL, IBC_ADD, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Add an activator entry")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, remove, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_WR, NULL, IBC_REMOVE, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Remove an activator entry")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, disable, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_WR, NULL, IBC_DISABLE, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Disable an activator entry")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, enable, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_WR, NULL, IBC_ENABLE, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Enable an activator entry")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, lookup, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_RW|CTLFLAG_ANYBODY, NULL, IBC_LOOKUP, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Lookup an activator entry")
 
 SYSCTL_PROC (_kern_binmisc, OID_AUTO, list, CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_RD|CTLFLAG_ANYBODY, NULL, IBC_LIST, sysctl_kern_binmisc, "S,ximgact_binmisc_entry", "Get snapshot of all the activator entries")
 
static imgact_binmisc_entry_timgact_binmisc_find_interpreter (const char *image_header)
 
static int imgact_binmisc_exec (struct image_params *imgp)
 
static void imgact_binmisc_init (void *arg)
 
static void imgact_binmisc_fini (void *arg)
 
 SYSINIT (imgact_binmisc, SI_SUB_EXEC, SI_ORDER_MIDDLE, imgact_binmisc_init, NULL)
 
 SYSUNINIT (imgact_binmisc, SI_SUB_EXEC, SI_ORDER_MIDDLE, imgact_binmisc_fini, NULL)
 
 EXEC_SET (imgact_binmisc, imgact_binmisc_execsw)
 

Variables

static struct execsw imgact_binmisc_execsw
 

Macro Definition Documentation

◆ IBC_ADD

#define IBC_ADD   1 /* Add given entry. */

Definition at line 78 of file imgact_binmisc.c.

◆ IBC_DISABLE

#define IBC_DISABLE   3 /* Disable entry for a given name. */

Definition at line 80 of file imgact_binmisc.c.

◆ IBC_ENABLE

#define IBC_ENABLE   4 /* Enable entry for a given name. */

Definition at line 81 of file imgact_binmisc.c.

◆ IBC_LIST

#define IBC_LIST   6 /* Get a snapshot of the interpretor list. */

Definition at line 83 of file imgact_binmisc.c.

◆ IBC_LOOKUP

#define IBC_LOOKUP   5 /* Lookup and return entry for given name. */

Definition at line 82 of file imgact_binmisc.c.

◆ IBC_REMOVE

#define IBC_REMOVE   2 /* Remove entry for a given name. */

Definition at line 79 of file imgact_binmisc.c.

◆ INTERP_LIST_ASSERT_LOCKED

#define INTERP_LIST_ASSERT_LOCKED ( )    sx_assert(&interp_list_sx, SA_LOCKED)

◆ INTERP_LIST_LOCK_DESTROY

#define INTERP_LIST_LOCK_DESTROY ( )    sx_destroy(&interp_list_sx)

◆ INTERP_LIST_LOCK_INIT

#define INTERP_LIST_LOCK_INIT ( )    sx_init(&interp_list_sx, KMOD_NAME)

◆ INTERP_LIST_RLOCK

#define INTERP_LIST_RLOCK ( )    sx_slock(&interp_list_sx)

◆ INTERP_LIST_RUNLOCK

#define INTERP_LIST_RUNLOCK ( )    sx_sunlock(&interp_list_sx)

◆ INTERP_LIST_WLOCK

#define INTERP_LIST_WLOCK ( )    sx_xlock(&interp_list_sx)

◆ INTERP_LIST_WUNLOCK

#define INTERP_LIST_WUNLOCK ( )    sx_xunlock(&interp_list_sx)

◆ ISM_OLD_ARGV0

#define ISM_OLD_ARGV0   'a' /* "#a" is replaced with the old argv0. */

Definition at line 91 of file imgact_binmisc.c.

◆ ISM_POUND

#define ISM_POUND   '#' /* "##" is the escape sequence for single #. */

Definition at line 90 of file imgact_binmisc.c.

Typedef Documentation

◆ imgact_binmisc_entry_t

Miscellaneous binary interpreter image activator.

If the given target executable's header matches 'xbe_magic' field in the 'interpreter_list' then it will use the user-level interpreter specified in the 'xbe_interpreter' field to execute the binary. The 'xbe_magic' field may be adjusted to a given offset using the value in the 'xbe_moffset' field and bits of the header may be masked using the 'xbe_mask' field. The 'interpreter_list' entries are managed using sysctl(3) as described in the <sys/imgact_binmisc.h> file.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ EXEC_SET()

EXEC_SET ( imgact_binmisc  ,
imgact_binmisc_execsw   
)

◆ imgact_binmisc_add_entry()

static int imgact_binmisc_add_entry ( ximgact_binmisc_entry_t *  xbe)
static

Definition at line 230 of file imgact_binmisc.c.

References imgact_binmisc_find_entry(), imgact_binmisc_new_entry(), INTERP_LIST_WLOCK, INTERP_LIST_WUNLOCK, ISM_OLD_ARGV0, and ISM_POUND.

Referenced by sysctl_kern_binmisc().

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

◆ imgact_binmisc_destroy_entry()

static void imgact_binmisc_destroy_entry ( imgact_binmisc_entry_t ibe)
static

Definition at line 190 of file imgact_binmisc.c.

References free().

Referenced by imgact_binmisc_fini(), and imgact_binmisc_remove_entry().

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

◆ imgact_binmisc_disable_entry()

static int imgact_binmisc_disable_entry ( char *  name)
static

Definition at line 318 of file imgact_binmisc.c.

References imgact_binmisc_find_entry(), INTERP_LIST_WLOCK, INTERP_LIST_WUNLOCK, and name.

Referenced by sysctl_kern_binmisc().

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

◆ imgact_binmisc_enable_entry()

static int imgact_binmisc_enable_entry ( char *  name)
static

Definition at line 339 of file imgact_binmisc.c.

References imgact_binmisc_find_entry(), INTERP_LIST_WLOCK, INTERP_LIST_WUNLOCK, and name.

Referenced by sysctl_kern_binmisc().

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

◆ imgact_binmisc_exec()

static int imgact_binmisc_exec ( struct image_params *  imgp)
static

◆ imgact_binmisc_find_entry()

static imgact_binmisc_entry_t * imgact_binmisc_find_entry ( char *  name)
static

◆ imgact_binmisc_find_interpreter()

static imgact_binmisc_entry_t * imgact_binmisc_find_interpreter ( const char *  image_header)
static

Definition at line 556 of file imgact_binmisc.c.

References INTERP_LIST_ASSERT_LOCKED.

Referenced by imgact_binmisc_exec().

Here is the caller graph for this function:

◆ imgact_binmisc_fini()

static void imgact_binmisc_fini ( void *  arg)
static

Definition at line 717 of file imgact_binmisc.c.

References imgact_binmisc_destroy_entry(), INTERP_LIST_LOCK_DESTROY, INTERP_LIST_WLOCK, and INTERP_LIST_WUNLOCK.

Here is the call graph for this function:

◆ imgact_binmisc_get_all_entries()

static int imgact_binmisc_get_all_entries ( struct sysctl_req *  req)
static

Definition at line 408 of file imgact_binmisc.c.

References count, free(), imgact_binmisc_populate_xbe(), INTERP_LIST_RLOCK, INTERP_LIST_RUNLOCK, and malloc().

Referenced by sysctl_kern_binmisc().

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

◆ imgact_binmisc_init()

static void imgact_binmisc_init ( void *  arg)
static

Definition at line 710 of file imgact_binmisc.c.

References INTERP_LIST_LOCK_INIT.

◆ imgact_binmisc_lookup_entry()

static int imgact_binmisc_lookup_entry ( char *  name,
ximgact_binmisc_entry_t *  xbe 
)
static

Definition at line 387 of file imgact_binmisc.c.

References imgact_binmisc_find_entry(), imgact_binmisc_populate_xbe(), INTERP_LIST_RLOCK, INTERP_LIST_RUNLOCK, and name.

Referenced by sysctl_kern_binmisc().

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

◆ imgact_binmisc_new_entry()

static imgact_binmisc_entry_t * imgact_binmisc_new_entry ( ximgact_binmisc_entry_t *  xbe,
ssize_t  interp_offset,
int  argv0_cnt 
)
static

Definition at line 159 of file imgact_binmisc.c.

References malloc().

Referenced by imgact_binmisc_add_entry().

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

◆ imgact_binmisc_populate_xbe()

static int imgact_binmisc_populate_xbe ( ximgact_binmisc_entry_t *  xbe,
imgact_binmisc_entry_t ibe 
)
static

Definition at line 356 of file imgact_binmisc.c.

References INTERP_LIST_ASSERT_LOCKED.

Referenced by imgact_binmisc_get_all_entries(), and imgact_binmisc_lookup_entry().

Here is the caller graph for this function:

◆ imgact_binmisc_remove_entry()

static int imgact_binmisc_remove_entry ( char *  name)
static

Definition at line 295 of file imgact_binmisc.c.

References imgact_binmisc_destroy_entry(), imgact_binmisc_find_entry(), INTERP_LIST_WLOCK, INTERP_LIST_WUNLOCK, and name.

Referenced by sysctl_kern_binmisc().

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

◆ MALLOC_DEFINE()

MALLOC_DEFINE ( M_BINMISC  ,
KMOD_NAME  ,
"misc binary image activator"   
)

◆ SLIST_HEAD()

static SLIST_HEAD ( imgact_binmisc_entry  )
static

Definition at line 96 of file imgact_binmisc.c.

◆ sysctl_kern_binmisc()

static int sysctl_kern_binmisc ( SYSCTL_HANDLER_ARGS  )
static

◆ SYSCTL_NODE()

SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
binmisc  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"Image activator for miscellaneous binaries"   
)

◆ SYSCTL_PROC() [1/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
add  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|  CTLFLAG_WR,
NULL  ,
IBC_ADD  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Add an activator entry"   
)

◆ SYSCTL_PROC() [2/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
disable  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|  CTLFLAG_WR,
NULL  ,
IBC_DISABLE  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Disable an activator entry"   
)

◆ SYSCTL_PROC() [3/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
enable  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|  CTLFLAG_WR,
NULL  ,
IBC_ENABLE  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Enable an activator entry"   
)

◆ SYSCTL_PROC() [4/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
list  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_RD|  CTLFLAG_ANYBODY,
NULL  ,
IBC_LIST  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Get snapshot of all the activator entries"   
)

◆ SYSCTL_PROC() [5/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
lookup  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|CTLFLAG_RW|  CTLFLAG_ANYBODY,
NULL  ,
IBC_LOOKUP  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Lookup an activator entry"   
)

◆ SYSCTL_PROC() [6/6]

SYSCTL_PROC ( _kern_binmisc  ,
OID_AUTO  ,
remove  ,
CTLFLAG_MPSAFE|CTLTYPE_STRUCT|  CTLFLAG_WR,
NULL  ,
IBC_REMOVE  ,
sysctl_kern_binmisc  ,
S,
ximgact_binmisc_entry"  ,
"Remove an activator entry"   
)

◆ SYSINIT()

SYSINIT ( imgact_binmisc  ,
SI_SUB_EXEC  ,
SI_ORDER_MIDDLE  ,
imgact_binmisc_init  ,
NULL   
)

◆ SYSUNINIT()

SYSUNINIT ( imgact_binmisc  ,
SI_SUB_EXEC  ,
SI_ORDER_MIDDLE  ,
imgact_binmisc_fini  ,
NULL   
)

Variable Documentation

◆ imgact_binmisc_execsw

struct execsw imgact_binmisc_execsw
static
Initial value:
= {
.ex_imgact = imgact_binmisc_exec,
.ex_name = KMOD_NAME
}
static int imgact_binmisc_exec(struct image_params *imgp)

Definition at line 741 of file imgact_binmisc.c.