Skip to content

Commit 84f0cd9

Browse files
author
Al Viro
committed
pick_link(): pass it struct path already with normal refcounting rules
step_into() tries to avoid grabbing and dropping mount references on the steps that do not involve crossing mountpoints (which is obviously the majority of cases). So it uses a local struct path with unusual refcounting rules - path.mnt is pinned if and only if it's not equal to nd->path.mnt. We used to have similar beasts all over the place and we had quite a few bugs crop up in their handling - it's easy to get confused when changing e.g. cleanup on failure exits (or adding a new check, etc.) Now that's mostly gone - the step_into() instance (which is what we need them for) is the only one left. It is exposed to mount traversal and it's (shortly) seen by pick_link(). Since pick_link() needs to store it in link stack, where the normal rules apply, it has to make sure that mount is pinned regardless of nd->path.mnt value. That's done on all calls of pick_link() and very early in those. Let's do that in the caller (step_into()) instead - that way the fewer places need to be aware of such struct path instances. Signed-off-by: Al Viro <[email protected]>
1 parent 19f6028 commit 84f0cd9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/namei.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,13 +1602,10 @@ static const char *pick_link(struct nameidata *nd, struct path *link,
16021602
int error;
16031603

16041604
if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) {
1605-
path_to_nameidata(link, nd);
1605+
if (!(nd->flags & LOOKUP_RCU))
1606+
path_put(link);
16061607
return ERR_PTR(-ELOOP);
16071608
}
1608-
if (!(nd->flags & LOOKUP_RCU)) {
1609-
if (link->mnt == nd->path.mnt)
1610-
mntget(link->mnt);
1611-
}
16121609
error = nd_alloc_stack(nd);
16131610
if (unlikely(error)) {
16141611
if (error == -ECHILD) {
@@ -1713,10 +1710,13 @@ static const char *step_into(struct nameidata *nd, int flags,
17131710
nd->seq = seq;
17141711
return NULL;
17151712
}
1716-
/* make sure that d_is_symlink above matches inode */
17171713
if (nd->flags & LOOKUP_RCU) {
1714+
/* make sure that d_is_symlink above matches inode */
17181715
if (read_seqcount_retry(&path.dentry->d_seq, seq))
17191716
return ERR_PTR(-ECHILD);
1717+
} else {
1718+
if (path.mnt == nd->path.mnt)
1719+
mntget(path.mnt);
17201720
}
17211721
return pick_link(nd, &path, inode, seq, flags);
17221722
}

0 commit comments

Comments
 (0)