Skip to content

Commit 4549fc7

Browse files
Al Virogregkh
authored andcommitted
atomic_open(): fix the handling of create_error
commit 10c64cea04d3c75c306b3f990586ffb343b63287 upstream. * 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. Acked-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b657027 commit 4549fc7

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

fs/namei.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,22 +2906,10 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry,
29062906
dentry = lookup_real(dir, dentry, nd->flags);
29072907
if (IS_ERR(dentry))
29082908
return PTR_ERR(dentry);
2909-
2910-
if (create_error) {
2911-
int open_flag = op->open_flag;
2912-
2913-
error = create_error;
2914-
if ((open_flag & O_EXCL)) {
2915-
if (!dentry->d_inode)
2916-
goto out;
2917-
} else if (!dentry->d_inode) {
2918-
goto out;
2919-
} else if ((open_flag & O_TRUNC) &&
2920-
d_is_reg(dentry)) {
2921-
goto out;
2922-
}
2923-
/* will fail later, go on to get the right error */
2924-
}
2909+
}
2910+
if (create_error && !dentry->d_inode) {
2911+
error = create_error;
2912+
goto out;
29252913
}
29262914
looked_up:
29272915
path->dentry = dentry;

0 commit comments

Comments
 (0)