diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-04-19 12:30:58 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-04-19 12:30:58 -0400 |
commit | 22213318af7ae265bc6cd8aef2febbc2d69a2440 (patch) | |
tree | bb9b6c5e25909555f5243d8983d07c96cfeb08a9 /fs | |
parent | c9eaa447e77efe77b7fa4c953bd62de8297fd6c5 (diff) |
fix races between __d_instantiate() and checks of dentry flags
in non-lazy walk we need to be careful about dentry switching from
negative to positive - both ->d_flags and ->d_inode are updated,
and in some places we might see only one store. The cases where
dentry has been obtained by dcache lookup with ->i_mutex held on
parent are safe - ->d_lock and ->i_mutex provide all the barriers
we need. However, there are several places where we run into
trouble:
* do_last() fetches ->d_inode, then checks ->d_flags and
assumes that inode won't be NULL unless d_is_negative() is true.
Race with e.g. creat() - we might have fetched the old value of
->d_inode (still NULL) and new value of ->d_flags (already not
DCACHE_MISS_TYPE). Lin Ming has observed and reported the resulting
oops.
* a bunch of places checks ->d_inode for being non-NULL,
then checks ->d_flags for "is it a symlink". Race with symlink(2)
in case if our CPU sees ->d_inode update first - we see non-NULL
there, but ->d_flags still contains DCACHE_MISS_TYPE instead of
DCACHE_SYMLINK_TYPE. Result: false negative on "should we follow
link here?", with subsequent unpleasantness.
Cc: stable@vger.kernel.org # 3.13 and 3.14 need that one
Reported-and-tested-by: Lin Ming <minggr@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/dcache.c | 3 | ||||
-rw-r--r-- | fs/namei.c | 6 |
2 files changed, 4 insertions, 5 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 40707d88a945..494a9def5dce 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -1647,8 +1647,7 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode) | |||
1647 | unsigned add_flags = d_flags_for_inode(inode); | 1647 | unsigned add_flags = d_flags_for_inode(inode); |
1648 | 1648 | ||
1649 | spin_lock(&dentry->d_lock); | 1649 | spin_lock(&dentry->d_lock); |
1650 | dentry->d_flags &= ~DCACHE_ENTRY_TYPE; | 1650 | __d_set_type(dentry, add_flags); |
1651 | dentry->d_flags |= add_flags; | ||
1652 | if (inode) | 1651 | if (inode) |
1653 | hlist_add_head(&dentry->d_alias, &inode->i_dentry); | 1652 | hlist_add_head(&dentry->d_alias, &inode->i_dentry); |
1654 | dentry->d_inode = inode; | 1653 | dentry->d_inode = inode; |
diff --git a/fs/namei.c b/fs/namei.c index c6157c894fce..80168273396b 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1542,7 +1542,7 @@ static inline int walk_component(struct nameidata *nd, struct path *path, | |||
1542 | inode = path->dentry->d_inode; | 1542 | inode = path->dentry->d_inode; |
1543 | } | 1543 | } |
1544 | err = -ENOENT; | 1544 | err = -ENOENT; |
1545 | if (!inode) | 1545 | if (!inode || d_is_negative(path->dentry)) |
1546 | goto out_path_put; | 1546 | goto out_path_put; |
1547 | 1547 | ||
1548 | if (should_follow_link(path->dentry, follow)) { | 1548 | if (should_follow_link(path->dentry, follow)) { |
@@ -2249,7 +2249,7 @@ mountpoint_last(struct nameidata *nd, struct path *path) | |||
2249 | mutex_unlock(&dir->d_inode->i_mutex); | 2249 | mutex_unlock(&dir->d_inode->i_mutex); |
2250 | 2250 | ||
2251 | done: | 2251 | done: |
2252 | if (!dentry->d_inode) { | 2252 | if (!dentry->d_inode || d_is_negative(dentry)) { |
2253 | error = -ENOENT; | 2253 | error = -ENOENT; |
2254 | dput(dentry); | 2254 | dput(dentry); |
2255 | goto out; | 2255 | goto out; |
@@ -2994,7 +2994,7 @@ retry_lookup: | |||
2994 | finish_lookup: | 2994 | finish_lookup: |
2995 | /* we _can_ be in RCU mode here */ | 2995 | /* we _can_ be in RCU mode here */ |
2996 | error = -ENOENT; | 2996 | error = -ENOENT; |
2997 | if (d_is_negative(path->dentry)) { | 2997 | if (!inode || d_is_negative(path->dentry)) { |
2998 | path_to_nameidata(path, nd); | 2998 | path_to_nameidata(path, nd); |
2999 | goto out; | 2999 | goto out; |
3000 | } | 3000 | } |