fcntl: remove unused VALID_UPGRADE_FLAGS
Subsystems (3)
Christian Brauner
maintainerPATCH 1/3 fcntl: remove unused VALID_UPGRADE_FLAGS
From: Christian Brauner <[email protected]>
We currently do not maky use of this feature and should we implement something like this in the future it's trivial to add it back.
--- include/linux/fcntl.h | 4 ---- 1 file changed, 4 deletions(-)
include/linux/fcntl.h +0 -4
@@ -12,10 +12,6 @@ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) -/* List of all valid flags for the how->upgrade_mask argument: */ -#define VALID_UPGRADE_FLAGS \ - (UPGRADE_NOWRITE | UPGRADE_NOREAD) -/* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \
base-commit: d434405aaab7d0ebc516b68a8fc4100922d7f5ef
Signature · 1 line
2.27.0
Christian Brauner
maintainerPATCH 2/3 open: don't silently ignore unknown O-flags in openat2()
From: Christian Brauner <[email protected]>
The new openat2() syscall verifies that no unknown O-flag values are set and returns an error to userspace if they are while the older open syscalls like open() and openat2() simply ignore unknown flag values:
#define O_FLAG_CURRENTLY_INVALID (1 << 31)
struct open_how how = {
.flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID,
.resolve = 0,
};
/* fails */
fd = openat2(-EBADF, "/dev/null", &how, sizeof(how));
/* succeeds */
fd = openat(-EBADF, "/dev/null", O_RDONLY | O_FLAG_CURRENTLY_INVALID);However, openat2() silently truncates the upper 32 bits meaning:
#define O_FLAG_CURRENTLY_INVALID_LOWER32 (1 << 31)
#define O_FLAG_CURRENTLY_INVALID_UPPER32 (1 << 40)
struct open_how how_lowe32 = {
.flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32,
.resolve = 0,
};
struct open_how how_upper32 = {
.flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32,
.resolve = 0,
};
/* fails */
fd = openat2(-EBADF, "/dev/null", &how_lower32, sizeof(how_lower32));
/* succeeds */
fd = openat2(-EBADF, "/dev/null", &how_upper32, sizeof(how_upper32));That seems like a bug. Fix it by preventing the truncation in build_open_flags().
There's a snafu here though stripping FMODE_* directly from flags would cause the upper 32 bits to be truncated as well due to integer promotion rules since FMODE_* is unsigned int, O_* are signed ints (yuck).
This change shouldn't regress old open syscalls since they silently truncate any unknown values.
--- fs/open.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/open.c +8 -3
@@ -1002,12 +1002,17 @@ inline struct open_how build_open_how(int flags, umode_t mode)inline int build_open_flags (const struct open_how *how,struct open_flags *op) { -int flags = how->flags; +u64 flags = how->flags; +u64 strip =FMODE_NONOTIFY |O_CLOEXEC ;int lookup_flags =0 ;int acc_mode =ACC_MODE (flags); -/* Must never be set by userspace */ - flags &= ~(FMODE_NONOTIFY |O_CLOEXEC ); +/* +* Strip flags that either shouldn't be set by userspace like +* FMODE_NONOTIFY or that aren't relevant in determining struct +* open_flags like O_CLOEXEC. +*/ + flags &= ~strip;/* * Older syscalls implicitly clear all of the invalid flags or argument
Signature · 1 line
2.27.0
Re: [PATCH 2/3] open: don't silently ignore unknown O-flags in openat2()
Quoted 71 lines · Christian Brauner
From: Christian Brauner <[email protected]>
The new
openat2()syscall verifies that no unknown O-flag values are set and returns an error to userspace if they are while the older open syscalls likeopen()andopenat2()simply ignore unknown flag values:#define O_FLAG_CURRENTLY_INVALID (1 << 31) struct open_how how = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID, .resolve = 0, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how, sizeof(how)); /* succeeds */ fd = openat(-EBADF, "/dev/null", O_RDONLY | O_FLAG_CURRENTLY_INVALID);However,
openat2()silently truncates the upper 32 bits meaning:#define O_FLAG_CURRENTLY_INVALID_LOWER32 (1 << 31) #define O_FLAG_CURRENTLY_INVALID_UPPER32 (1 << 40) struct open_how how_lowe32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32, .resolve = 0, }; struct open_how how_upper32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32, .resolve = 0, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how_lower32, sizeof(how_lower32)); /* succeeds */ fd = openat2(-EBADF, "/dev/null", &how_upper32, sizeof(how_upper32));That seems like a bug. Fix it by preventing the truncation in
build_open_flags().There's a snafu here though stripping FMODE_* directly from flags would cause the upper 32 bits to be truncated as well due to integer promotion rules since FMODE_* is unsigned int, O_* are signed ints (yuck).
This change shouldn't regress old open syscalls since they silently truncate any unknown values.
Cc Christoph Hellwig <[email protected]>Cc Aleksa Sarai <[email protected]>Cc Al Viro <[email protected]>Reported-by Richard Guy Briggs <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- fs/open.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)fs/open.c +2
-1@@ -1002,12 +1002,17 @@ inline struct open_how build_open_how(int flags, umode_t mode)inline int build_open_flags (const struct open_how *how,struct open_flags *op) { -int flags = how->flags; +u64 flags = how->flags; +u64 strip =FMODE_NONOTIFY |O_CLOEXEC ;int lookup_flags =0 ;
fs/open.c inline struct open_how build_open_how(int flags, umode_t mode) · line 1015
Quoted 10 lines
fs/open.c +6
-2int acc_mode =ACC_MODE (flags); -/* Must never be set by userspace */ - flags &= ~(FMODE_NONOTIFY |O_CLOEXEC ); +/* +* Strip flags that either shouldn't be set by userspace like +* FMODE_NONOTIFY or that aren't relevant in determining struct +* open_flags like O_CLOEXEC. +*/ + flags &= ~strip;
Would it not be simpler to only change flags' type (and elaborated comment) and leave the original strip or will that run afoul of FMODE_* type clamping to u32?
To guard against this assignment of u64 flags to op->open_flags losing info in the future further down in this function, it would be necessary to add something like the following that you suggested to include/linux/fcntl.h following the definition of VALID_OPEN_FLAGS:
BUILD_BUG_ON_MSG(upper_32_bits(VALID_OPEN_FLAGS), "will be ignored by open_flags assignment in build_open_flags()");
A similar check could be added for O_ACCMODE for 32 bits in general, and for 8 bits for Tomoyo.
Quoted 4 lines
fs/open.c +0
-0/* * Older syscalls implicitly clear all of the invalid flags or argument Signature · 1 line
2.27.0
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH 2/3] open: don't silently ignore unknown O-flags in openat2()
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
There's a snafu here though stripping FMODE_* directly from flags would cause the upper 32 bits to be truncated as well due to integer promotion rules since FMODE_* is unsigned int, O_* are signed ints (yuck).
This change shouldn't regress old open syscalls since they silently truncate any unknown values.
So, this is a change in behavior for openat. But given how new it is and there are not flags defined yet in the truncated range I think we should be fine:
Re: [PATCH 2/3] open: don't silently ignore unknown O-flags in openat2()
In reply to Christian BraunerQuoted 40 lines · Christian Brauner
The new
openat2()syscall verifies that no unknown O-flag values are set and returns an error to userspace if they are while the older open syscalls likeopen()andopenat2()simply ignore unknown flag values:#define O_FLAG_CURRENTLY_INVALID (1 << 31) struct open_how how = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID, .resolve = 0, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how, sizeof(how)); /* succeeds */ fd = openat(-EBADF, "/dev/null", O_RDONLY | O_FLAG_CURRENTLY_INVALID);However,
openat2()silently truncates the upper 32 bits meaning:#define O_FLAG_CURRENTLY_INVALID_LOWER32 (1 << 31) #define O_FLAG_CURRENTLY_INVALID_UPPER32 (1 << 40) struct open_how how_lowe32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32, .resolve = 0, }; struct open_how how_upper32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWE32, .resolve = 0, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how_lower32, sizeof(how_lower32)); /* succeeds */ fd = openat2(-EBADF, "/dev/null", &how_upper32, sizeof(how_upper32));That seems like a bug. Fix it by preventing the truncation in
build_open_flags().
Quoted 6 lines
There's a snafu here though stripping FMODE_* directly from flags would cause the upper 32 bits to be truncated as well due to integer promotion rules since FMODE_* is unsigned int, O_* are signed ints (yuck).
This change shouldn't regress old open syscalls since they silently truncate any unknown values.
Yeah, oops on my part (I was always worried I'd missed something with making everything -EINVAL).
Signature · 4 lines
Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH <https://www.cyphar.com/>
Christian Brauner
maintainerPATCH 3/3 test: add openat2() test for invalid upper 32 bit flag value
In reply to Christian BraunerFrom: Christian Brauner <[email protected]>
Test that openat2() rejects unknown flags in the upper 32 bit range.
--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/openat2/openat2_test.c +6 -1
@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {
@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL }, };BUILD_BUG_ON (ARRAY_LEN (tests) !=NUM_OPENAT2_FLAG_TESTS );
Signature · 1 line
2.27.0
Re: [PATCH 3/3] test: add openat2() test for invalid upper 32 bit flag value
Quoted 26 lines · Christian Brauner
From: Christian Brauner <[email protected]>
Test that
openat2()rejects unknown flags in the upper 32 bit range.Cc Richard Guy Briggs <[email protected]>Cc Aleksa Sarai <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/testing/selftests/openat2/openat2_test.c +1
-1@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {
tools/testing/selftests/openat2/openat2_test.c void test_openat2_flags(void) · line 236
Quoted 8 lines
tools/testing/selftests/openat2/openat2_test.c +5
-0@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL },
This doesn't appear to specifically test for flags over 32 bits. It appears to test for flags not included in VALID_OPEN_FLAGS.
"1ULL << 2" would accomplish the same thing, as would "1ULL << 31" due to the unused flags in the bottom 32 bits.
The test appears to be useful, but misnamed.
If a new flag was added at 1ULL << 33, this test wouldn't notice and it would still get dropped in build_open_flags() when flags gets assigned to op->open_flags.
Quoted 6 lines
tools/testing/selftests/openat2/openat2_test.c +0
-0};BUILD_BUG_ON (ARRAY_LEN (tests) !=NUM_OPENAT2_FLAG_TESTS );Signature · 1 line
2.27.0
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH 3/3] test: add openat2() test for invalid upper 32 bit flag value
Quoted 39 lines · Richard Guy Briggs
Quoted 26 lines · Christian Brauner
From: Christian Brauner <[email protected]>
Test that
openat2()rejects unknown flags in the upper 32 bit range.Cc Richard Guy Briggs <[email protected]>Cc Aleksa Sarai <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/testing/selftests/openat2/openat2_test.c +1
-1@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {tools/testing/selftests/openat2/openat2_test.c void test_openat2_flags(void) · line 236
Quoted 8 lines
tools/testing/selftests/openat2/openat2_test.c +5
-0@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL },This doesn't appear to specifically test for flags over 32 bits. It appears to test for flags not included in
VALID_OPEN_FLAGS.
Quoted 4 lines
"1ULL << 2" would accomplish the same thing, as would "1ULL << 31" due to the unused flags in the bottom 32 bits.
The test appears to be useful, but misnamed.
I mean we can name it test "currently unknown upper bit".
Quoted 2 lines
If a new flag was added at 1ULL << 33, this test wouldn't notice and it
It isn't supposed to notice because it's a known flag. If we add #define O_FANCY (1ULL << 63)
this test should fail and either would need to be adapted or more likely be dropped since all bits are taken apparently.
Quoted 2 lines
would still get dropped in
build_open_flags()when flags gets assigned toop->open_flags.
I didn't intend to add a test whether flags are silently dropped. I intended to add a test whether any currently unkown bit in the upper 32 bits is loudly rejected instead of silently ignored.
I may misunderstand what kind of test you would like to see here.
Christian
Re: [PATCH 3/3] test: add openat2() test for invalid upper 32 bit flag value
Quoted 48 lines · Christian Brauner
Quoted 39 lines · Richard Guy Briggs
Quoted 26 lines · Christian Brauner
From: Christian Brauner <[email protected]>
Test that
openat2()rejects unknown flags in the upper 32 bit range.Cc Richard Guy Briggs <[email protected]>Cc Aleksa Sarai <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/testing/selftests/openat2/openat2_test.c +1
-1@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {tools/testing/selftests/openat2/openat2_test.c void test_openat2_flags(void) · line 236
Quoted 8 lines
tools/testing/selftests/openat2/openat2_test.c +5
-0@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL },This doesn't appear to specifically test for flags over 32 bits. It appears to test for flags not included in
VALID_OPEN_FLAGS.Quoted 4 lines
"1ULL << 2" would accomplish the same thing, as would "1ULL << 31" due to the unused flags in the bottom 32 bits.
The test appears to be useful, but misnamed.
I mean we can name it test "currently unknown upper bit".
Quoted 1 line
Quoted 6 lines
Quoted 1 line
If a new flag was added at 1ULL << 33, this test wouldn't notice and it
It isn't supposed to notice because it's a known flag. If we add #define
O_FANCY(1ULL << 63)
this test should fail and either would need to be adapted or more likely be dropped since all bits are taken apparently.
If that O_FANCY was added to VALID_OPEN_FLAGS, then this test would fail to fail since the check in build_open_flags() would have no problem with it.
Quoted 6 lines
Quoted 2 lines
would still get dropped in
build_open_flags()when flags gets assigned toop->open_flags.I didn't intend to add a test whether flags are silently dropped. I intended to add a test whether any currently unkown bit in the upper 32 bits is loudly rejected instead of silently ignored.
It appears to be testing for unknown flags regardless of where they are in the 64 bits, since the incoming flags are tested against VALID_OPEN_FLAGS.
Quoted 1 line
I may misunderstand what kind of test you would like to see here.
I think we need two tests:
1) test for unknown flags
2) test for flags that will get dropped in build_open_flags() by the assignment from (u64) how->flags to (int) op->open_flag.
This second test could be a BUILD_* test.
Quoted 1 line
Christian
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH 3/3] test: add openat2() test for invalid upper 32 bit flag value
Quoted 51 lines · Richard Guy Briggs
Quoted 50 lines · Christian Brauner
Quoted 39 lines · Richard Guy Briggs
Quoted 26 lines · Christian Brauner
From: Christian Brauner <[email protected]>
Test that
openat2()rejects unknown flags in the upper 32 bit range.Cc Richard Guy Briggs <[email protected]>Cc Aleksa Sarai <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/testing/selftests/openat2/openat2_test.c +1
-1@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {tools/testing/selftests/openat2/openat2_test.c void test_openat2_flags(void) · line 236
Quoted 8 lines
tools/testing/selftests/openat2/openat2_test.c +5
-0@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL },This doesn't appear to specifically test for flags over 32 bits. It appears to test for flags not included in
VALID_OPEN_FLAGS.Quoted 4 lines
"1ULL << 2" would accomplish the same thing, as would "1ULL << 31" due to the unused flags in the bottom 32 bits.
The test appears to be useful, but misnamed.
I mean we can name it test "currently unknown upper bit".
Quoted 2 lines
If a new flag was added at 1ULL << 33, this test wouldn't notice and it
Quoted 8 lines
Quoted 4 lines
It isn't supposed to notice because it's a known flag. If we add #define
O_FANCY(1ULL << 63)
this test should fail and either would need to be adapted or more likely be dropped since all bits are taken apparently.If that
O_FANCYwas added toVALID_OPEN_FLAGS, then this test would fail to fail since the check inbuild_open_flags()would have no problem with it.
Right but that's perfectly fine and just means you need to update the test. That's why this is 1ULL << 63 which moves this way into the future.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
would still get dropped in
build_open_flags()when flags gets assigned toop->open_flags.I didn't intend to add a test whether flags are silently dropped. I intended to add a test whether any currently unkown bit in the upper 32 bits is loudly rejected instead of silently ignored.
It appears to be testing for unknown flags regardless of where they are in the 64 bits, since the incoming flags are tested against
VALID_OPEN_FLAGS.
I fail to see the fundamental issue (even with the name) but I happily rename it to "currently unknown bit in upper 32 bits rejected" to indicate that.
Quoted 10 lines
Quoted 2 lines
I may misunderstand what kind of test you would like to see here.
I think we need two tests:
1) test for unknown flags
2) test for flags that will get dropped inbuild_open_flags()by the assignment from (u64)how->flagsto (int)op->open_flag.This second test could be a BUILD_* test.
Yes, that makes sense. Thank you.
I think that can be a build test based on VALID_OPEN_FLAGS. I think the assumption that any new flag needs to be added to this define is perfectly fine?
Christian
Re: [PATCH 3/3] test: add openat2() test for invalid upper 32 bit flag value
Quoted 57 lines · Christian Brauner
Quoted 56 lines · Richard Guy Briggs
Quoted 54 lines · Christian Brauner
Quoted 39 lines · Richard Guy Briggs
Quoted 26 lines · Christian Brauner
From: Christian Brauner <[email protected]>
Test that
openat2()rejects unknown flags in the upper 32 bit range.Cc Richard Guy Briggs <[email protected]>Cc Aleksa Sarai <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/testing/selftests/openat2/openat2_test.c +1
-1@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 24 +#define NUM_OPENAT2_FLAG_TESTS 25void test_openat2_flags (void ) {tools/testing/selftests/openat2/openat2_test.c void test_openat2_flags(void) · line 236
Quoted 8 lines
tools/testing/selftests/openat2/openat2_test.c +5
-0@@ -229,6 +229,11 @@ void test_openat2_flags(void) { .name = "invalid how.resolve and O_PATH", .how.flags = O_PATH, .how.resolve = 0x1337, .err = -EINVAL }, + + /* Invalid flags in the upper 32 bits must be rejected. */ + { .name = "invalid flags (1 << 63)", + .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = -EINVAL },This doesn't appear to specifically test for flags over 32 bits. It appears to test for flags not included in
VALID_OPEN_FLAGS.Quoted 4 lines
"1ULL << 2" would accomplish the same thing, as would "1ULL << 31" due to the unused flags in the bottom 32 bits.
The test appears to be useful, but misnamed.
I mean we can name it test "currently unknown upper bit".
Quoted 2 lines
If a new flag was added at 1ULL << 33, this test wouldn't notice and it
It isn't supposed to notice because it's a known flag. If we add #define
O_FANCY(1ULL << 63)
this test should fail and either would need to be adapted or more likely be dropped since all bits are taken apparently.
Quoted 7 lines
Quoted 3 lines
If that
O_FANCYwas added toVALID_OPEN_FLAGS, then this test would fail to fail since the check inbuild_open_flags()would have no problem with it.Right but that's perfectly fine and just means you need to update the test. That's why this is 1ULL << 63 which moves this way into the future.
It is temping to change the test to (-1ULL & ~VALID_OPEN_FLAGS) to catch any outside what has been expressly defined. (Not certain about syntax...)
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
would still get dropped in
build_open_flags()when flags gets assigned toop->open_flags.I didn't intend to add a test whether flags are silently dropped. I intended to add a test whether any currently unkown bit in the upper 32 bits is loudly rejected instead of silently ignored.
Quoted 7 lines
Quoted 3 lines
It appears to be testing for unknown flags regardless of where they are in the 64 bits, since the incoming flags are tested against
VALID_OPEN_FLAGS.I fail to see the fundamental issue (even with the name) but I happily rename it to "currently unknown bit in upper 32 bits rejected" to indicate that.
How about "currently unknown bit rejected"?
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
I may misunderstand what kind of test you would like to see here.
I think we need two tests:
1) test for unknown flags
2) test for flags that will get dropped inbuild_open_flags()by the assignment from (u64)how->flagsto (int)op->open_flag.
Quoted 6 lines
Quoted 1 line
This second test could be a BUILD_* test.
Yes, that makes sense. Thank you.
I think that can be a build test based onVALID_OPEN_FLAGS. I think the assumption that any new flag needs to be added to this define is perfectly fine?
I don't see how else we can do this other than to throw a runtime error which will happen anyways the first time userspace tries to use a new flag that isn't included in VALID_OPEN_FLAGS in the first place, so I think this is a safe assumption.
Quoted 1 line
Christian
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Quoted 10 lines · Christian Brauner
From: Christian Brauner <[email protected]>
We currently do not maky use of this feature and should we implement something like this in the future it's trivial to add it back.
Cc Christoph Hellwig <[email protected]>Cc Aleksa Sarai <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Quoted 20 lines
--- include/linux/fcntl.h | 4 ---- 1 file changed, 4 deletions(-)include/linux/fcntl.h +0
-4@@ -12,10 +12,6 @@ FASYNC | O_DIRECT | O_LARGEFILE | O_DIRECTORY | O_NOFOLLOW | \ O_NOATIME | O_CLOEXEC | O_PATH | __O_TMPFILE) -/* List of all valid flags for the how->upgrade_mask argument: */ -#define VALID_UPGRADE_FLAGS \ - (UPGRADE_NOWRITE | UPGRADE_NOREAD) -/* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \
Quoted 4 lines
base-commit:
d434405aaab7d0ebc516b68a8fc4100922d7f5efSignature · 1 line
2.27.0
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Quoted 4 lines · Christian Brauner
From: Christian Brauner <[email protected]>
We currently do not maky use of this feature and should we implement something like this in the future it's trivial to add it back.
Looks like that ->upgrade_mask field never made it into mainline?
Either way removing and unused mask always seems valid, so: