FreeBSD kernel kern code
vfs_lookup.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/dirent.h>
#include <sys/kernel.h>
#include <sys/capsicum.h>
#include <sys/fcntl.h>
#include <sys/jail.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/filedesc.h>
#include <sys/proc.h>
#include <sys/sdt.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
#include <vm/uma.h>
Include dependency graph for vfs_lookup.c:

Go to the source code of this file.

Data Structures

struct  nameicap_tracker
 

Macros

#define NAMEI_DIAGNOSTIC   1
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SDT_PROVIDER_DEFINE (vfs)
 
 SDT_PROBE_DEFINE4 (vfs, namei, lookup, entry, "struct vnode *", "char *", "unsigned long", "bool")
 
 SDT_PROBE_DEFINE4 (vfs, namei, lookup, return, "int", "struct vnode *", "bool", "struct nameidata")
 
static int crossmp_vop_islocked (struct vop_islocked_args *ap)
 
static int crossmp_vop_lock1 (struct vop_lock1_args *ap)
 
static int crossmp_vop_unlock (struct vop_unlock_args *ap)
 
 MALLOC_DEFINE (M_NAMEITRACKER, "namei_tracker", "namei tracking for dotdot")
 
static void nameiinit (void *dummy __unused)
 
 SYSINIT (vfs, SI_SUB_VFS, SI_ORDER_SECOND, nameiinit, NULL)
 
 SYSCTL_INT (_vfs, OID_AUTO, lookup_cap_dotdot, CTLFLAG_RWTUN, &lookup_cap_dotdot, 0, "enables \"..\" components in path lookup in capability mode")
 
 SYSCTL_INT (_vfs, OID_AUTO, lookup_cap_dotdot_nonlocal, CTLFLAG_RWTUN, &lookup_cap_dotdot_nonlocal, 0, "enables \"..\" components in path lookup in capability mode " "on non-local mount")
 
static void nameicap_tracker_add (struct nameidata *ndp, struct vnode *dp)
 
static void nameicap_cleanup_from (struct nameidata *ndp, struct nameicap_tracker *first)
 
static void nameicap_cleanup (struct nameidata *ndp)
 
static int nameicap_check_dotdot (struct nameidata *ndp, struct vnode *dp)
 
static void namei_cleanup_cnp (struct componentname *cnp)
 
static int namei_handle_root (struct nameidata *ndp, struct vnode **dpp)
 
static int namei_setup (struct nameidata *ndp, struct vnode **dpp, struct pwd **pwdp)
 
static int namei_getpath (struct nameidata *ndp)
 
static int namei_emptypath (struct nameidata *ndp)
 
int namei (struct nameidata *ndp)
 
static int compute_cn_lkflags (struct mount *mp, int lkflags, int cnflags)
 
static __inline int needs_exclusive_leaf (struct mount *mp, int flags)
 
 _Static_assert (MAXNAMLEN==NAME_MAX, "MAXNAMLEN and NAME_MAX have different values")
 
int vfs_lookup (struct nameidata *ndp)
 
int vfs_relookup (struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
 
void NDFREE_PNBUF (struct nameidata *ndp)
 
void() NDFREE (struct nameidata *ndp, const u_int flags)
 
int kern_alternate_path (const char *prefix, const char *path, enum uio_seg pathseg, char **pathbuf, int create, int dirfd)
 

Variables

uma_zone_t namei_zone
 
static struct vnode * vp_crossmp
 
static struct vop_vector crossmp_vnodeops
 
static int lookup_cap_dotdot = 1
 
static int lookup_cap_dotdot_nonlocal = 1
 

Macro Definition Documentation

◆ NAMEI_DIAGNOSTIC

#define NAMEI_DIAGNOSTIC   1

Definition at line 74 of file vfs_lookup.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _Static_assert()

_Static_assert ( MAXNAMLEN  = =NAME_MAX,
"MAXNAMLEN and NAME_MAX have different values"   
)

◆ compute_cn_lkflags()

static int compute_cn_lkflags ( struct mount *  mp,
int  lkflags,
int  cnflags 
)
static

Definition at line 755 of file vfs_lookup.c.

Referenced by vfs_lookup().

Here is the caller graph for this function:

◆ crossmp_vop_islocked()

static int crossmp_vop_islocked ( struct vop_islocked_args *  ap)
static

Definition at line 90 of file vfs_lookup.c.

◆ crossmp_vop_lock1()

static int crossmp_vop_lock1 ( struct vop_lock1_args *  ap)
static

Definition at line 97 of file vfs_lookup.c.

References flags, and panic().

Here is the call graph for this function:

◆ crossmp_vop_unlock()

static int crossmp_vop_unlock ( struct vop_unlock_args *  ap)
static

Definition at line 123 of file vfs_lookup.c.

◆ kern_alternate_path()

int kern_alternate_path ( const char *  prefix,
const char *  path,
enum uio_seg  pathseg,
char **  pathbuf,
int  create,
int  dirfd 
)

Definition at line 1674 of file vfs_lookup.c.

References buf, dirfd, free(), malloc(), namei(), NDFREE(), path, and vrele().

Here is the call graph for this function:

◆ MALLOC_DEFINE()

MALLOC_DEFINE ( M_NAMEITRACKER  ,
"namei_tracker"  ,
"namei tracking for dotdot"   
)

◆ namei()

◆ namei_cleanup_cnp()

static void namei_cleanup_cnp ( struct componentname *  cnp)
static

Definition at line 253 of file vfs_lookup.c.

References namei_zone.

Referenced by namei(), and namei_emptypath().

Here is the caller graph for this function:

◆ namei_emptypath()

static int namei_emptypath ( struct nameidata *  ndp)
static

Definition at line 471 of file vfs_lookup.c.

References namei(), namei_cleanup_cnp(), namei_setup(), pwd_drop(), and vput().

Referenced by namei().

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

◆ namei_getpath()

static int namei_getpath ( struct nameidata *  ndp)
static

Definition at line 443 of file vfs_lookup.c.

References namei_zone.

Referenced by namei().

Here is the caller graph for this function:

◆ namei_handle_root()

static int namei_handle_root ( struct nameidata *  ndp,
struct vnode **  dpp 
)
static

Definition at line 264 of file vfs_lookup.c.

References vrefact().

Referenced by namei(), and namei_setup().

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

◆ namei_setup()

static int namei_setup ( struct nameidata *  ndp,
struct vnode **  dpp,
struct pwd **  pwdp 
)
static

Definition at line 286 of file vfs_lookup.c.

References badfileops, fget_cap(), lookup_cap_dotdot, namei(), namei_handle_root(), pwd_drop(), pwd_hold(), vref(), vrefact(), and vrele().

Referenced by namei(), and namei_emptypath().

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

◆ nameicap_check_dotdot()

static int nameicap_check_dotdot ( struct nameidata *  ndp,
struct vnode *  dp 
)
static

Definition at line 226 of file vfs_lookup.c.

References nameicap_tracker::dp, lookup_cap_dotdot_nonlocal, and nameicap_cleanup_from().

Referenced by vfs_lookup().

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

◆ nameicap_cleanup()

static void nameicap_cleanup ( struct nameidata *  ndp)
static

Definition at line 207 of file vfs_lookup.c.

References nameicap_cleanup_from().

Referenced by namei().

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

◆ nameicap_cleanup_from()

static void nameicap_cleanup_from ( struct nameidata *  ndp,
struct nameicap_tracker first 
)
static

Definition at line 194 of file vfs_lookup.c.

References nameicap_tracker::dp, free(), and vdrop().

Referenced by nameicap_check_dotdot(), and nameicap_cleanup().

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

◆ nameicap_tracker_add()

static void nameicap_tracker_add ( struct nameidata *  ndp,
struct vnode *  dp 
)
static

Definition at line 178 of file vfs_lookup.c.

References nameicap_tracker::dp, malloc(), and vhold().

Referenced by vfs_lookup().

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

◆ nameiinit()

static void nameiinit ( void *dummy  __unused)
static

Definition at line 157 of file vfs_lookup.c.

References crossmp_vnodeops, getnewvnode(), namei_zone, and vp_crossmp.

Here is the call graph for this function:

◆ NDFREE()

◆ NDFREE_PNBUF()

void NDFREE_PNBUF ( struct nameidata *  ndp)

Definition at line 1517 of file vfs_lookup.c.

References namei_zone.

Referenced by NDFREE().

Here is the caller graph for this function:

◆ needs_exclusive_leaf()

static __inline int needs_exclusive_leaf ( struct mount *  mp,
int  flags 
)
static

Definition at line 768 of file vfs_lookup.c.

References flags.

Referenced by vfs_lookup().

Here is the caller graph for this function:

◆ SDT_PROBE_DEFINE4() [1/2]

SDT_PROBE_DEFINE4 ( vfs  ,
namei  ,
lookup  ,
entry  ,
"struct vnode *"  ,
"char *"  ,
"unsigned long"  ,
"bool"   
)

◆ SDT_PROBE_DEFINE4() [2/2]

SDT_PROBE_DEFINE4 ( vfs  ,
namei  ,
lookup  ,
return  ,
"int"  ,
"struct vnode *"  ,
"bool"  ,
"struct nameidata"   
)

◆ SDT_PROVIDER_DEFINE()

SDT_PROVIDER_DEFINE ( vfs  )

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _vfs  ,
OID_AUTO  ,
lookup_cap_dotdot  ,
CTLFLAG_RWTUN  ,
lookup_cap_dotdot,
,
"enables \"..\" components in path lookup in capability mode  
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _vfs  ,
OID_AUTO  ,
lookup_cap_dotdot_nonlocal  ,
CTLFLAG_RWTUN  ,
lookup_cap_dotdot_nonlocal,
,
"enables \"..\" components in path lookup in capability mode " "on non-local mount"   
)

◆ SYSINIT()

SYSINIT ( vfs  ,
SI_SUB_VFS  ,
SI_ORDER_SECOND  ,
nameiinit  ,
NULL   
)

◆ vfs_lookup()

int vfs_lookup ( struct nameidata *  ndp)

Definition at line 844 of file vfs_lookup.c.

References compute_cn_lkflags(), nameicap_check_dotdot(), nameicap_tracker_add(), NDFREE(), needs_exclusive_leaf(), panic(), pr, printf(), rootvnode, vfs_busy(), vfs_unbusy(), vn_printf(), vp_crossmp, vput(), vref(), vrefact(), and vrele().

Referenced by namei().

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

◆ vfs_relookup()

int vfs_relookup ( struct vnode *  dvp,
struct vnode **  vpp,
struct componentname *  cnp 
)

Definition at line 1389 of file vfs_lookup.c.

References panic(), printf(), vn_printf(), vput(), and vrele().

Here is the call graph for this function:

Variable Documentation

◆ crossmp_vnodeops

struct vop_vector crossmp_vnodeops
static
Initial value:
= {
.vop_default = &default_vnodeops,
.vop_islocked = crossmp_vop_islocked,
.vop_lock1 = crossmp_vop_lock1,
.vop_unlock = crossmp_vop_unlock,
}
struct vop_vector default_vnodeops
Definition: vfs_default.c:109
static int crossmp_vop_unlock(struct vop_unlock_args *ap)
Definition: vfs_lookup.c:123
static int crossmp_vop_islocked(struct vop_islocked_args *ap)
Definition: vfs_lookup.c:90
static int crossmp_vop_lock1(struct vop_lock1_args *ap)
Definition: vfs_lookup.c:97

Definition at line 137 of file vfs_lookup.c.

Referenced by nameiinit().

◆ lookup_cap_dotdot

int lookup_cap_dotdot = 1
static

Definition at line 167 of file vfs_lookup.c.

Referenced by namei_setup().

◆ lookup_cap_dotdot_nonlocal

int lookup_cap_dotdot_nonlocal = 1
static

Definition at line 171 of file vfs_lookup.c.

Referenced by nameicap_check_dotdot().

◆ namei_zone

◆ vp_crossmp

struct vnode* vp_crossmp
static

Definition at line 87 of file vfs_lookup.c.

Referenced by nameiinit(), and vfs_lookup().