Skip to content

Commit 97adb49

Browse files
committed
Merge tag 'v6.4/vfs.open' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs open fixlet from Christian Brauner: "EINVAL ist keinmal: This contains the changes to make O_DIRECTORY when specified together with O_CREAT an invalid request. The wider background is that a regression report about the behavior of O_DIRECTORY | O_CREAT was sent to fsdevel about a behavior that was changed multiple years and LTS releases earlier during v5.7 development. This has also been covered in https://lwn.net/Articles/926782/ which provides an excellent summary of the discussion" * tag 'v6.4/vfs.open' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: open: return EINVAL for O_DIRECTORY | O_CREAT
2 parents e2eff52 + 43b4506 commit 97adb49

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

fs/open.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,13 +1196,21 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)
11961196
}
11971197

11981198
/*
1199-
* In order to ensure programs get explicit errors when trying to use
1200-
* O_TMPFILE on old kernels, O_TMPFILE is implemented such that it
1201-
* looks like (O_DIRECTORY|O_RDWR & ~O_CREAT) to old kernels. But we
1202-
* have to require userspace to explicitly set it.
1199+
* Block bugs where O_DIRECTORY | O_CREAT created regular files.
1200+
* Note, that blocking O_DIRECTORY | O_CREAT here also protects
1201+
* O_TMPFILE below which requires O_DIRECTORY being raised.
12031202
*/
1203+
if ((flags & (O_DIRECTORY | O_CREAT)) == (O_DIRECTORY | O_CREAT))
1204+
return -EINVAL;
1205+
1206+
/* Now handle the creative implementation of O_TMPFILE. */
12041207
if (flags & __O_TMPFILE) {
1205-
if ((flags & O_TMPFILE_MASK) != O_TMPFILE)
1208+
/*
1209+
* In order to ensure programs get explicit errors when trying
1210+
* to use O_TMPFILE on old kernels we enforce that O_DIRECTORY
1211+
* is raised alongside __O_TMPFILE.
1212+
*/
1213+
if (!(flags & O_DIRECTORY))
12061214
return -EINVAL;
12071215
if (!(acc_mode & MAY_WRITE))
12081216
return -EINVAL;

include/uapi/asm-generic/fcntl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191

9292
/* a horrid kludge trying to make sure that this will fail on old kernels */
9393
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
94-
#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT)
9594

9695
#ifndef O_NDELAY
9796
#define O_NDELAY O_NONBLOCK

tools/include/uapi/asm-generic/fcntl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191

9292
/* a horrid kludge trying to make sure that this will fail on old kernels */
9393
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
94-
#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT)
9594

9695
#ifndef O_NDELAY
9796
#define O_NDELAY O_NONBLOCK

0 commit comments

Comments
 (0)