All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
@ 2020-10-07 10:36 ` Aleksa Sarai
  0 siblings, 0 replies; 7+ messages in thread
From: Aleksa Sarai @ 2020-10-07 10:36 UTC (permalink / raw)
  To: Alexander Viro, Shuah Khan
  Cc: containers, linux-kernel, stable, linux-kselftest, linux-fsdevel

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: <stable@vger.kernel.org> # v5.6+
Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
 fs/open.c                                      | 4 ++++
 tools/testing/selftests/openat2/openat2_test.c | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index 9af548fb841b..4d7537ae59df 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -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)
diff --git a/tools/testing/selftests/openat2/openat2_test.c b/tools/testing/selftests/openat2/openat2_test.c
index b386367c606b..381d874cce99 100644
--- a/tools/testing/selftests/openat2/openat2_test.c
+++ b/tools/testing/selftests/openat2/openat2_test.c
@@ -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,
-- 
2.28.0

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
@ 2020-10-07 10:36 ` Aleksa Sarai
  0 siblings, 0 replies; 7+ messages in thread
From: Aleksa Sarai @ 2020-10-07 10:36 UTC (permalink / raw)
  To: Alexander Viro, Shuah Khan
  Cc: Aleksa Sarai, stable, Christian Brauner, containers,
	linux-fsdevel, linux-kselftest, linux-kernel

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: <stable@vger.kernel.org> # v5.6+
Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
 fs/open.c                                      | 4 ++++
 tools/testing/selftests/openat2/openat2_test.c | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index 9af548fb841b..4d7537ae59df 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -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)
diff --git a/tools/testing/selftests/openat2/openat2_test.c b/tools/testing/selftests/openat2/openat2_test.c
index b386367c606b..381d874cce99 100644
--- a/tools/testing/selftests/openat2/openat2_test.c
+++ b/tools/testing/selftests/openat2/openat2_test.c
@@ -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,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
  2020-10-07 10:36 ` Aleksa Sarai
@ 2020-10-09 11:50   ` Christian Brauner
  -1 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2020-10-09 11:50 UTC (permalink / raw)
  To: Aleksa Sarai
  Cc: containers, linux-kernel, stable, Alexander Viro,
	linux-kselftest, linux-fsdevel, Shuah Khan

On Wed, Oct 07, 2020 at 09:36:08PM +1100, Aleksa Sarai wrote:
> 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!

> 
> Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: <stable@vger.kernel.org> # v5.6+
> ---

Thanks! This is a good fix imho.
Christian
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
@ 2020-10-09 11:50   ` Christian Brauner
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2020-10-09 11:50 UTC (permalink / raw)
  To: Aleksa Sarai
  Cc: Alexander Viro, Shuah Khan, containers, linux-kernel, stable,
	linux-kselftest, linux-fsdevel

On Wed, Oct 07, 2020 at 09:36:08PM +1100, Aleksa Sarai wrote:
> 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!

> 
> Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: <stable@vger.kernel.org> # v5.6+
> ---

Thanks! This is a good fix imho.
Christian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
  2020-10-07 10:36 ` Aleksa Sarai
@ 2020-10-27 22:28   ` Shuah Khan
  -1 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2020-10-27 22:28 UTC (permalink / raw)
  To: Aleksa Sarai, Alexander Viro, Shuah Khan
  Cc: containers, linux-kernel, stable, linux-kselftest, Shuah Khan,
	linux-fsdevel

On 10/7/20 4:36 AM, Aleksa Sarai wrote:
> 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: <stable@vger.kernel.org> # v5.6+
> Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> ---
>   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
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
@ 2020-10-27 22:28   ` Shuah Khan
  0 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2020-10-27 22:28 UTC (permalink / raw)
  To: Aleksa Sarai, Alexander Viro, Shuah Khan
  Cc: stable, Christian Brauner, containers, linux-fsdevel,
	linux-kselftest, linux-kernel, Shuah Khan

On 10/7/20 4:36 AM, Aleksa Sarai wrote:
> 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: <stable@vger.kernel.org> # v5.6+
> Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> ---
>   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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT
  2020-10-27 22:28   ` Shuah Khan
  (?)
@ 2020-10-27 23:39   ` Aleksa Sarai
  -1 siblings, 0 replies; 7+ messages in thread
From: Aleksa Sarai @ 2020-10-27 23:39 UTC (permalink / raw)
  To: Shuah Khan
  Cc: containers, linux-kernel, stable, Alexander Viro,
	linux-kselftest, linux-fsdevel, Shuah Khan


[-- Attachment #1.1: Type: text/plain, Size: 1236 bytes --]

On 2020-10-27, Shuah Khan <skhan@linuxfoundation.org> wrote:
> On 10/7/20 4:36 AM, Aleksa Sarai wrote:
> > 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: <stable@vger.kernel.org> # v5.6+
> > Fixes: fddb5d430ad9 ("open: introduce openat2(2) syscall")
> > Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
> > Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> > ---
> >   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.

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

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

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 171 bytes --]

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-10-27 23:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 10:36 [PATCH] openat2: reject RESOLVE_BENEATH|RESOLVE_IN_ROOT Aleksa Sarai
2020-10-07 10:36 ` Aleksa Sarai
2020-10-09 11:50 ` Christian Brauner
2020-10-09 11:50   ` Christian Brauner
2020-10-27 22:28 ` Shuah Khan
2020-10-27 22:28   ` Shuah Khan
2020-10-27 23:39   ` Aleksa Sarai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.