diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index f468acb8ee7d..d1925333d327 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -771,6 +771,9 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, struct inode *inode; int p9_omode; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (d_in_lookup(dentry)) { struct dentry *res = v9fs_vfs_lookup(dir, dentry, 0); if (res || d_really_is_positive(dentry)) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 141fb54db65d..9f4b865d07d7 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -239,6 +239,9 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, struct v9fs_session_info *v9ses; struct posix_acl *pacl = NULL, *dacl = NULL; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (d_in_lookup(dentry)) { struct dentry *res = v9fs_vfs_lookup(dir, dentry, 0); if (res || d_really_is_positive(dentry)) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index d54d71669176..9707d9ed17b6 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -813,6 +813,9 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, if (dentry->d_name.len > NAME_MAX) return -ENAMETOOLONG; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + err = ceph_wait_on_conflict_unlink(dentry); if (err) return err; diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index b658b6baf72f..4c59992b9867 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -940,6 +940,9 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, if (fuse_is_bad(dir)) return -EIO; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (d_in_lookup(entry)) { struct dentry *res = fuse_lookup(dir, entry, 0); if (res || d_really_is_positive(entry)) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index e9bf4879c07f..21c6544fbee5 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1384,6 +1384,9 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry, { bool excl = !!(flags & O_EXCL); + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (d_in_lookup(dentry)) { struct dentry *d = __gfs2_lookup(dir, dentry, file); if (file->f_mode & FMODE_OPENED) { diff --git a/fs/namei.c b/fs/namei.c index 60223278f9ec..9d9529ef30c4 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4383,11 +4383,6 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry struct inode *dir = path->dentry->d_inode; int error; - if ((open_flag & O_MKDIR_MASK) == O_MKDIR_MASK) { - error = -EOPNOTSUPP; - goto out; - } - file->__f_path.dentry = DENTRY_NOT_SET; file->__f_path.mnt = path->mnt; error = dir->i_op->atomic_open(dir, dentry, file, @@ -4410,7 +4405,6 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry error = -ENOENT; } } -out: if (error) { dput(dentry); dentry = ERR_PTR(error); @@ -4642,7 +4636,7 @@ static const char *open_last_lookups(struct nameidata *nd, */ } if (open_flag & O_CREAT) - inode_lock(dir->d_inode); + inode_lock_nested(dir->d_inode, I_MUTEX_PARENT); else inode_lock_shared(dir->d_inode); dentry = lookup_open(nd, file, op, got_write, &delegated_inode); @@ -4713,6 +4707,7 @@ static int do_open(struct nameidata *nd, if (open_flag & O_CREAT) { if ((open_flag & O_EXCL) && !(file->f_mode & FMODE_CREATED)) return -EEXIST; + // there are no special rules for creating dirs in a sticky bit dir if (!(open_flag & O_DIRECTORY)) { if (d_is_dir(nd->path.dentry)) return -EISDIR; diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index e9ce1883288c..e44c7598b68e 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2314,6 +2314,9 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry, if (dentry->d_name.len > NFS_SERVER(dir)->namelen) return -ENAMETOOLONG; + if ((open_flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (open_flags & O_CREAT) { error = nfs_do_create(dir, dentry, mode, open_flags); if (!error) { diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 25048a3c2364..467f6bc707da 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -52,6 +52,9 @@ int nfs_check_flags(int flags) if ((flags & (O_APPEND | O_DIRECT)) == (O_APPEND | O_DIRECT)) return -EINVAL; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + return 0; } EXPORT_SYMBOL_GPL(nfs_check_flags); diff --git a/fs/open.c b/fs/open.c index 68b694ae1843..865ea6f70e8c 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1209,7 +1209,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) if (WILL_CREATE(flags)) { if (how->mode & ~S_IALLUGO) return -EINVAL; - if (flags & O_DIRECTORY) + if ((flags & (O_MKDIR_MASK)) == O_MKDIR_MASK) op->mode = how->mode | S_IFDIR; else op->mode = how->mode | S_IFREG; diff --git a/fs/smb/client/dir.c b/fs/smb/client/dir.c index e4295a5b55b3..ec8c54c91261 100644 --- a/fs/smb/client/dir.c +++ b/fs/smb/client/dir.c @@ -526,6 +526,9 @@ int cifs_atomic_open(struct inode *dir, struct dentry *direntry, if (unlikely(cifs_forced_shutdown(cifs_sb))) return smb_EIO(smb_eio_trace_forced_shutdown); + if ((oflags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + /* * Posix open is only called (at lookup time) for file create now. For * opens (rather than creates), because we do not know if it is a file diff --git a/fs/vboxsf/dir.c b/fs/vboxsf/dir.c index 42bedc4ec7af..aef5ca6730be 100644 --- a/fs/vboxsf/dir.c +++ b/fs/vboxsf/dir.c @@ -318,6 +318,9 @@ static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry, u64 handle; int err; + if ((flags & O_MKDIR_MASK) == O_MKDIR_MASK) + return -EINVAL; + if (d_in_lookup(dentry)) { struct dentry *res = vboxsf_dir_lookup(parent, dentry, 0); if (res || d_really_is_positive(dentry)) diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h index a332e79b3207..e31f3a57f07c 100644 --- a/include/linux/fcntl.h +++ b/include/linux/fcntl.h @@ -12,6 +12,8 @@ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) +#define O_MKDIR_MASK (O_CREAT | O_DIRECTORY) + /* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \ diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h index 40ab8bbe668b..613475285643 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -95,8 +95,6 @@ #define O_NDELAY O_NONBLOCK #endif -#define O_MKDIR_MASK (O_CREAT | O_DIRECTORY) - #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */