completely ignore unknown open flags
Subsystems (2)
This is the fallout from the reject unknown flags discussion a few weeks back. So to keep backwards compatibily we can't _reject_ unknown flags. But we'd better totally ignore them and don't pass them to file systems or back to userspace using fcntl.
PATCH 1/2 fs: add a VALID_OPEN_FLAGS
Add a central define for all valid open flags, and use it in the uniqueness check.
--- fs/fcntl.c | 14 ++++---------- include/linux/fcntl.h | 6 ++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
fs/fcntl.c +4 -10
@@ -742,16 +742,10 @@ static int __init fcntl_init(void)* Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY * is defined as O_NONBLOCK on some platforms and not on others. */ -BUILD_BUG_ON (21 -1 /* for O_RDONLY being 0 */ !=HWEIGHT32 ( -O_RDONLY |O_WRONLY |O_RDWR | -O_CREAT |O_EXCL |O_NOCTTY | -O_TRUNC |O_APPEND |/* O_NONBLOCK | */ - __O_SYNC |O_DSYNC |FASYNC | -O_DIRECT |O_LARGEFILE |O_DIRECTORY | -O_NOFOLLOW |O_NOATIME |O_CLOEXEC | - __FMODE_EXEC |O_PATH | __O_TMPFILE | - __FMODE_NONOTIFY - )); +BUILD_BUG_ON (21 -1 /* for O_RDONLY being 0 */ != +HWEIGHT32 ( + (VALID_OPEN_FLAGS & ~(O_NONBLOCK |O_NDELAY )) | + __FMODE_EXEC | __FMODE_NONOTIFY)); fasync_cache =kmem_cache_create ("fasync_cache" ,sizeof (struct fasync_struct ),0 ,SLAB_PANIC ,NULL );
include/linux/fcntl.h +6 -0
@@ -3,6 +3,12 @@#include <uapi/linux/fcntl.h> +/* list of all valid flags for the open/openat flags argument: */ +#define VALID_OPEN_FLAGS \ + (O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | \ + O_APPEND | O_NDELAY | O_NONBLOCK | O_NDELAY | __O_SYNC | O_DSYNC | \ + FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ + O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE)#ifndef force_o_largefile#define force_o_largefile () (BITS_PER_LONG != 32)
Signature · 1 line
2.11.0
PATCH 2/2 fs: completely ignore unknown open flags
In reply to Christoph HellwigCurrently we just stash anything we got into file->f_flags, and the report it in fcntl(F_GETFD). This patch just clears out all unknown flags so that we don't pass them to the fs or report them.
--- fs/open.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/open.c +6 -0
@@ -900,6 +900,12 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *oint lookup_flags =0 ;int acc_mode =ACC_MODE (flags); +/* +* Clear out all open flags we don't know about so that we don't report +* them in fcntl(F_GETFD) or similar interfaces. +*/ + flags &=VALID_OPEN_FLAGS ; +if (flags & (O_CREAT | __O_TMPFILE)) op->mode = (mode &S_IALLUGO ) |S_IFREG ;else
Signature · 1 line
2.11.0
Quoted 4 lines · Christoph Hellwig
This is the fallout from the reject unknown flags discussion a few weeks back. So to keep backwards compatibily we can't _reject_ unknown flags. But we'd better totally ignore them and don't pass them to file systems or back to userspace using fcntl.
Ack, this makes sense to me. It's crazy to let fcntl etc show bits that the kernel isn't even using.
I'm assuming this will come through Al eventually. It doesn't seem high-priority for me to worry about it just before the 4.11 release, but it might be worth marking for stable just to percolate the change eventually to other kernels, and keep these kinds of differences minimal.
Linus
Al Viro
maintainerQuoted 6 lines · Linus Torvalds
Quoted 4 lines · Christoph Hellwig
This is the fallout from the reject unknown flags discussion a few weeks back. So to keep backwards compatibily we can't _reject_ unknown flags. But we'd better totally ignore them and don't pass them to file systems or back to userspace using fcntl.
Quoted 8 lines
Ack, this makes sense to me. It's crazy to let fcntl etc show bits that the kernel isn't even using.
I'm assuming this will come through Al eventually. It doesn't seem high-priority for me to worry about it just before the 4.11 release, but it might be worth marking for stable just to percolate the change eventually to other kernels, and keep these kinds of differences minimal.
Applied tonight, still hadn't pushed it out into -next - the tree goes through testing.
Quoted 5 lines · Linus Torvalds
I'm assuming this will come through Al eventually. It doesn't seem high-priority for me to worry about it just before the 4.11 release, but it might be worth marking for stable just to percolate the change eventually to other kernels, and keep these kinds of differences minimal.
Agreed. I just wanted you on Cc as your were very vocal on the issue.