Lines Matching +full:2 +full:nd

563 #define EMBEDDED_LEVELS 2
589 #define ND_ROOT_GRABBED 2
628 static bool nd_alloc_stack(struct nameidata *nd) in nd_alloc_stack() argument
633 nd->flags & LOOKUP_RCU ? GFP_ATOMIC : GFP_KERNEL); in nd_alloc_stack()
636 memcpy(p, nd->internal, sizeof(nd->internal)); in nd_alloc_stack()
637 nd->stack = p; in nd_alloc_stack()
658 static void drop_links(struct nameidata *nd) in drop_links() argument
660 int i = nd->depth; in drop_links()
662 struct saved *last = nd->stack + i; in drop_links()
668 static void leave_rcu(struct nameidata *nd) in leave_rcu() argument
670 nd->flags &= ~LOOKUP_RCU; in leave_rcu()
671 nd->seq = nd->next_seq = 0; in leave_rcu()
675 static void terminate_walk(struct nameidata *nd) in terminate_walk() argument
677 drop_links(nd); in terminate_walk()
678 if (!(nd->flags & LOOKUP_RCU)) { in terminate_walk()
680 path_put(&nd->path); in terminate_walk()
681 for (i = 0; i < nd->depth; i++) in terminate_walk()
682 path_put(&nd->stack[i].link); in terminate_walk()
683 if (nd->state & ND_ROOT_GRABBED) { in terminate_walk()
684 path_put(&nd->root); in terminate_walk()
685 nd->state &= ~ND_ROOT_GRABBED; in terminate_walk()
688 leave_rcu(nd); in terminate_walk()
690 nd->depth = 0; in terminate_walk()
691 nd->path.mnt = NULL; in terminate_walk()
692 nd->path.dentry = NULL; in terminate_walk()
712 static inline bool legitimize_path(struct nameidata *nd, in legitimize_path() argument
715 return __legitimize_path(path, seq, nd->m_seq); in legitimize_path()
718 static bool legitimize_links(struct nameidata *nd) in legitimize_links() argument
721 if (unlikely(nd->flags & LOOKUP_CACHED)) { in legitimize_links()
722 drop_links(nd); in legitimize_links()
723 nd->depth = 0; in legitimize_links()
726 for (i = 0; i < nd->depth; i++) { in legitimize_links()
727 struct saved *last = nd->stack + i; in legitimize_links()
728 if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { in legitimize_links()
729 drop_links(nd); in legitimize_links()
730 nd->depth = i + 1; in legitimize_links()
737 static bool legitimize_root(struct nameidata *nd) in legitimize_root() argument
739 /* Nothing to do if nd->root is zero or is managed by the VFS user. */ in legitimize_root()
740 if (!nd->root.mnt || (nd->state & ND_ROOT_PRESET)) in legitimize_root()
742 nd->state |= ND_ROOT_GRABBED; in legitimize_root()
743 return legitimize_path(nd, &nd->root, nd->root_seq); in legitimize_root()
747 * Path walking has 2 modes, rcu-walk and ref-walk (see
759 * @nd: nameidata pathwalk data
762 * try_to_unlazy attempts to legitimize the current nd->path and nd->root
768 static bool try_to_unlazy(struct nameidata *nd) in try_to_unlazy() argument
770 struct dentry *parent = nd->path.dentry; in try_to_unlazy()
772 BUG_ON(!(nd->flags & LOOKUP_RCU)); in try_to_unlazy()
774 if (unlikely(!legitimize_links(nd))) in try_to_unlazy()
776 if (unlikely(!legitimize_path(nd, &nd->path, nd->seq))) in try_to_unlazy()
778 if (unlikely(!legitimize_root(nd))) in try_to_unlazy()
780 leave_rcu(nd); in try_to_unlazy()
781 BUG_ON(nd->inode != parent->d_inode); in try_to_unlazy()
785 nd->path.mnt = NULL; in try_to_unlazy()
786 nd->path.dentry = NULL; in try_to_unlazy()
788 leave_rcu(nd); in try_to_unlazy()
794 * @nd: nameidata pathwalk data
800 * nd->path and nd->root for ref-walk mode. Must be called from rcu-walk context.
804 static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry) in try_to_unlazy_next() argument
807 BUG_ON(!(nd->flags & LOOKUP_RCU)); in try_to_unlazy_next()
809 if (unlikely(!legitimize_links(nd))) in try_to_unlazy_next()
811 res = __legitimize_mnt(nd->path.mnt, nd->m_seq); in try_to_unlazy_next()
817 if (unlikely(!lockref_get_not_dead(&nd->path.dentry->d_lockref))) in try_to_unlazy_next()
829 if (read_seqcount_retry(&dentry->d_seq, nd->next_seq)) in try_to_unlazy_next()
835 if (unlikely(!legitimize_root(nd))) in try_to_unlazy_next()
837 leave_rcu(nd); in try_to_unlazy_next()
841 nd->path.mnt = NULL; in try_to_unlazy_next()
843 nd->path.dentry = NULL; in try_to_unlazy_next()
845 leave_rcu(nd); in try_to_unlazy_next()
848 leave_rcu(nd); in try_to_unlazy_next()
863 * @nd: pointer nameidata
865 * If we had been in RCU mode, drop out of it and legitimize nd->path.
869 * need to drop nd->path.
871 static int complete_walk(struct nameidata *nd) in complete_walk() argument
873 struct dentry *dentry = nd->path.dentry; in complete_walk()
876 if (nd->flags & LOOKUP_RCU) { in complete_walk()
878 * We don't want to zero nd->root for scoped-lookups or in complete_walk()
879 * externally-managed nd->root. in complete_walk()
881 if (!(nd->state & ND_ROOT_PRESET)) in complete_walk()
882 if (!(nd->flags & LOOKUP_IS_SCOPED)) in complete_walk()
883 nd->root.mnt = NULL; in complete_walk()
884 nd->flags &= ~LOOKUP_CACHED; in complete_walk()
885 if (!try_to_unlazy(nd)) in complete_walk()
889 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) { in complete_walk()
906 if (!path_is_under(&nd->path, &nd->root)) in complete_walk()
910 if (likely(!(nd->state & ND_JUMPED))) in complete_walk()
916 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags); in complete_walk()
926 static int set_root(struct nameidata *nd) in set_root() argument
935 if (WARN_ON(nd->flags & LOOKUP_IS_SCOPED)) in set_root()
938 if (nd->flags & LOOKUP_RCU) { in set_root()
943 nd->root = fs->root; in set_root()
944 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq); in set_root()
947 get_fs_root(fs, &nd->root); in set_root()
948 nd->state |= ND_ROOT_GRABBED; in set_root()
953 static int nd_jump_root(struct nameidata *nd) in nd_jump_root() argument
955 if (unlikely(nd->flags & LOOKUP_BENEATH)) in nd_jump_root()
957 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) { in nd_jump_root()
959 if (nd->path.mnt != NULL && nd->path.mnt != nd->root.mnt) in nd_jump_root()
962 if (!nd->root.mnt) { in nd_jump_root()
963 int error = set_root(nd); in nd_jump_root()
967 if (nd->flags & LOOKUP_RCU) { in nd_jump_root()
969 nd->path = nd->root; in nd_jump_root()
970 d = nd->path.dentry; in nd_jump_root()
971 nd->inode = d->d_inode; in nd_jump_root()
972 nd->seq = nd->root_seq; in nd_jump_root()
973 if (read_seqcount_retry(&d->d_seq, nd->seq)) in nd_jump_root()
976 path_put(&nd->path); in nd_jump_root()
977 nd->path = nd->root; in nd_jump_root()
978 path_get(&nd->path); in nd_jump_root()
979 nd->inode = nd->path.dentry->d_inode; in nd_jump_root()
981 nd->state |= ND_JUMPED; in nd_jump_root()
992 struct nameidata *nd = current->nameidata; in nd_jump_link() local
994 if (unlikely(nd->flags & LOOKUP_NO_MAGICLINKS)) in nd_jump_link()
998 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) { in nd_jump_link()
999 if (nd->path.mnt != path->mnt) in nd_jump_link()
1003 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) in nd_jump_link()
1006 path_put(&nd->path); in nd_jump_link()
1007 nd->path = *path; in nd_jump_link()
1008 nd->inode = nd->path.dentry->d_inode; in nd_jump_link()
1009 nd->state |= ND_JUMPED; in nd_jump_link()
1017 static inline void put_link(struct nameidata *nd) in put_link() argument
1019 struct saved *last = nd->stack + --nd->depth; in put_link()
1021 if (!(nd->flags & LOOKUP_RCU)) in put_link()
1082 * @nd: nameidata pathwalk data
1095 static inline int may_follow_link(struct nameidata *nd, const struct inode *inode) in may_follow_link() argument
1103 mnt_userns = mnt_user_ns(nd->path.mnt); in may_follow_link()
1110 if ((nd->dir_mode & (S_ISVTX|S_IWOTH)) != (S_ISVTX|S_IWOTH)) in may_follow_link()
1114 if (uid_valid(nd->dir_uid) && uid_eq(nd->dir_uid, i_uid)) in may_follow_link()
1117 if (nd->flags & LOOKUP_RCU) in may_follow_link()
1120 audit_inode(nd->name, nd->stack[0].link.dentry, 0); in may_follow_link()
1209 * @nd: nameidata pathwalk data
1219 * If the sysctl_protected_fifos (or sysctl_protected_regular) is set to 2
1232 struct nameidata *nd, struct inode *const inode) in may_create_in_sticky() argument
1234 umode_t dir_mode = nd->dir_mode; in may_create_in_sticky()
1235 kuid_t dir_uid = nd->dir_uid; in may_create_in_sticky()
1246 ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) || in may_create_in_sticky()
1247 (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) { in may_create_in_sticky()
1477 static bool __follow_mount_rcu(struct nameidata *nd, struct path *path) in __follow_mount_rcu() argument
1485 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in __follow_mount_rcu()
1505 nd->state |= ND_JUMPED; in __follow_mount_rcu()
1506 nd->next_seq = read_seqcount_begin(&dentry->d_seq); in __follow_mount_rcu()
1510 if (read_seqretry(&mount_lock, nd->m_seq)) in __follow_mount_rcu()
1514 if (read_seqretry(&mount_lock, nd->m_seq)) in __follow_mount_rcu()
1521 static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, in handle_mounts() argument
1527 path->mnt = nd->path.mnt; in handle_mounts()
1529 if (nd->flags & LOOKUP_RCU) { in handle_mounts()
1530 unsigned int seq = nd->next_seq; in handle_mounts()
1531 if (likely(__follow_mount_rcu(nd, path))) in handle_mounts()
1533 // *path and nd->next_seq might've been clobbered in handle_mounts()
1534 path->mnt = nd->path.mnt; in handle_mounts()
1536 nd->next_seq = seq; in handle_mounts()
1537 if (!try_to_unlazy_next(nd, dentry)) in handle_mounts()
1540 ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags); in handle_mounts()
1542 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in handle_mounts()
1545 nd->state |= ND_JUMPED; in handle_mounts()
1549 if (path->mnt != nd->path.mnt) in handle_mounts()
1609 static struct dentry *lookup_fast(struct nameidata *nd) in lookup_fast() argument
1611 struct dentry *dentry, *parent = nd->path.dentry; in lookup_fast()
1619 if (nd->flags & LOOKUP_RCU) { in lookup_fast()
1620 dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq); in lookup_fast()
1622 if (!try_to_unlazy(nd)) in lookup_fast()
1631 if (read_seqcount_retry(&parent->d_seq, nd->seq)) in lookup_fast()
1634 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1637 if (!try_to_unlazy_next(nd, dentry)) in lookup_fast()
1641 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1643 dentry = __d_lookup(parent, &nd->last); in lookup_fast()
1646 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1708 struct nameidata *nd) in may_lookup() argument
1710 if (nd->flags & LOOKUP_RCU) { in may_lookup()
1711 int err = inode_permission(mnt_userns, nd->inode, MAY_EXEC|MAY_NOT_BLOCK); in may_lookup()
1712 if (err != -ECHILD || !try_to_unlazy(nd)) in may_lookup()
1715 return inode_permission(mnt_userns, nd->inode, MAY_EXEC); in may_lookup()
1718 static int reserve_stack(struct nameidata *nd, struct path *link) in reserve_stack() argument
1720 if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) in reserve_stack()
1723 if (likely(nd->depth != EMBEDDED_LEVELS)) in reserve_stack()
1725 if (likely(nd->stack != nd->internal)) in reserve_stack()
1727 if (likely(nd_alloc_stack(nd))) in reserve_stack()
1730 if (nd->flags & LOOKUP_RCU) { in reserve_stack()
1733 bool grabbed_link = legitimize_path(nd, link, nd->next_seq); in reserve_stack()
1735 if (!try_to_unlazy(nd) || !grabbed_link) in reserve_stack()
1738 if (nd_alloc_stack(nd)) in reserve_stack()
1744 enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};
1746 static const char *pick_link(struct nameidata *nd, struct path *link, in pick_link() argument
1751 int error = reserve_stack(nd, link); in pick_link()
1754 if (!(nd->flags & LOOKUP_RCU)) in pick_link()
1758 last = nd->stack + nd->depth++; in pick_link()
1761 last->seq = nd->next_seq; in pick_link()
1764 error = may_follow_link(nd, inode); in pick_link()
1769 if (unlikely(nd->flags & LOOKUP_NO_SYMLINKS) || in pick_link()
1773 if (!(nd->flags & LOOKUP_RCU)) { in pick_link()
1777 if (!try_to_unlazy(nd)) in pick_link()
1783 nd->flags & LOOKUP_RCU); in pick_link()
1792 if (nd->flags & LOOKUP_RCU) { in pick_link()
1794 if (res == ERR_PTR(-ECHILD) && try_to_unlazy(nd)) in pick_link()
1805 error = nd_jump_root(nd); in pick_link()
1814 put_link(nd); in pick_link()
1824 * NOTE: dentry must be what nd->next_seq had been sampled from.
1826 static const char *step_into(struct nameidata *nd, int flags, in step_into() argument
1831 int err = handle_mounts(nd, dentry, &path); in step_into()
1837 ((flags & WALK_TRAILING) && !(nd->flags & LOOKUP_FOLLOW)) || in step_into()
1840 if (nd->flags & LOOKUP_RCU) { in step_into()
1841 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) in step_into()
1846 dput(nd->path.dentry); in step_into()
1847 if (nd->path.mnt != path.mnt) in step_into()
1848 mntput(nd->path.mnt); in step_into()
1850 nd->path = path; in step_into()
1851 nd->inode = inode; in step_into()
1852 nd->seq = nd->next_seq; in step_into()
1855 if (nd->flags & LOOKUP_RCU) { in step_into()
1857 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) in step_into()
1860 if (path.mnt == nd->path.mnt) in step_into()
1863 return pick_link(nd, &path, inode, flags); in step_into()
1866 static struct dentry *follow_dotdot_rcu(struct nameidata *nd) in follow_dotdot_rcu() argument
1870 if (path_equal(&nd->path, &nd->root)) in follow_dotdot_rcu()
1872 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) { in follow_dotdot_rcu()
1875 if (!choose_mountpoint_rcu(real_mount(nd->path.mnt), in follow_dotdot_rcu()
1876 &nd->root, &path, &seq)) in follow_dotdot_rcu()
1878 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in follow_dotdot_rcu()
1880 nd->path = path; in follow_dotdot_rcu()
1881 nd->inode = path.dentry->d_inode; in follow_dotdot_rcu()
1882 nd->seq = seq; in follow_dotdot_rcu()
1884 if (read_seqretry(&mount_lock, nd->m_seq)) in follow_dotdot_rcu()
1888 old = nd->path.dentry; in follow_dotdot_rcu()
1890 nd->next_seq = read_seqcount_begin(&parent->d_seq); in follow_dotdot_rcu()
1892 if (read_seqcount_retry(&old->d_seq, nd->seq)) in follow_dotdot_rcu()
1894 if (unlikely(!path_connected(nd->path.mnt, parent))) in follow_dotdot_rcu()
1898 if (read_seqretry(&mount_lock, nd->m_seq)) in follow_dotdot_rcu()
1900 if (unlikely(nd->flags & LOOKUP_BENEATH)) in follow_dotdot_rcu()
1902 nd->next_seq = nd->seq; in follow_dotdot_rcu()
1903 return nd->path.dentry; in follow_dotdot_rcu()
1906 static struct dentry *follow_dotdot(struct nameidata *nd) in follow_dotdot() argument
1910 if (path_equal(&nd->path, &nd->root)) in follow_dotdot()
1912 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) { in follow_dotdot()
1915 if (!choose_mountpoint(real_mount(nd->path.mnt), in follow_dotdot()
1916 &nd->root, &path)) in follow_dotdot()
1918 path_put(&nd->path); in follow_dotdot()
1919 nd->path = path; in follow_dotdot()
1920 nd->inode = path.dentry->d_inode; in follow_dotdot()
1921 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in follow_dotdot()
1925 parent = dget_parent(nd->path.dentry); in follow_dotdot()
1926 if (unlikely(!path_connected(nd->path.mnt, parent))) { in follow_dotdot()
1933 if (unlikely(nd->flags & LOOKUP_BENEATH)) in follow_dotdot()
1935 return dget(nd->path.dentry); in follow_dotdot()
1938 static const char *handle_dots(struct nameidata *nd, int type) in handle_dots() argument
1944 if (!nd->root.mnt) { in handle_dots()
1945 error = ERR_PTR(set_root(nd)); in handle_dots()
1949 if (nd->flags & LOOKUP_RCU) in handle_dots()
1950 parent = follow_dotdot_rcu(nd); in handle_dots()
1952 parent = follow_dotdot(nd); in handle_dots()
1955 error = step_into(nd, WALK_NOFOLLOW, parent); in handle_dots()
1959 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) { in handle_dots()
1963 * above nd->root (and so userspace should retry or use in handle_dots()
1967 if (__read_seqcount_retry(&mount_lock.seqcount, nd->m_seq)) in handle_dots()
1969 if (__read_seqcount_retry(&rename_lock.seqcount, nd->r_seq)) in handle_dots()
1976 static const char *walk_component(struct nameidata *nd, int flags) in walk_component() argument
1984 if (unlikely(nd->last_type != LAST_NORM)) { in walk_component()
1985 if (!(flags & WALK_MORE) && nd->depth) in walk_component()
1986 put_link(nd); in walk_component()
1987 return handle_dots(nd, nd->last_type); in walk_component()
1989 dentry = lookup_fast(nd); in walk_component()
1993 dentry = lookup_slow(&nd->last, nd->path.dentry, nd->flags); in walk_component()
1997 if (!(flags & WALK_MORE) && nd->depth) in walk_component()
1998 put_link(nd); in walk_component()
1999 return step_into(nd, flags, dentry); in walk_component()
2037 * influence out to 2^6 = 64 state bits.
2040 * deltas or 64*63/2 = 2016 two-bit input deltas, and finding the
2049 * Input delta: 1-bit 2-bit
2051 * 2 rounds: 2753.7 140389.8
2055 * (64*128) (64*63/2 * 128)
2079 * Input delta: 1-bit 2-bit
2081 * 2 rounds: 1246.4 25475.4
2085 * (32*64) (32*31/2 * 64)
2235 * Returns 0 and nd will have valid dentry and mnt on success.
2238 static int link_path_walk(const char *name, struct nameidata *nd) in link_path_walk() argument
2240 int depth = 0; // depth <= nd->depth in link_path_walk()
2243 nd->last_type = LAST_ROOT; in link_path_walk()
2244 nd->flags |= LOOKUP_PARENT; in link_path_walk()
2250 nd->dir_mode = 0; // short-circuit the 'hardening' idiocy in link_path_walk()
2261 mnt_userns = mnt_user_ns(nd->path.mnt); in link_path_walk()
2262 err = may_lookup(mnt_userns, nd); in link_path_walk()
2266 hash_len = hash_name(nd->path.dentry, name); in link_path_walk()
2270 case 2: in link_path_walk()
2273 nd->state |= ND_JUMPED; in link_path_walk()
2280 struct dentry *parent = nd->path.dentry; in link_path_walk()
2281 nd->state &= ~ND_JUMPED; in link_path_walk()
2292 nd->last.hash_len = hash_len; in link_path_walk()
2293 nd->last.name = name; in link_path_walk()
2294 nd->last_type = type; in link_path_walk()
2310 nd->dir_uid = i_uid_into_mnt(mnt_userns, nd->inode); in link_path_walk()
2311 nd->dir_mode = nd->inode->i_mode; in link_path_walk()
2312 nd->flags &= ~LOOKUP_PARENT; in link_path_walk()
2316 name = nd->stack[--depth].name; in link_path_walk()
2317 link = walk_component(nd, 0); in link_path_walk()
2320 link = walk_component(nd, WALK_MORE); in link_path_walk()
2326 nd->stack[depth++].name = name; in link_path_walk()
2330 if (unlikely(!d_can_lookup(nd->path.dentry))) { in link_path_walk()
2331 if (nd->flags & LOOKUP_RCU) { in link_path_walk()
2332 if (!try_to_unlazy(nd)) in link_path_walk()
2341 static const char *path_init(struct nameidata *nd, unsigned flags) in path_init() argument
2344 const char *s = nd->name->name; in path_init()
2355 nd->seq = nd->next_seq = 0; in path_init()
2357 nd->flags = flags; in path_init()
2358 nd->state |= ND_JUMPED; in path_init()
2360 nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount); in path_init()
2361 nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount); in path_init()
2364 if (nd->state & ND_ROOT_PRESET) { in path_init()
2365 struct dentry *root = nd->root.dentry; in path_init()
2369 nd->path = nd->root; in path_init()
2370 nd->inode = inode; in path_init()
2372 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2373 nd->root_seq = nd->seq; in path_init()
2375 path_get(&nd->path); in path_init()
2380 nd->root.mnt = NULL; in path_init()
2382 /* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */ in path_init()
2384 error = nd_jump_root(nd); in path_init()
2391 if (nd->dfd == AT_FDCWD) { in path_init()
2398 nd->path = fs->pwd; in path_init()
2399 nd->inode = nd->path.dentry->d_inode; in path_init()
2400 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2403 get_fs_pwd(current->fs, &nd->path); in path_init()
2404 nd->inode = nd->path.dentry->d_inode; in path_init()
2408 struct fd f = fdget_raw(nd->dfd); in path_init()
2421 nd->path = f.file->f_path; in path_init()
2423 nd->inode = nd->path.dentry->d_inode; in path_init()
2424 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2426 path_get(&nd->path); in path_init()
2427 nd->inode = nd->path.dentry->d_inode; in path_init()
2434 nd->root = nd->path; in path_init()
2436 nd->root_seq = nd->seq; in path_init()
2438 path_get(&nd->root); in path_init()
2439 nd->state |= ND_ROOT_GRABBED; in path_init()
2445 static inline const char *lookup_last(struct nameidata *nd) in lookup_last() argument
2447 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len]) in lookup_last()
2448 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in lookup_last()
2450 return walk_component(nd, WALK_TRAILING); in lookup_last()
2453 static int handle_lookup_down(struct nameidata *nd) in handle_lookup_down() argument
2455 if (!(nd->flags & LOOKUP_RCU)) in handle_lookup_down()
2456 dget(nd->path.dentry); in handle_lookup_down()
2457 nd->next_seq = nd->seq; in handle_lookup_down()
2458 return PTR_ERR(step_into(nd, WALK_NOFOLLOW, nd->path.dentry)); in handle_lookup_down()
2461 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
2462 static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path) in path_lookupat() argument
2464 const char *s = path_init(nd, flags); in path_lookupat()
2468 err = handle_lookup_down(nd); in path_lookupat()
2473 while (!(err = link_path_walk(s, nd)) && in path_lookupat()
2474 (s = lookup_last(nd)) != NULL) in path_lookupat()
2476 if (!err && unlikely(nd->flags & LOOKUP_MOUNTPOINT)) { in path_lookupat()
2477 err = handle_lookup_down(nd); in path_lookupat()
2478 nd->state &= ~ND_JUMPED; // no d_weak_revalidate(), please... in path_lookupat()
2481 err = complete_walk(nd); in path_lookupat()
2483 if (!err && nd->flags & LOOKUP_DIRECTORY) in path_lookupat()
2484 if (!d_can_lookup(nd->path.dentry)) in path_lookupat()
2487 *path = nd->path; in path_lookupat()
2488 nd->path.mnt = NULL; in path_lookupat()
2489 nd->path.dentry = NULL; in path_lookupat()
2491 terminate_walk(nd); in path_lookupat()
2499 struct nameidata nd; in filename_lookup() local
2502 set_nameidata(&nd, dfd, name, root); in filename_lookup()
2503 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); in filename_lookup()
2505 retval = path_lookupat(&nd, flags, path); in filename_lookup()
2507 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path); in filename_lookup()
2516 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
2517 static int path_parentat(struct nameidata *nd, unsigned flags, in path_parentat() argument
2520 const char *s = path_init(nd, flags); in path_parentat()
2521 int err = link_path_walk(s, nd); in path_parentat()
2523 err = complete_walk(nd); in path_parentat()
2525 *parent = nd->path; in path_parentat()
2526 nd->path.mnt = NULL; in path_parentat()
2527 nd->path.dentry = NULL; in path_parentat()
2529 terminate_walk(nd); in path_parentat()
2539 struct nameidata nd; in filename_parentat() local
2543 set_nameidata(&nd, dfd, name, NULL); in filename_parentat()
2544 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); in filename_parentat()
2546 retval = path_parentat(&nd, flags, parent); in filename_parentat()
2548 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent); in filename_parentat()
2550 *last = nd.last; in filename_parentat()
2551 *type = nd.last_type; in filename_parentat()
2636 if (len < 2 || (len == 2 && name[1] == '.')) in lookup_one_common()
2900 * 2. We should have write and exec permissions on dir
2963 * 2. We can't do it if dir is read-only (done in permission())
3263 static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, in atomic_open() argument
3268 struct inode *dir = nd->path.dentry->d_inode; in atomic_open()
3271 if (nd->flags & LOOKUP_DIRECTORY) in atomic_open()
3275 file->f_path.mnt = nd->path.mnt; in atomic_open()
3318 static struct dentry *lookup_open(struct nameidata *nd, struct file *file, in lookup_open() argument
3323 struct dentry *dir = nd->path.dentry; in lookup_open()
3335 dentry = d_lookup(dir, &nd->last); in lookup_open()
3338 dentry = d_alloc_parallel(dir, &nd->last, &wq); in lookup_open()
3345 error = d_revalidate(dentry, nd->flags); in lookup_open()
3370 mnt_userns = mnt_user_ns(nd->path.mnt); in lookup_open()
3376 create_error = may_o_create(mnt_userns, &nd->path, in lookup_open()
3384 dentry = atomic_open(nd, dentry, file, open_flag, mode); in lookup_open()
3392 nd->flags); in lookup_open()
3429 static const char *open_last_lookups(struct nameidata *nd, in open_last_lookups() argument
3432 struct dentry *dir = nd->path.dentry; in open_last_lookups()
3438 nd->flags |= op->intent; in open_last_lookups()
3440 if (nd->last_type != LAST_NORM) { in open_last_lookups()
3441 if (nd->depth) in open_last_lookups()
3442 put_link(nd); in open_last_lookups()
3443 return handle_dots(nd, nd->last_type); in open_last_lookups()
3447 if (nd->last.name[nd->last.len]) in open_last_lookups()
3448 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in open_last_lookups()
3450 dentry = lookup_fast(nd); in open_last_lookups()
3456 BUG_ON(nd->flags & LOOKUP_RCU); in open_last_lookups()
3459 if (nd->flags & LOOKUP_RCU) { in open_last_lookups()
3460 if (!try_to_unlazy(nd)) in open_last_lookups()
3463 audit_inode(nd->name, dir, AUDIT_INODE_PARENT); in open_last_lookups()
3465 if (unlikely(nd->last.name[nd->last.len])) in open_last_lookups()
3470 got_write = !mnt_want_write(nd->path.mnt); in open_last_lookups()
3481 dentry = lookup_open(nd, file, op, got_write); in open_last_lookups()
3490 mnt_drop_write(nd->path.mnt); in open_last_lookups()
3496 dput(nd->path.dentry); in open_last_lookups()
3497 nd->path.dentry = dentry; in open_last_lookups()
3502 if (nd->depth) in open_last_lookups()
3503 put_link(nd); in open_last_lookups()
3504 res = step_into(nd, WALK_TRAILING, dentry); in open_last_lookups()
3506 nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); in open_last_lookups()
3513 static int do_open(struct nameidata *nd, in do_open() argument
3523 error = complete_walk(nd); in do_open()
3528 audit_inode(nd->name, nd->path.dentry, 0); in do_open()
3529 mnt_userns = mnt_user_ns(nd->path.mnt); in do_open()
3533 if (d_is_dir(nd->path.dentry)) in do_open()
3535 error = may_create_in_sticky(mnt_userns, nd, in do_open()
3536 d_backing_inode(nd->path.dentry)); in do_open()
3540 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) in do_open()
3549 } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) { in do_open()
3550 error = mnt_want_write(nd->path.mnt); in do_open()
3555 error = may_open(mnt_userns, &nd->path, acc_mode, open_flag); in do_open()
3557 error = vfs_open(&nd->path, file); in do_open()
3567 mnt_drop_write(nd->path.mnt); in do_open()
3657 static int do_tmpfile(struct nameidata *nd, unsigned flags, in do_tmpfile() argument
3663 int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path); in do_tmpfile()
3674 audit_inode(nd->name, file->f_path.dentry, 0); in do_tmpfile()
3682 static int do_o_path(struct nameidata *nd, unsigned flags, struct file *file) in do_o_path() argument
3685 int error = path_lookupat(nd, flags, &path); in do_o_path()
3687 audit_inode(nd->name, path.dentry, 0); in do_o_path()
3694 static struct file *path_openat(struct nameidata *nd, in path_openat() argument
3705 error = do_tmpfile(nd, flags, op, file); in path_openat()
3707 error = do_o_path(nd, flags, file); in path_openat()
3709 const char *s = path_init(nd, flags); in path_openat()
3710 while (!(error = link_path_walk(s, nd)) && in path_openat()
3711 (s = open_last_lookups(nd, file, op)) != NULL) in path_openat()
3714 error = do_open(nd, file, op); in path_openat()
3715 terminate_walk(nd); in path_openat()
3736 struct nameidata nd; in do_filp_open() local
3740 set_nameidata(&nd, dfd, pathname, NULL); in do_filp_open()
3741 filp = path_openat(&nd, op, flags | LOOKUP_RCU); in do_filp_open()
3743 filp = path_openat(&nd, op, flags); in do_filp_open()
3745 filp = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_filp_open()
3753 struct nameidata nd; in do_file_open_root() local
3765 set_nameidata(&nd, -1, filename, root); in do_file_open_root()
3766 file = path_openat(&nd, op, flags | LOOKUP_RCU); in do_file_open_root()
3768 file = path_openat(&nd, op, flags); in do_file_open_root()
3770 file = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_file_open_root()
4675 * we'd better make sure that there's no link(2) for them.