Commit 9ddd8340 authored by Al Viro's avatar Al Viro Committed by Sasha Levin

atomic_open(): fix the handling of create_error

[ Upstream commit 10c64cea ]

* 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: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent cb4a26d1
...@@ -2839,22 +2839,10 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2839,22 +2839,10 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry,
dentry = lookup_real(dir, dentry, nd->flags); dentry = lookup_real(dir, dentry, nd->flags);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return PTR_ERR(dentry); return PTR_ERR(dentry);
}
if (create_error) { if (create_error && !dentry->d_inode) {
int open_flag = op->open_flag;
error = create_error; error = create_error;
if ((open_flag & O_EXCL)) {
if (!dentry->d_inode)
goto out; goto out;
} else if (!dentry->d_inode) {
goto out;
} else if ((open_flag & O_TRUNC) &&
d_is_reg(dentry)) {
goto out;
}
/* will fail later, go on to get the right error */
}
} }
looked_up: looked_up:
path->dentry = dentry; path->dentry = dentry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment