Skip to contentSkip to conversation

openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT

PATCH Superseded Aleksa Sarai 3 participants 4 messages Oct 7, 2020 – Oct 27, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc <[email protected]> # v5.6+
Fixes fddb5d430ad9 ("open: introduce openat2(2) syscall")
---
 fs/open.c                                      | 4 ++++
 tools/testing/selftests/openat2/openat2_test.c | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
fs/open.c +4 -0
index 9af548fb841b..4d7537ae59df 100644
@@ -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)
tools/testing/selftests/openat2/openat2_test.c +7 -1
index b386367c606b..381d874cce99 100644
@@ -155,7 +155,7 @@ struct flag_test {
 	int err;
 };
 
-#define NUM_OPENAT2_FLAG_TESTS 23
+#define NUM_OPENAT2_FLAG_TESTS 24
 
 void 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 · 1 line
2.28.0
#1 lore raw
Quoted 8 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_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.

Indeed!

Quoted 6 lines
Fixes fddb5d430ad9 ("open: introduce openat2(2) syscall")
Cc <[email protected]> # v5.6+

---

Thanks! This is a good fix imho.
Christian

maintainer
#2 lore raw
In reply to Aleksa Sarai
Quoted 9 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_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.

Quoted 7 lines
Cc <[email protected]> # v5.6+
Fixes fddb5d430ad9 ("open: introduce openat2(2) syscall")
---
  fs/open.c                                      | 4 +++
  tools/testing/selftests/openat2/openat2_test.c | 8 +++++++-

You are combining fs change with selftest change.

Is there a reason why these two changes are combined? 2 separate patches is better.

thanks,
-- Shuah

#3 lore raw
Quoted 18 lines · Shuah Khan
Quoted 9 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_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.

Quoted 7 lines
Cc <[email protected]> # v5.6+
Fixes fddb5d430ad9 ("open: introduce openat2(2) syscall")
---
  fs/open.c                                      | 4 +++
  tools/testing/selftests/openat2/openat2_test.c | 8 +++++++-
Quoted 4 lines

You are combining fs change with selftest change.

Is there a reason why these two changes are combined? 2 separate patches is better.

Not really, I'll split it into two patches.

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>

_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers