diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2016-04-27 01:11:55 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-04-30 16:40:52 -0400 |
commit | 10c64cea04d3c75c306b3f990586ffb343b63287 (patch) | |
tree | 6536d39b5be023d107315d6ce319da742cfcbeab | |
parent | 357f435d8a0d32068c75f3c7176434d992b3adb7 (diff) |
atomic_open(): fix the handling of create_error
* if we have a hashed negative dentry and either CREAT|EXCL on
r/o filesystem, or CREAT|TRUNC on r/o filesystem, or CREAT|EXCL
with failing may_o_create(), we should fail with EROFS or the
error may_o_create() has returned, but not ENOENT. Which is what
the current code ends up returning.
* if we have CREAT|TRUNC hitting a regular file on a read-only
filesystem, we can't fail with EROFS here. At the very least,
not until we'd done follow_managed() - we might have a writable
file (or a device, for that matter) bound on top of that one.
Moreover, the code downstream will see that O_TRUNC and attempt
to grab the write access (*after* following possible mount), so
if we really should fail with EROFS, it will happen. No need
to do that inside atomic_open().
The real logics is much simpler than what the current code is
trying to do - if we decided to go for simple lookup, ended
up with a negative dentry *and* had create_error set, fail with
create_error. No matter whether we'd got that negative dentry
from lookup_real() or had found it in dcache.
Cc: stable@vger.kernel.org # v3.6+
Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/namei.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/fs/namei.c b/fs/namei.c index 1d9ca2d5dff6..b4589922c0de 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -2942,22 +2942,10 @@ no_open: | |||
2942 | dentry = lookup_real(dir, dentry, nd->flags); | 2942 | dentry = lookup_real(dir, dentry, nd->flags); |
2943 | if (IS_ERR(dentry)) | 2943 | if (IS_ERR(dentry)) |
2944 | return PTR_ERR(dentry); | 2944 | return PTR_ERR(dentry); |
2945 | 2945 | } | |
2946 | if (create_error) { | 2946 | if (create_error && !dentry->d_inode) { |
2947 | int open_flag = op->open_flag; | 2947 | error = create_error; |
2948 | 2948 | goto out; | |
2949 | error = create_error; | ||
2950 | if ((open_flag & O_EXCL)) { | ||
2951 | if (!dentry->d_inode) | ||
2952 | goto out; | ||
2953 | } else if (!dentry->d_inode) { | ||
2954 | goto out; | ||
2955 | } else if ((open_flag & O_TRUNC) && | ||
2956 | d_is_reg(dentry)) { | ||
2957 | goto out; | ||
2958 | } | ||
2959 | /* will fail later, go on to get the right error */ | ||
2960 | } | ||
2961 | } | 2949 | } |
2962 | looked_up: | 2950 | looked_up: |
2963 | path->dentry = dentry; | 2951 | path->dentry = dentry; |