openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
v2 cover openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
This was an oversight in the original implementation, as it makes no sense to specify both scoping flags to the same openat2(2) invocation (before this patch, the result of such an invocation was equivalent to RESOLVE_IN_ROOT being ignored).
This is a userspace-visible ABI change, but the only user of openat2(2) at the moment is LXC which doesn't specify both flags and so no userspace programs will break as a result.
Changelog:
v2: Split patch so as to separate selftest changes. [Shuah Khan]
v1: <https://lore.kernel.org/lkml/[email protected]/>
Aleksa Sarai (2):
openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
selftests: openat2: add RESOLVE_ conflict test
fs/open.c | 4 ++++ tools/testing/selftests/openat2/openat2_test.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
Signature · 6 lines
2.29.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v2 1/2 openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
This was an oversight in the original implementation, as it makes no sense to specify both scoping flags to the same openat2(2) invocation (before this patch, the result of such an invocation was equivalent to RESOLVE_IN_ROOT being ignored).
This is a userspace-visible ABI change, but the only user of openat2(2) at the moment is LXC which doesn't specify both flags and so no userspace programs will break as a result.
--- fs/open.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/open.c +4 -0
@@ -1010,6 +1010,10 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)if (how->resolve & ~VALID_RESOLVE_FLAGS )return -EINVAL ; +/* Scoping flags are mutually exclusive. */ +if ((how->resolve &RESOLVE_BENEATH ) && (how->resolve &RESOLVE_IN_ROOT )) +return -EINVAL ; +/* Deal with the mode. */ if (WILL_CREATE (flags)) {if (how->mode & ~S_IALLUGO )
Signature · 6 lines
2.29.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v2 2/2 selftests: openat2: add RESOLVE_ conflict test
In reply to Aleksa SaraiNow that we reject conflicting RESOLVE_ flags, add a selftest to avoid regressions.
--- tools/testing/selftests/openat2/openat2_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/openat2/openat2_test.c +7 -1
@@ -155,7 +155,7 @@ struct flag_test {int err; }; -#define NUM_OPENAT2_FLAG_TESTS 23 +#define NUM_OPENAT2_FLAG_TESTS 24void test_openat2_flags (void ) {
@@ -210,6 +210,12 @@ void test_openat2_flags(void) .how.flags = O_TMPFILE | O_RDWR, .how.mode = 0x0000A00000000000ULL, .err = -EINVAL }, +/* ->resolve flags must not conflict. */ + { .name = "incompatible resolve flags (BENEATH | IN_ROOT)", + .how.flags = O_RDONLY, + .how.resolve = RESOLVE_BENEATH | RESOLVE_IN_ROOT, + .err = -EINVAL }, + /* ->resolve must only contain RESOLVE_* flags. */ { .name = "invalid how.resolve and O_RDONLY", .how.flags = O_RDONLY,
Signature · 6 lines
2.29.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Quoted 13 lines · Aleksa Sarai
This was an oversight in the original implementation, as it makes no sense to specify both scoping flags to the same openat2(2) invocation (before this patch, the result of such an invocation was equivalent to
RESOLVE_IN_ROOTbeing ignored).This is a userspace-visible ABI change, but the only user of openat2(2) at the moment is LXC which doesn't specify both flags and so no userspace programs will break as a result.
Changelog:
v2: Split patch so as to separate selftest changes. [Shuah Khan]
v1: <https://lore.kernel.org/lkml/[email protected]/>
Quoted 7 lines
Aleksa Sarai (2):
openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
selftests: openat2: addRESOLVE_conflict testfs/open.c | 4 ++++ tools/testing/selftests/openat2/openat2_test.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
I've applied this patchset now. There's no need to have this sit around another merge window. I'm happy to drop it again in case you're picking it up later, Al.
Thanks!
Christian
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers