FreeBSD kernel kern code
imgact_elf.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_compat.h"
#include "opt_core.h"
#include <sys/param.h>
#include <sys/capability.h>
#include <sys/exec.h>
#include <sys/fcntl.h>
#include <sys/filedesc.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/mman.h>
#include <sys/namei.h>
#include <sys/pioctl.h>
#include <sys/proc.h>
#include <sys/procfs.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/sbuf.h>
#include <sys/sf_buf.h>
#include <sys/smp.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/syscall.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/vnode.h>
#include <sys/syslog.h>
#include <sys/eventhandler.h>
#include <sys/user.h>
#include <net/zlib.h>
#include <vm/vm.h>
#include <vm/vm_kern.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_extern.h>
#include <machine/elf.h>
#include <machine/md_var.h>
Include dependency graph for imgact_elf.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  phdr_closure
 
struct  sseg_closure
 
struct  note_info
 
struct  sbuf_drain_core_params
 

Macros

#define ELF_NOTE_ROUNDSIZE   4
 
#define OLD_EI_BRAND   8
 
#define CORE_BUF_SIZE   (16 * 1024)
 
#define trunc_page_ps(va, ps)   ((va) & ~(ps - 1))
 
#define round_page_ps(va, ps)   (((va) + (ps - 1)) & ~(ps - 1))
 
#define aligned(a, t)   (trunc_page_ps((u_long)(a), sizeof(t)) == (u_long)(a))
 
#define suword   __CONCAT(suword, __ELF_WORD_SIZE)
 
#define ELF_KERN_PROC_MASK   0
 

Typedefs

typedef void(* segment_callback) (vm_map_entry_t, void *)
 
typedef void(* outfunc_t) (void *, struct sbuf *, size_t *)
 
typedef prstatus_t elf_prstatus_t
 
typedef prpsinfo_t elf_prpsinfo_t
 
typedef prfpregset_t elf_prfpregset_t
 
typedef prfpregset_t elf_fpregset_t
 
typedef gregset_t elf_gregset_t
 
typedef thrmisc_t elf_thrmisc_t
 
typedef struct kinfo_proc elf_kinfo_proc_t
 
typedef vm_offset_t elf_ps_strings_t
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static int __elfN() check_header (const Elf_Ehdr *hdr)
 
static Elf_Brandinfo *__elfN() get_brandinfo (struct image_params *imgp, const char *interp, int interp_name_len, int32_t *osrel)
 
static int __elfN() load_file (struct proc *p, const char *file, u_long *addr, u_long *entry, size_t pagesize)
 
static int __elfN() load_section (struct vmspace *vmspace, vm_object_t object, vm_offset_t offset, caddr_t vmaddr, size_t memsz, size_t filsz, vm_prot_t prot, size_t pagesize)
 
static int __CONCAT (exec_, __elfN(imgact))
 
static boolean_t __elfN() bsdsunix_trans_osrel (const Elf_Note *note, int32_t *osrel)
 
Elf_Brandnote __elfN (kbsdsunix_brandnote)
 
static boolean_t kbsdsunix_trans_osrel (const Elf_Note *note, int32_t *osrel)
 
int __elfN() insert_brand_entry (Elf_Brandinfo *entry)
 
int __elfN() remove_brand_entry (Elf_Brandinfo *entry)
 
int __elfN() brand_inuse (Elf_Brandinfo *entry)
 
static int __elfN() map_partial (vm_map_t map, vm_object_t object, vm_ooffset_t offset, vm_offset_t start, vm_offset_t end, vm_prot_t prot)
 
static int __elfN() map_insert (vm_map_t map, vm_object_t object, vm_ooffset_t offset, vm_offset_t start, vm_offset_t end, vm_prot_t prot, int cow)
 
int __elfN() bsdsunix_fixup (register_t **stack_base, struct image_params *imgp)
 
 TAILQ_HEAD (note_info_list, note_info)
 
static void cb_put_phdr (vm_map_entry_t, void *)
 
static void cb_size_segment (vm_map_entry_t, void *)
 
static void each_writable_segment (struct thread *, segment_callback, void *)
 
static int __elfN() corehdr (struct thread *, struct vnode *, struct ucred *, int, void *, size_t, struct note_info_list *, size_t, gzFile)
 
static void __elfN() prepare_notes (struct thread *, struct note_info_list *, size_t *)
 
static void __elfN() puthdr (struct thread *, void *, size_t, int, size_t)
 
static void __elfN() putnote (struct note_info *, struct sbuf *)
 
static size_t register_note (struct note_info_list *, int, outfunc_t, void *)
 
static int sbuf_drain_core_output (void *, const char *, int)
 
static int sbuf_drain_count (void *arg, const char *data, int len)
 
static void __elfN() note_fpregset (void *, struct sbuf *, size_t *)
 
static void __elfN() note_prpsinfo (void *, struct sbuf *, size_t *)
 
static void __elfN() note_prstatus (void *, struct sbuf *, size_t *)
 
static void __elfN() note_threadmd (void *, struct sbuf *, size_t *)
 
static void __elfN() note_thrmisc (void *, struct sbuf *, size_t *)
 
static void __elfN() note_procstat_auxv (void *, struct sbuf *, size_t *)
 
static void __elfN() note_procstat_proc (void *, struct sbuf *, size_t *)
 
static void __elfN() note_procstat_psstrings (void *, struct sbuf *, size_t *)
 
static void note_procstat_files (void *, struct sbuf *, size_t *)
 
static void note_procstat_groups (void *, struct sbuf *, size_t *)
 
static void note_procstat_osrel (void *, struct sbuf *, size_t *)
 
static void note_procstat_rlimit (void *, struct sbuf *, size_t *)
 
static void note_procstat_umask (void *, struct sbuf *, size_t *)
 
static void note_procstat_vmmap (void *, struct sbuf *, size_t *)
 
static int core_output (struct vnode *vp, void *base, size_t len, off_t offset, struct ucred *active_cred, struct ucred *file_cred, struct thread *td, char *core_buf, gzFile gzfile)
 
static int sbuf_drain_count (void *arg, const char *data __unused, int len)
 
int __elfN() coredump (struct thread *td, struct vnode *vp, off_t limit, int flags)
 
static boolean_t __elfN() parse_notes (struct image_params *imgp, Elf_Brandnote *checknote, int32_t *osrel, const Elf_Phdr *pnote)
 
static boolean_t __elfN() check_note (struct image_params *imgp, Elf_Brandnote *checknote, int32_t *osrel)
 
static struct execsw __elfN (execsw)
 
 EXEC_SET (__CONCAT(elf, __ELF_WORD_SIZE), __elfN(execsw))
 
static vm_prot_t __elfN() trans_prot (Elf_Word flags)
 
static Elf_Word __elfN() untrans_prot (vm_prot_t prot)
 

Variables

static const char GNU_ABI_VENDOR [] = "GNU"
 
static int GNU_KBSDSUNIX_ABI_DESC = 3
 

Macro Definition Documentation

#define aligned (   a,
 
)    (trunc_page_ps((u_long)(a), sizeof(t)) == (u_long)(a))

Referenced by load_file(), and parse_notes().

#define CORE_BUF_SIZE   (16 * 1024)

Referenced by coredump(), and corehdr().

#define ELF_KERN_PROC_MASK   0

Definition at line 1637 of file imgact_elf.c.

Referenced by note_procstat_proc().

#define ELF_NOTE_ROUNDSIZE   4
#define OLD_EI_BRAND   8

Definition at line 86 of file imgact_elf.c.

Referenced by get_brandinfo().

#define round_page_ps (   va,
  ps 
)    (((va) + (ps - 1)) & ~(ps - 1))

Referenced by load_section().

#define trunc_page_ps (   va,
  ps 
)    ((va) & ~(ps - 1))

Referenced by load_section().

Typedef Documentation

typedef prfpregset_t elf_fpregset_t

Definition at line 1634 of file imgact_elf.c.

typedef gregset_t elf_gregset_t

Definition at line 1635 of file imgact_elf.c.

typedef struct kinfo_proc elf_kinfo_proc_t

Definition at line 1638 of file imgact_elf.c.

typedef prfpregset_t elf_prfpregset_t

Definition at line 1633 of file imgact_elf.c.

typedef prpsinfo_t elf_prpsinfo_t

Definition at line 1632 of file imgact_elf.c.

typedef prstatus_t elf_prstatus_t

Definition at line 1631 of file imgact_elf.c.

typedef vm_offset_t elf_ps_strings_t

Definition at line 1639 of file imgact_elf.c.

typedef thrmisc_t elf_thrmisc_t

Definition at line 1636 of file imgact_elf.c.

typedef void(* outfunc_t) (void *, struct sbuf *, size_t *)

Definition at line 1047 of file imgact_elf.c.

typedef void(* segment_callback) (vm_map_entry_t, void *)

Definition at line 1033 of file imgact_elf.c.

Function Documentation

static int __CONCAT ( exec_  ,
__elfN(imgact)   
)
static

Definition at line 96 of file imgact_elf.c.

Elf_Brandnote __elfN ( kbsdsunix_brandnote  )
static struct execsw __elfN ( execsw  )
static
__FBSDID ( "$BSDSUniX$"  )
int __elfN() brand_inuse ( Elf_Brandinfo *  entry)

Definition at line 242 of file imgact_elf.c.

References allproc_lock.

int __elfN() bsdsunix_fixup ( register_t **  stack_base,
struct image_params *  imgp 
)

Definition at line 981 of file imgact_elf.c.

References free(), mp_ncpus, and suword.

Here is the call graph for this function:

static boolean_t __elfN() bsdsunix_trans_osrel ( const Elf_Note *  note,
int32_t *  osrel 
)
static

Definition at line 161 of file imgact_elf.c.

References ELF_NOTE_ROUNDSIZE.

static void cb_put_phdr ( vm_map_entry_t  entry,
void *  closure 
)
static

Definition at line 1303 of file imgact_elf.c.

References __elfN(), phdr_closure::offset, phdr_closure::phdr, and untrans_prot().

Referenced by puthdr().

Here is the call graph for this function:

Here is the caller graph for this function:

static void cb_size_segment ( vm_map_entry_t  entry,
void *  closure 
)
static

Definition at line 1329 of file imgact_elf.c.

References sseg_closure::count, and sseg_closure::size.

Referenced by coredump().

Here is the caller graph for this function:

static int __elfN() check_header ( const Elf_Ehdr *  hdr)
static

Definition at line 328 of file imgact_elf.c.

Referenced by load_file().

Here is the caller graph for this function:

static boolean_t __elfN() check_note ( struct image_params *  imgp,
Elf_Brandnote *  checknote,
int32_t *  osrel 
)
static

Definition at line 2027 of file imgact_elf.c.

References __elfN(), and parse_notes().

Referenced by get_brandinfo().

Here is the call graph for this function:

Here is the caller graph for this function:

static int core_output ( struct vnode *  vp,
void *  base,
size_t  len,
off_t  offset,
struct ucred *  active_cred,
struct ucred *  file_cred,
struct thread *  td,
char *  core_buf,
gzFile  gzfile 
)
static

Definition at line 1093 of file imgact_elf.c.

References panic(), and vn_rdwr_inchunks().

Referenced by coredump().

Here is the call graph for this function:

Here is the caller graph for this function:

int __elfN() coredump ( struct thread *  td,
struct vnode *  vp,
off_t  limit,
int  flags 
)

Definition at line 1178 of file imgact_elf.c.

References __elfN(), cb_size_segment(), CORE_BUF_SIZE, core_output(), corehdr(), sseg_closure::count, each_writable_segment(), free(), gz_open(), gzclose(), log(), malloc(), prepare_notes(), racct_add(), and sseg_closure::size.

Referenced by doadump().

Here is the call graph for this function:

Here is the caller graph for this function:

static int __elfN() corehdr ( struct thread *  td,
struct vnode *  vp,
struct ucred *  cred,
int  numsegs,
void *  hdr,
size_t  hdrsize,
struct note_info_list *  notelst,
size_t  notesz,
gzFile  gzfile 
)
static
static void each_writable_segment ( struct thread *  td,
segment_callback  func,
void *  closure 
)
static

Definition at line 1345 of file imgact_elf.c.

Referenced by coredump(), and puthdr().

Here is the caller graph for this function:

EXEC_SET ( __CONCAT(elf, __ELF_WORD_SIZE ,
__elfN(execsw  
)
static Elf_Brandinfo* __elfN() get_brandinfo ( struct image_params *  imgp,
const char *  interp,
int  interp_name_len,
int32_t *  osrel 
)
static

Definition at line 260 of file imgact_elf.c.

References __elfN(), check_note(), and OLD_EI_BRAND.

Here is the call graph for this function:

int __elfN() insert_brand_entry ( Elf_Brandinfo *  entry)

Definition at line 207 of file imgact_elf.c.

References printf().

Here is the call graph for this function:

static boolean_t kbsdsunix_trans_osrel ( const Elf_Note *  note,
int32_t *  osrel 
)
static

Definition at line 185 of file imgact_elf.c.

References ELF_NOTE_ROUNDSIZE.

static int __elfN() load_file ( struct proc *  p,
const char *  file,
u_long *  addr,
u_long *  entry,
size_t  pagesize 
)
static
static int __elfN() load_section ( struct vmspace *  vmspace,
vm_object_t  object,
vm_offset_t  offset,
caddr_t  vmaddr,
size_t  memsz,
size_t  filsz,
vm_prot_t  prot,
size_t  pagesize 
)
static

Definition at line 460 of file imgact_elf.c.

References __elfN(), map_insert(), round_page_ps, trunc_page_ps, and uprintf().

Referenced by load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int __elfN() map_insert ( vm_map_t  map,
vm_object_t  object,
vm_ooffset_t  offset,
vm_offset_t  start,
vm_offset_t  end,
vm_prot_t  prot,
int  cow 
)
static

Definition at line 392 of file imgact_elf.c.

References __elfN(), map_partial(), and start.

Referenced by load_section().

Here is the call graph for this function:

Here is the caller graph for this function:

static int __elfN() map_partial ( vm_map_t  map,
vm_object_t  object,
vm_ooffset_t  offset,
vm_offset_t  start,
vm_offset_t  end,
vm_prot_t  prot 
)
static

Definition at line 357 of file imgact_elf.c.

Referenced by map_insert().

Here is the caller graph for this function:

static void __elfN() note_fpregset ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1697 of file imgact_elf.c.

References free(), malloc(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_procstat_auxv ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1947 of file imgact_elf.c.

References proc_getauxv(), sbuf_bcat(), sbuf_delete(), sbuf_drain_count(), sbuf_finish(), sbuf_new(), and sbuf_set_drain().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_files ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1789 of file imgact_elf.c.

References kern_proc_filedesc_out(), sbuf_bcat(), sbuf_delete(), sbuf_drain_count(), sbuf_finish(), sbuf_new(), and sbuf_set_drain().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_groups ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1845 of file imgact_elf.c.

References sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_osrel ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1905 of file imgact_elf.c.

References sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_procstat_proc ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1764 of file imgact_elf.c.

References ELF_KERN_PROC_MASK, kern_proc_out(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_procstat_psstrings ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1923 of file imgact_elf.c.

References sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_rlimit ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1882 of file imgact_elf.c.

References lim_rlimit(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_umask ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1864 of file imgact_elf.c.

References sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void note_procstat_vmmap ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1819 of file imgact_elf.c.

References kern_proc_vmmap_out(), sbuf_bcat(), sbuf_delete(), sbuf_drain_count(), sbuf_finish(), sbuf_new(), and sbuf_set_drain().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_prpsinfo ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1643 of file imgact_elf.c.

References free(), malloc(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_prstatus ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1669 of file imgact_elf.c.

References free(), malloc(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_threadmd ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1738 of file imgact_elf.c.

References __elfN(), buf, free(), malloc(), and sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() note_thrmisc ( void *  arg,
struct sbuf *  sb,
size_t *  sizep 
)
static

Definition at line 1718 of file imgact_elf.c.

References sbuf_bcat().

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

static boolean_t __elfN() parse_notes ( struct image_params *  imgp,
Elf_Brandnote *  checknote,
int32_t *  osrel,
const Elf_Phdr *  pnote 
)
static

Definition at line 1975 of file imgact_elf.c.

References aligned, and ELF_NOTE_ROUNDSIZE.

Referenced by check_note().

Here is the caller graph for this function:

static void __elfN() prepare_notes ( struct thread *  td,
struct note_info_list *  list,
size_t *  sizep 
)
static
static void __elfN() puthdr ( struct thread *  td,
void *  hdr,
size_t  hdrsize,
int  numsegs,
size_t  notesz 
)
static

Definition at line 1505 of file imgact_elf.c.

References cb_put_phdr(), each_writable_segment(), ELF_NOTE_ROUNDSIZE, phdr_closure::offset, and phdr_closure::phdr.

Referenced by corehdr().

Here is the call graph for this function:

Here is the caller graph for this function:

static void __elfN() putnote ( struct note_info ninfo,
struct sbuf *  sb 
)
static

Definition at line 1589 of file imgact_elf.c.

References ELF_NOTE_ROUNDSIZE, note_info::outarg, note_info::outfunc, note_info::outsize, sbuf_bcat(), sbuf_end_section(), sbuf_start_section(), and note_info::type.

Referenced by corehdr().

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t register_note ( struct note_info_list *  list,
int  type,
outfunc_t  out,
void *  arg 
)
static

Definition at line 1564 of file imgact_elf.c.

References ELF_NOTE_ROUNDSIZE, malloc(), note_info::outarg, note_info::outfunc, note_info::outsize, and note_info::type.

Referenced by prepare_notes().

Here is the call graph for this function:

Here is the caller graph for this function:

int __elfN() remove_brand_entry ( Elf_Brandinfo *  entry)

Definition at line 226 of file imgact_elf.c.

static int sbuf_drain_core_output ( void *  arg,
const char *  data,
int  len 
)
static

Definition at line 1128 of file imgact_elf.c.

References sbuf_drain_core_params::active_cred, sbuf_drain_core_params::file_cred, sbuf_drain_core_params::offset, sbuf_drain_core_params::td, vn_rdwr_inchunks(), and sbuf_drain_core_params::vp.

Referenced by corehdr().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sbuf_drain_count ( void *  arg,
const char *  data,
int  len 
)
static

Referenced by note_procstat_auxv(), note_procstat_files(), and note_procstat_vmmap().

Here is the caller graph for this function:

static int sbuf_drain_count ( void *  arg,
const char *data  __unused,
int  len 
)
static

Definition at line 1168 of file imgact_elf.c.

TAILQ_HEAD ( note_info_list  ,
note_info   
)

Referenced by turnstile_unpend().

Here is the caller graph for this function:

static vm_prot_t __elfN() trans_prot ( Elf_Word  flags)
static

Definition at line 2108 of file imgact_elf.c.

Referenced by load_file().

Here is the caller graph for this function:

static Elf_Word __elfN() untrans_prot ( vm_prot_t  prot)
static

Definition at line 2129 of file imgact_elf.c.

Referenced by cb_put_phdr().

Here is the caller graph for this function:

Variable Documentation

const char GNU_ABI_VENDOR[] = "GNU"
static

Definition at line 172 of file imgact_elf.c.

int GNU_KBSDSUNIX_ABI_DESC = 3
static

Definition at line 173 of file imgact_elf.c.