Skip to content

Commit 4023bfc

Browse files
author
Al Viro
committed
be careful with nd->inode in path_init() and follow_dotdot_rcu()
in the former we simply check if dentry is still valid after picking its ->d_inode; in the latter we fetch ->d_inode in the same places where we fetch dentry and its ->d_seq, under the same checks. Cc: [email protected] # 2.6.38+ Signed-off-by: Al Viro <[email protected]>
1 parent 7bd8837 commit 4023bfc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

fs/namei.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
11421142

11431143
static int follow_dotdot_rcu(struct nameidata *nd)
11441144
{
1145+
struct inode *inode = nd->inode;
11451146
if (!nd->root.mnt)
11461147
set_root_rcu(nd);
11471148

@@ -1155,6 +1156,7 @@ static int follow_dotdot_rcu(struct nameidata *nd)
11551156
struct dentry *parent = old->d_parent;
11561157
unsigned seq;
11571158

1159+
inode = parent->d_inode;
11581160
seq = read_seqcount_begin(&parent->d_seq);
11591161
if (read_seqcount_retry(&old->d_seq, nd->seq))
11601162
goto failed;
@@ -1164,6 +1166,7 @@ static int follow_dotdot_rcu(struct nameidata *nd)
11641166
}
11651167
if (!follow_up_rcu(&nd->path))
11661168
break;
1169+
inode = nd->path.dentry->d_inode;
11671170
nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
11681171
}
11691172
while (d_mountpoint(nd->path.dentry)) {
@@ -1173,11 +1176,12 @@ static int follow_dotdot_rcu(struct nameidata *nd)
11731176
break;
11741177
nd->path.mnt = &mounted->mnt;
11751178
nd->path.dentry = mounted->mnt.mnt_root;
1179+
inode = nd->path.dentry->d_inode;
11761180
nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
11771181
if (read_seqretry(&mount_lock, nd->m_seq))
11781182
goto failed;
11791183
}
1180-
nd->inode = nd->path.dentry->d_inode;
1184+
nd->inode = inode;
11811185
return 0;
11821186

11831187
failed:
@@ -1904,7 +1908,14 @@ static int path_init(int dfd, const char *name, unsigned int flags,
19041908
}
19051909

19061910
nd->inode = nd->path.dentry->d_inode;
1907-
return 0;
1911+
if (!(flags & LOOKUP_RCU))
1912+
return 0;
1913+
if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq)))
1914+
return 0;
1915+
if (!(nd->flags & LOOKUP_ROOT))
1916+
nd->root.mnt = NULL;
1917+
rcu_read_unlock();
1918+
return -ECHILD;
19081919
}
19091920

19101921
static inline int lookup_last(struct nameidata *nd, struct path *path)

0 commit comments

Comments
 (0)