namei.c (c441bfb5f2866de71e092c1b9d866a65978dfe1a) namei.c (58ec9059b396a570b208239b4edc45eeb68b14c4)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/namei.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 540 unchanged lines hidden (view full) ---

549EXPORT_SYMBOL(path_put);
550
551#define EMBEDDED_LEVELS 2
552struct nameidata {
553 struct path path;
554 struct qstr last;
555 struct path root;
556 struct inode *inode; /* path.dentry.d_inode */
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/namei.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 540 unchanged lines hidden (view full) ---

549EXPORT_SYMBOL(path_put);
550
551#define EMBEDDED_LEVELS 2
552struct nameidata {
553 struct path path;
554 struct qstr last;
555 struct path root;
556 struct inode *inode; /* path.dentry.d_inode */
557 unsigned int flags;
557 unsigned int flags, state;
558 unsigned seq, m_seq, r_seq;
559 int last_type;
560 unsigned depth;
561 int total_link_count;
562 struct saved {
563 struct path link;
564 struct delayed_call done;
565 const char *name;
566 unsigned seq;
567 } *stack, internal[EMBEDDED_LEVELS];
568 struct filename *name;
569 struct nameidata *saved;
570 unsigned root_seq;
571 int dfd;
572 kuid_t dir_uid;
573 umode_t dir_mode;
574} __randomize_layout;
575
558 unsigned seq, m_seq, r_seq;
559 int last_type;
560 unsigned depth;
561 int total_link_count;
562 struct saved {
563 struct path link;
564 struct delayed_call done;
565 const char *name;
566 unsigned seq;
567 } *stack, internal[EMBEDDED_LEVELS];
568 struct filename *name;
569 struct nameidata *saved;
570 unsigned root_seq;
571 int dfd;
572 kuid_t dir_uid;
573 umode_t dir_mode;
574} __randomize_layout;
575
576static void set_nameidata(struct nameidata *p, int dfd, struct filename *name)
576#define ND_ROOT_PRESET 1
577#define ND_ROOT_GRABBED 2
578#define ND_JUMPED 4
579
580static void __set_nameidata(struct nameidata *p, int dfd, struct filename *name)
577{
578 struct nameidata *old = current->nameidata;
579 p->stack = p->internal;
581{
582 struct nameidata *old = current->nameidata;
583 p->stack = p->internal;
584 p->depth = 0;
580 p->dfd = dfd;
581 p->name = name;
582 p->path.mnt = NULL;
583 p->path.dentry = NULL;
584 p->total_link_count = old ? old->total_link_count : 0;
585 p->saved = old;
586 current->nameidata = p;
587}
588
585 p->dfd = dfd;
586 p->name = name;
587 p->path.mnt = NULL;
588 p->path.dentry = NULL;
589 p->total_link_count = old ? old->total_link_count : 0;
590 p->saved = old;
591 current->nameidata = p;
592}
593
594static inline void set_nameidata(struct nameidata *p, int dfd, struct filename *name,
595 const struct path *root)
596{
597 __set_nameidata(p, dfd, name);
598 p->state = 0;
599 if (unlikely(root)) {
600 p->state = ND_ROOT_PRESET;
601 p->root = *root;
602 }
603}
604
589static void restore_nameidata(void)
590{
591 struct nameidata *now = current->nameidata, *old = now->saved;
592
593 current->nameidata = old;
594 if (old)
595 old->total_link_count = now->total_link_count;
596 if (now->stack != now->internal)

--- 43 unchanged lines hidden (view full) ---

640static void terminate_walk(struct nameidata *nd)
641{
642 drop_links(nd);
643 if (!(nd->flags & LOOKUP_RCU)) {
644 int i;
645 path_put(&nd->path);
646 for (i = 0; i < nd->depth; i++)
647 path_put(&nd->stack[i].link);
605static void restore_nameidata(void)
606{
607 struct nameidata *now = current->nameidata, *old = now->saved;
608
609 current->nameidata = old;
610 if (old)
611 old->total_link_count = now->total_link_count;
612 if (now->stack != now->internal)

--- 43 unchanged lines hidden (view full) ---

656static void terminate_walk(struct nameidata *nd)
657{
658 drop_links(nd);
659 if (!(nd->flags & LOOKUP_RCU)) {
660 int i;
661 path_put(&nd->path);
662 for (i = 0; i < nd->depth; i++)
663 path_put(&nd->stack[i].link);
648 if (nd->flags & LOOKUP_ROOT_GRABBED) {
664 if (nd->state & ND_ROOT_GRABBED) {
649 path_put(&nd->root);
665 path_put(&nd->root);
650 nd->flags &= ~LOOKUP_ROOT_GRABBED;
666 nd->state &= ~ND_ROOT_GRABBED;
651 }
652 } else {
653 nd->flags &= ~LOOKUP_RCU;
654 rcu_read_unlock();
655 }
656 nd->depth = 0;
657 nd->path.mnt = NULL;
658 nd->path.dentry = NULL;

--- 46 unchanged lines hidden (view full) ---

705 /*
706 * For scoped-lookups (where nd->root has been zeroed), we need to
707 * restart the whole lookup from scratch -- because set_root() is wrong
708 * for these lookups (nd->dfd is the root, not the filesystem root).
709 */
710 if (!nd->root.mnt && (nd->flags & LOOKUP_IS_SCOPED))
711 return false;
712 /* Nothing to do if nd->root is zero or is managed by the VFS user. */
667 }
668 } else {
669 nd->flags &= ~LOOKUP_RCU;
670 rcu_read_unlock();
671 }
672 nd->depth = 0;
673 nd->path.mnt = NULL;
674 nd->path.dentry = NULL;

--- 46 unchanged lines hidden (view full) ---

721 /*
722 * For scoped-lookups (where nd->root has been zeroed), we need to
723 * restart the whole lookup from scratch -- because set_root() is wrong
724 * for these lookups (nd->dfd is the root, not the filesystem root).
725 */
726 if (!nd->root.mnt && (nd->flags & LOOKUP_IS_SCOPED))
727 return false;
728 /* Nothing to do if nd->root is zero or is managed by the VFS user. */
713 if (!nd->root.mnt || (nd->flags & LOOKUP_ROOT))
729 if (!nd->root.mnt || (nd->state & ND_ROOT_PRESET))
714 return true;
730 return true;
715 nd->flags |= LOOKUP_ROOT_GRABBED;
731 nd->state |= ND_ROOT_GRABBED;
716 return legitimize_path(nd, &nd->root, nd->root_seq);
717}
718
719/*
720 * Path walking has 2 modes, rcu-walk and ref-walk (see
721 * Documentation/filesystems/path-lookup.txt). In situations when we can't
722 * continue in RCU mode, we attempt to drop out of rcu-walk mode and grab
723 * normal reference counts on dentries and vfsmounts to transition to ref-walk

--- 120 unchanged lines hidden (view full) ---

844 struct dentry *dentry = nd->path.dentry;
845 int status;
846
847 if (nd->flags & LOOKUP_RCU) {
848 /*
849 * We don't want to zero nd->root for scoped-lookups or
850 * externally-managed nd->root.
851 */
732 return legitimize_path(nd, &nd->root, nd->root_seq);
733}
734
735/*
736 * Path walking has 2 modes, rcu-walk and ref-walk (see
737 * Documentation/filesystems/path-lookup.txt). In situations when we can't
738 * continue in RCU mode, we attempt to drop out of rcu-walk mode and grab
739 * normal reference counts on dentries and vfsmounts to transition to ref-walk

--- 120 unchanged lines hidden (view full) ---

860 struct dentry *dentry = nd->path.dentry;
861 int status;
862
863 if (nd->flags & LOOKUP_RCU) {
864 /*
865 * We don't want to zero nd->root for scoped-lookups or
866 * externally-managed nd->root.
867 */
852 if (!(nd->flags & (LOOKUP_ROOT | LOOKUP_IS_SCOPED)))
853 nd->root.mnt = NULL;
868 if (!(nd->state & ND_ROOT_PRESET))
869 if (!(nd->flags & LOOKUP_IS_SCOPED))
870 nd->root.mnt = NULL;
854 nd->flags &= ~LOOKUP_CACHED;
855 if (!try_to_unlazy(nd))
856 return -ECHILD;
857 }
858
859 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) {
860 /*
861 * While the guarantee of LOOKUP_IS_SCOPED is (roughly) "don't

--- 10 unchanged lines hidden (view full) ---

872 * Userspace could move the path outside the root after this
873 * check, but as discussed elsewhere this is not a concern (the
874 * resolved file was inside the root at some point).
875 */
876 if (!path_is_under(&nd->path, &nd->root))
877 return -EXDEV;
878 }
879
871 nd->flags &= ~LOOKUP_CACHED;
872 if (!try_to_unlazy(nd))
873 return -ECHILD;
874 }
875
876 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) {
877 /*
878 * While the guarantee of LOOKUP_IS_SCOPED is (roughly) "don't

--- 10 unchanged lines hidden (view full) ---

889 * Userspace could move the path outside the root after this
890 * check, but as discussed elsewhere this is not a concern (the
891 * resolved file was inside the root at some point).
892 */
893 if (!path_is_under(&nd->path, &nd->root))
894 return -EXDEV;
895 }
896
880 if (likely(!(nd->flags & LOOKUP_JUMPED)))
897 if (likely(!(nd->state & ND_JUMPED)))
881 return 0;
882
883 if (likely(!(dentry->d_flags & DCACHE_OP_WEAK_REVALIDATE)))
884 return 0;
885
886 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags);
887 if (status > 0)
888 return 0;

--- 21 unchanged lines hidden (view full) ---

910
911 do {
912 seq = read_seqcount_begin(&fs->seq);
913 nd->root = fs->root;
914 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq);
915 } while (read_seqcount_retry(&fs->seq, seq));
916 } else {
917 get_fs_root(fs, &nd->root);
898 return 0;
899
900 if (likely(!(dentry->d_flags & DCACHE_OP_WEAK_REVALIDATE)))
901 return 0;
902
903 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags);
904 if (status > 0)
905 return 0;

--- 21 unchanged lines hidden (view full) ---

927
928 do {
929 seq = read_seqcount_begin(&fs->seq);
930 nd->root = fs->root;
931 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq);
932 } while (read_seqcount_retry(&fs->seq, seq));
933 } else {
934 get_fs_root(fs, &nd->root);
918 nd->flags |= LOOKUP_ROOT_GRABBED;
935 nd->state |= ND_ROOT_GRABBED;
919 }
920 return 0;
921}
922
923static int nd_jump_root(struct nameidata *nd)
924{
925 if (unlikely(nd->flags & LOOKUP_BENEATH))
926 return -EXDEV;

--- 16 unchanged lines hidden (view full) ---

943 if (unlikely(read_seqcount_retry(&d->d_seq, nd->seq)))
944 return -ECHILD;
945 } else {
946 path_put(&nd->path);
947 nd->path = nd->root;
948 path_get(&nd->path);
949 nd->inode = nd->path.dentry->d_inode;
950 }
936 }
937 return 0;
938}
939
940static int nd_jump_root(struct nameidata *nd)
941{
942 if (unlikely(nd->flags & LOOKUP_BENEATH))
943 return -EXDEV;

--- 16 unchanged lines hidden (view full) ---

960 if (unlikely(read_seqcount_retry(&d->d_seq, nd->seq)))
961 return -ECHILD;
962 } else {
963 path_put(&nd->path);
964 nd->path = nd->root;
965 path_get(&nd->path);
966 nd->inode = nd->path.dentry->d_inode;
967 }
951 nd->flags |= LOOKUP_JUMPED;
968 nd->state |= ND_JUMPED;
952 return 0;
953}
954
955/*
956 * Helper to directly jump to a known parsed path from ->get_link,
957 * caller must have taken a reference to path beforehand.
958 */
959int nd_jump_link(struct path *path)

--- 11 unchanged lines hidden (view full) ---

971 }
972 /* Not currently safe for scoped-lookups. */
973 if (unlikely(nd->flags & LOOKUP_IS_SCOPED))
974 goto err;
975
976 path_put(&nd->path);
977 nd->path = *path;
978 nd->inode = nd->path.dentry->d_inode;
969 return 0;
970}
971
972/*
973 * Helper to directly jump to a known parsed path from ->get_link,
974 * caller must have taken a reference to path beforehand.
975 */
976int nd_jump_link(struct path *path)

--- 11 unchanged lines hidden (view full) ---

988 }
989 /* Not currently safe for scoped-lookups. */
990 if (unlikely(nd->flags & LOOKUP_IS_SCOPED))
991 goto err;
992
993 path_put(&nd->path);
994 nd->path = *path;
995 nd->inode = nd->path.dentry->d_inode;
979 nd->flags |= LOOKUP_JUMPED;
996 nd->state |= ND_JUMPED;
980 return 0;
981
982err:
983 path_put(path);
984 return error;
985}
986
987static inline void put_link(struct nameidata *nd)

--- 430 unchanged lines hidden (view full) ---

1418 flags = dentry->d_flags;
1419 }
1420
1421 if (flags & DCACHE_MOUNTED) {
1422 struct mount *mounted = __lookup_mnt(path->mnt, dentry);
1423 if (mounted) {
1424 path->mnt = &mounted->mnt;
1425 dentry = path->dentry = mounted->mnt.mnt_root;
997 return 0;
998
999err:
1000 path_put(path);
1001 return error;
1002}
1003
1004static inline void put_link(struct nameidata *nd)

--- 430 unchanged lines hidden (view full) ---

1435 flags = dentry->d_flags;
1436 }
1437
1438 if (flags & DCACHE_MOUNTED) {
1439 struct mount *mounted = __lookup_mnt(path->mnt, dentry);
1440 if (mounted) {
1441 path->mnt = &mounted->mnt;
1442 dentry = path->dentry = mounted->mnt.mnt_root;
1426 nd->flags |= LOOKUP_JUMPED;
1443 nd->state |= ND_JUMPED;
1427 *seqp = read_seqcount_begin(&dentry->d_seq);
1428 *inode = dentry->d_inode;
1429 /*
1430 * We don't need to re-check ->d_seq after this
1431 * ->d_inode read - there will be an RCU delay
1432 * between mount hash removal and ->mnt_root
1433 * becoming unpinned.
1434 */

--- 28 unchanged lines hidden (view full) ---

1463 path->mnt = nd->path.mnt;
1464 path->dentry = dentry;
1465 }
1466 ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
1467 if (jumped) {
1468 if (unlikely(nd->flags & LOOKUP_NO_XDEV))
1469 ret = -EXDEV;
1470 else
1444 *seqp = read_seqcount_begin(&dentry->d_seq);
1445 *inode = dentry->d_inode;
1446 /*
1447 * We don't need to re-check ->d_seq after this
1448 * ->d_inode read - there will be an RCU delay
1449 * between mount hash removal and ->mnt_root
1450 * becoming unpinned.
1451 */

--- 28 unchanged lines hidden (view full) ---

1480 path->mnt = nd->path.mnt;
1481 path->dentry = dentry;
1482 }
1483 ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
1484 if (jumped) {
1485 if (unlikely(nd->flags & LOOKUP_NO_XDEV))
1486 ret = -EXDEV;
1487 else
1471 nd->flags |= LOOKUP_JUMPED;
1488 nd->state |= ND_JUMPED;
1472 }
1473 if (unlikely(ret)) {
1474 dput(path->dentry);
1475 if (path->mnt != nd->path.mnt)
1476 mntput(path->mnt);
1477 } else {
1478 *inode = d_backing_inode(path->dentry);
1479 *seqp = 0; /* out of RCU mode, so the value doesn't matter */

--- 734 unchanged lines hidden (view full) ---

2214
2215 hash_len = hash_name(nd->path.dentry, name);
2216
2217 type = LAST_NORM;
2218 if (name[0] == '.') switch (hashlen_len(hash_len)) {
2219 case 2:
2220 if (name[1] == '.') {
2221 type = LAST_DOTDOT;
1489 }
1490 if (unlikely(ret)) {
1491 dput(path->dentry);
1492 if (path->mnt != nd->path.mnt)
1493 mntput(path->mnt);
1494 } else {
1495 *inode = d_backing_inode(path->dentry);
1496 *seqp = 0; /* out of RCU mode, so the value doesn't matter */

--- 734 unchanged lines hidden (view full) ---

2231
2232 hash_len = hash_name(nd->path.dentry, name);
2233
2234 type = LAST_NORM;
2235 if (name[0] == '.') switch (hashlen_len(hash_len)) {
2236 case 2:
2237 if (name[1] == '.') {
2238 type = LAST_DOTDOT;
2222 nd->flags |= LOOKUP_JUMPED;
2239 nd->state |= ND_JUMPED;
2223 }
2224 break;
2225 case 1:
2226 type = LAST_DOT;
2227 }
2228 if (likely(type == LAST_NORM)) {
2229 struct dentry *parent = nd->path.dentry;
2240 }
2241 break;
2242 case 1:
2243 type = LAST_DOT;
2244 }
2245 if (likely(type == LAST_NORM)) {
2246 struct dentry *parent = nd->path.dentry;
2230 nd->flags &= ~LOOKUP_JUMPED;
2247 nd->state &= ~ND_JUMPED;
2231 if (unlikely(parent->d_flags & DCACHE_OP_HASH)) {
2232 struct qstr this = { { .hash_len = hash_len }, .name = name };
2233 err = parent->d_op->d_hash(parent, &this);
2234 if (err < 0)
2235 return err;
2236 hash_len = this.hash_len;
2237 name = this.name;
2238 }

--- 57 unchanged lines hidden (view full) ---

2296 if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED)
2297 return ERR_PTR(-EAGAIN);
2298
2299 if (!*s)
2300 flags &= ~LOOKUP_RCU;
2301 if (flags & LOOKUP_RCU)
2302 rcu_read_lock();
2303
2248 if (unlikely(parent->d_flags & DCACHE_OP_HASH)) {
2249 struct qstr this = { { .hash_len = hash_len }, .name = name };
2250 err = parent->d_op->d_hash(parent, &this);
2251 if (err < 0)
2252 return err;
2253 hash_len = this.hash_len;
2254 name = this.name;
2255 }

--- 57 unchanged lines hidden (view full) ---

2313 if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED)
2314 return ERR_PTR(-EAGAIN);
2315
2316 if (!*s)
2317 flags &= ~LOOKUP_RCU;
2318 if (flags & LOOKUP_RCU)
2319 rcu_read_lock();
2320
2304 nd->flags = flags | LOOKUP_JUMPED;
2305 nd->depth = 0;
2321 nd->flags = flags;
2322 nd->state |= ND_JUMPED;
2306
2307 nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount);
2308 nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
2309 smp_rmb();
2310
2323
2324 nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount);
2325 nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
2326 smp_rmb();
2327
2311 if (flags & LOOKUP_ROOT) {
2328 if (nd->state & ND_ROOT_PRESET) {
2312 struct dentry *root = nd->root.dentry;
2313 struct inode *inode = root->d_inode;
2314 if (*s && unlikely(!d_can_lookup(root)))
2315 return ERR_PTR(-ENOTDIR);
2316 nd->path = nd->root;
2317 nd->inode = inode;
2318 if (flags & LOOKUP_RCU) {
2319 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);

--- 58 unchanged lines hidden (view full) ---

2378
2379 /* For scoped-lookups we need to set the root to the dirfd as well. */
2380 if (flags & LOOKUP_IS_SCOPED) {
2381 nd->root = nd->path;
2382 if (flags & LOOKUP_RCU) {
2383 nd->root_seq = nd->seq;
2384 } else {
2385 path_get(&nd->root);
2329 struct dentry *root = nd->root.dentry;
2330 struct inode *inode = root->d_inode;
2331 if (*s && unlikely(!d_can_lookup(root)))
2332 return ERR_PTR(-ENOTDIR);
2333 nd->path = nd->root;
2334 nd->inode = inode;
2335 if (flags & LOOKUP_RCU) {
2336 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);

--- 58 unchanged lines hidden (view full) ---

2395
2396 /* For scoped-lookups we need to set the root to the dirfd as well. */
2397 if (flags & LOOKUP_IS_SCOPED) {
2398 nd->root = nd->path;
2399 if (flags & LOOKUP_RCU) {
2400 nd->root_seq = nd->seq;
2401 } else {
2402 path_get(&nd->root);
2386 nd->flags |= LOOKUP_ROOT_GRABBED;
2403 nd->state |= ND_ROOT_GRABBED;
2387 }
2388 }
2389 return s;
2390}
2391
2392static inline const char *lookup_last(struct nameidata *nd)
2393{
2394 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len])

--- 22 unchanged lines hidden (view full) ---

2417 s = ERR_PTR(err);
2418 }
2419
2420 while (!(err = link_path_walk(s, nd)) &&
2421 (s = lookup_last(nd)) != NULL)
2422 ;
2423 if (!err && unlikely(nd->flags & LOOKUP_MOUNTPOINT)) {
2424 err = handle_lookup_down(nd);
2404 }
2405 }
2406 return s;
2407}
2408
2409static inline const char *lookup_last(struct nameidata *nd)
2410{
2411 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len])

--- 22 unchanged lines hidden (view full) ---

2434 s = ERR_PTR(err);
2435 }
2436
2437 while (!(err = link_path_walk(s, nd)) &&
2438 (s = lookup_last(nd)) != NULL)
2439 ;
2440 if (!err && unlikely(nd->flags & LOOKUP_MOUNTPOINT)) {
2441 err = handle_lookup_down(nd);
2425 nd->flags &= ~LOOKUP_JUMPED; // no d_weak_revalidate(), please...
2442 nd->state &= ~ND_JUMPED; // no d_weak_revalidate(), please...
2426 }
2427 if (!err)
2428 err = complete_walk(nd);
2429
2430 if (!err && nd->flags & LOOKUP_DIRECTORY)
2431 if (!d_can_lookup(nd->path.dentry))
2432 err = -ENOTDIR;
2433 if (!err) {

--- 7 unchanged lines hidden (view full) ---

2441
2442int filename_lookup(int dfd, struct filename *name, unsigned flags,
2443 struct path *path, struct path *root)
2444{
2445 int retval;
2446 struct nameidata nd;
2447 if (IS_ERR(name))
2448 return PTR_ERR(name);
2443 }
2444 if (!err)
2445 err = complete_walk(nd);
2446
2447 if (!err && nd->flags & LOOKUP_DIRECTORY)
2448 if (!d_can_lookup(nd->path.dentry))
2449 err = -ENOTDIR;
2450 if (!err) {

--- 7 unchanged lines hidden (view full) ---

2458
2459int filename_lookup(int dfd, struct filename *name, unsigned flags,
2460 struct path *path, struct path *root)
2461{
2462 int retval;
2463 struct nameidata nd;
2464 if (IS_ERR(name))
2465 return PTR_ERR(name);
2449 if (unlikely(root)) {
2450 nd.root = *root;
2451 flags |= LOOKUP_ROOT;
2452 }
2453 set_nameidata(&nd, dfd, name);
2466 set_nameidata(&nd, dfd, name, root);
2454 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path);
2455 if (unlikely(retval == -ECHILD))
2456 retval = path_lookupat(&nd, flags, path);
2457 if (unlikely(retval == -ESTALE))
2458 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path);
2459
2460 if (likely(!retval))
2461 audit_inode(name, path->dentry,

--- 24 unchanged lines hidden (view full) ---

2486 unsigned int flags, struct path *parent,
2487 struct qstr *last, int *type)
2488{
2489 int retval;
2490 struct nameidata nd;
2491
2492 if (IS_ERR(name))
2493 return name;
2467 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path);
2468 if (unlikely(retval == -ECHILD))
2469 retval = path_lookupat(&nd, flags, path);
2470 if (unlikely(retval == -ESTALE))
2471 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path);
2472
2473 if (likely(!retval))
2474 audit_inode(name, path->dentry,

--- 24 unchanged lines hidden (view full) ---

2499 unsigned int flags, struct path *parent,
2500 struct qstr *last, int *type)
2501{
2502 int retval;
2503 struct nameidata nd;
2504
2505 if (IS_ERR(name))
2506 return name;
2494 set_nameidata(&nd, dfd, name);
2507 set_nameidata(&nd, dfd, name, NULL);
2495 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent);
2496 if (unlikely(retval == -ECHILD))
2497 retval = path_parentat(&nd, flags, parent);
2498 if (unlikely(retval == -ESTALE))
2499 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent);
2500 if (likely(!retval)) {
2501 *last = nd.last;
2502 *type = nd.last_type;

--- 1009 unchanged lines hidden (view full) ---

3512
3513struct file *do_filp_open(int dfd, struct filename *pathname,
3514 const struct open_flags *op)
3515{
3516 struct nameidata nd;
3517 int flags = op->lookup_flags;
3518 struct file *filp;
3519
2508 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent);
2509 if (unlikely(retval == -ECHILD))
2510 retval = path_parentat(&nd, flags, parent);
2511 if (unlikely(retval == -ESTALE))
2512 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent);
2513 if (likely(!retval)) {
2514 *last = nd.last;
2515 *type = nd.last_type;

--- 1009 unchanged lines hidden (view full) ---

3525
3526struct file *do_filp_open(int dfd, struct filename *pathname,
3527 const struct open_flags *op)
3528{
3529 struct nameidata nd;
3530 int flags = op->lookup_flags;
3531 struct file *filp;
3532
3520 set_nameidata(&nd, dfd, pathname);
3533 set_nameidata(&nd, dfd, pathname, NULL);
3521 filp = path_openat(&nd, op, flags | LOOKUP_RCU);
3522 if (unlikely(filp == ERR_PTR(-ECHILD)))
3523 filp = path_openat(&nd, op, flags);
3524 if (unlikely(filp == ERR_PTR(-ESTALE)))
3525 filp = path_openat(&nd, op, flags | LOOKUP_REVAL);
3526 restore_nameidata();
3527 return filp;
3528}
3529
3534 filp = path_openat(&nd, op, flags | LOOKUP_RCU);
3535 if (unlikely(filp == ERR_PTR(-ECHILD)))
3536 filp = path_openat(&nd, op, flags);
3537 if (unlikely(filp == ERR_PTR(-ESTALE)))
3538 filp = path_openat(&nd, op, flags | LOOKUP_REVAL);
3539 restore_nameidata();
3540 return filp;
3541}
3542
3530struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,
3543struct file *do_file_open_root(const struct path *root,
3531 const char *name, const struct open_flags *op)
3532{
3533 struct nameidata nd;
3534 struct file *file;
3535 struct filename *filename;
3544 const char *name, const struct open_flags *op)
3545{
3546 struct nameidata nd;
3547 struct file *file;
3548 struct filename *filename;
3536 int flags = op->lookup_flags | LOOKUP_ROOT;
3549 int flags = op->lookup_flags;
3537
3550
3538 nd.root.mnt = mnt;
3539 nd.root.dentry = dentry;
3540
3541 if (d_is_symlink(dentry) && op->intent & LOOKUP_OPEN)
3551 if (d_is_symlink(root->dentry) && op->intent & LOOKUP_OPEN)
3542 return ERR_PTR(-ELOOP);
3543
3544 filename = getname_kernel(name);
3545 if (IS_ERR(filename))
3546 return ERR_CAST(filename);
3547
3552 return ERR_PTR(-ELOOP);
3553
3554 filename = getname_kernel(name);
3555 if (IS_ERR(filename))
3556 return ERR_CAST(filename);
3557
3548 set_nameidata(&nd, -1, filename);
3558 set_nameidata(&nd, -1, filename, root);
3549 file = path_openat(&nd, op, flags | LOOKUP_RCU);
3550 if (unlikely(file == ERR_PTR(-ECHILD)))
3551 file = path_openat(&nd, op, flags);
3552 if (unlikely(file == ERR_PTR(-ESTALE)))
3553 file = path_openat(&nd, op, flags | LOOKUP_REVAL);
3554 restore_nameidata();
3555 putname(filename);
3556 return file;

--- 1366 unchanged lines hidden ---
3559 file = path_openat(&nd, op, flags | LOOKUP_RCU);
3560 if (unlikely(file == ERR_PTR(-ECHILD)))
3561 file = path_openat(&nd, op, flags);
3562 if (unlikely(file == ERR_PTR(-ESTALE)))
3563 file = path_openat(&nd, op, flags | LOOKUP_REVAL);
3564 restore_nameidata();
3565 putname(filename);
3566 return file;

--- 1366 unchanged lines hidden ---