* [PATCH 0/2] listns(): validate the reserved spare2 field
@ 2026-11-28 14:06 Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 1/2] nstree: reject a non-zero spare2 in the listns() request Nikolai Dokutovich
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Nikolai Dokutovich @ 2026-11-28 14:06 UTC (permalink / raw)
To: Christian Brauner
Cc: linux-fsdevel, Alexander Viro, Jan Kara, Jeff Layton,
linux-kernel, stable, Nikolai Dokutovich
copy_ns_id_req() rejects a non-zero @spare but not @spare2, although
struct ns_id_req documents both as reserved. Validate @spare2 the same
way, and extend the error-case selftest to cover it instead of only
@spare.
Nikolai Dokutovich (2):
nstree: reject a non-zero spare2 in the listns() request
selftests/namespaces: check that listns() rejects a non-zero spare2
kernel/nstree.c | 2 +-
tools/testing/selftests/namespaces/listns_test.c | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] nstree: reject a non-zero spare2 in the listns() request
2026-11-28 14:06 [PATCH 0/2] listns(): validate the reserved spare2 field Nikolai Dokutovich
@ 2026-11-28 14:06 ` Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 2/2] selftests/namespaces: check that listns() rejects a non-zero spare2 Nikolai Dokutovich
2026-11-28 15:44 ` [PATCH 0/2] listns(): validate the reserved spare2 field Bradley Morgan
2 siblings, 0 replies; 5+ messages in thread
From: Nikolai Dokutovich @ 2026-11-28 14:06 UTC (permalink / raw)
To: Christian Brauner
Cc: linux-fsdevel, Alexander Viro, Jan Kara, Jeff Layton,
linux-kernel, stable, Nikolai Dokutovich
struct ns_id_req documents @spare2 as reserved, and copy_ns_id_req()
already rejects a non-zero @spare. Reject a non-zero @spare2 the same
way so that both reserved fields are validated consistently and the
field can be given a meaning later without having to keep accepting
callers that filled it with arbitrary bits.
This makes kernels that already have listns() reject a value they used
to accept; no valid caller has a reason to set the field.
Fixes: 76b6f5dfb3fd ("nstree: add listns()")
Cc: stable@vger.kernel.org
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
kernel/nstree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/nstree.c b/kernel/nstree.c
index 44e07d0fa8e5..ba5743dd4f17 100644
--- a/kernel/nstree.c
+++ b/kernel/nstree.c
@@ -437,7 +437,7 @@ static int copy_ns_id_req(const struct ns_id_req __user *req,
ret = copy_struct_from_user(kreq, sizeof(*kreq), req, usize);
if (ret)
return ret;
- if (kreq->spare != 0)
+ if (kreq->spare != 0 || kreq->spare2 != 0)
return -EINVAL;
if (kreq->ns_type & ~NS_ALL)
return -EOPNOTSUPP;
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] selftests/namespaces: check that listns() rejects a non-zero spare2
2026-11-28 14:06 [PATCH 0/2] listns(): validate the reserved spare2 field Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 1/2] nstree: reject a non-zero spare2 in the listns() request Nikolai Dokutovich
@ 2026-11-28 14:06 ` Nikolai Dokutovich
2026-11-28 15:44 ` [PATCH 0/2] listns(): validate the reserved spare2 field Bradley Morgan
2 siblings, 0 replies; 5+ messages in thread
From: Nikolai Dokutovich @ 2026-11-28 14:06 UTC (permalink / raw)
To: Christian Brauner
Cc: linux-fsdevel, Alexander Viro, Jan Kara, Jeff Layton,
linux-kernel, stable, Nikolai Dokutovich
copy_ns_id_req() rejects a non-zero reserved field. Extend the error
case test to cover @spare2 as well as @spare.
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
tools/testing/selftests/namespaces/listns_test.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/namespaces/listns_test.c b/tools/testing/selftests/namespaces/listns_test.c
index 538d60f908b4..c52b02bd416a 100644
--- a/tools/testing/selftests/namespaces/listns_test.c
+++ b/tools/testing/selftests/namespaces/listns_test.c
@@ -667,6 +667,17 @@ TEST(listns_error_cases)
}
req.spare = 0;
+ /* Test with invalid spare2 field */
+ req.spare2 = 1;
+ ret = sys_listns(&req, ns_ids, ARRAY_SIZE(ns_ids), 0);
+ if (errno == ENOSYS) {
+ /* listns() not supported, skip this check */
+ } else {
+ ASSERT_LT(ret, 0);
+ ASSERT_EQ(errno, EINVAL);
+ }
+ req.spare2 = 0;
+
/* Test with huge nr_ns_ids */
ret = sys_listns(&req, ns_ids, 2000000, 0);
if (errno == ENOSYS) {
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] listns(): validate the reserved spare2 field
2026-11-28 14:06 [PATCH 0/2] listns(): validate the reserved spare2 field Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 1/2] nstree: reject a non-zero spare2 in the listns() request Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 2/2] selftests/namespaces: check that listns() rejects a non-zero spare2 Nikolai Dokutovich
@ 2026-11-28 15:44 ` Bradley Morgan
2026-11-28 15:49 ` Bradley Morgan
2 siblings, 1 reply; 5+ messages in thread
From: Bradley Morgan @ 2026-11-28 15:44 UTC (permalink / raw)
To: ndokutovich
Cc: brauner, jack, jlayton, linux-fsdevel, linux-kernel, stable, viro
On 28 November 2026 14:06:21 GMT, Nikolai Dokutovich
<ndokutovich@gmail.com> wrote:
>copy_ns_id_req() rejects a non-zero @spare but not @spare2, although
>struct ns_id_req documents both as reserved. Validate @spare2 the same
>way, and extend the error-case selftest to cover it instead of only
>@spare.
>
>Nikolai Dokutovich (2):
> nstree: reject a non-zero spare2 in the listns() request
> selftests/namespaces: check that listns() rejects a non-zero spare2
Had a nice read through, thanks for the tests, for the whole series, let's
put,
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
Also, a nice question, since I tend to be a bit ^Winsane^W
Is this bug a edge case? Most bugs found nowadays in the kernel are edge
cases, but they would still need to be merged, because again, it's still a
case that can be reached.
My question to you, is could this bug be actually reached? Like, would a
future caller set spare2 as non zero? would the driver maintainer for
example be silly enough to set non zero spare2, probably knowing the
consequences (if they understood the code), well, if they didn't, it'd be
their problem, no?
I had a look at some callers, mostly selftests, and they all patch up this
correctly, so this wouldn't be reachable RIGHT now. I added my tag because
we will have to account for the future callers silliness (adding non zero
spare2)...
>
> kernel/nstree.c | 2 +-
> tools/testing/selftests/namespaces/listns_test.c | 11 +++++++++++
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
>
--- Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] listns(): validate the reserved spare2 field
2026-11-28 15:44 ` [PATCH 0/2] listns(): validate the reserved spare2 field Bradley Morgan
@ 2026-11-28 15:49 ` Bradley Morgan
0 siblings, 0 replies; 5+ messages in thread
From: Bradley Morgan @ 2026-11-28 15:49 UTC (permalink / raw)
To: ndokutovich
Cc: brauner, jack, jlayton, linux-fsdevel, linux-kernel, stable, viro
On 28 November 2026 15:44:07 GMT, Bradley Morgan <bradley.morgan@linux.dev>
wrote:
>On 28 November 2026 14:06:21 GMT, Nikolai Dokutovich
><ndokutovich@gmail.com> wrote:
>>copy_ns_id_req() rejects a non-zero @spare but not @spare2, although
>>struct ns_id_req documents both as reserved. Validate @spare2 the same
>>way, and extend the error-case selftest to cover it instead of only
>>@spare.
>>
>>Nikolai Dokutovich (2):
>> nstree: reject a non-zero spare2 in the listns() request
>> selftests/namespaces: check that listns() rejects a non-zero spare2
>
>Had a nice read through, thanks for the tests, for the whole series, let's
>put,
>
>Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>
>Also, a nice question, since I tend to be a bit ^Winsane^W
>
>Is this bug a edge case? Most bugs found nowadays in the kernel are edge
>cases, but they would still need to be merged, because again, it's still a
>case that can be reached.
>
>My question to you, is could this bug be actually reached? Like, would a
>future caller set spare2 as non zero? would the driver maintainer for
>example be silly enough to set non zero spare2, probably knowing the
>consequences (if they understood the code), well, if they didn't, it'd be
>their problem, no?
Aw I was wrong, sorry, the function is called thru tests and as a syscall.
Apologies for the wrongness :(
R-B stands.
>
>I had a look at some callers, mostly selftests, and they all patch up this
>correctly, so this wouldn't be reachable RIGHT now. I added my tag because
>we will have to account for the future callers silliness (adding non zero
>spare2)...
>
>
>
>>
>> kernel/nstree.c | 2 +-
>> tools/testing/selftests/namespaces/listns_test.c | 11 +++++++++++
>> 2 files changed, 12 insertions(+), 1 deletion(-)
>>
>>
>
>--- Thanks!
--- Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-28 15:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 14:06 [PATCH 0/2] listns(): validate the reserved spare2 field Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 1/2] nstree: reject a non-zero spare2 in the listns() request Nikolai Dokutovich
2026-11-28 14:06 ` [PATCH 2/2] selftests/namespaces: check that listns() rejects a non-zero spare2 Nikolai Dokutovich
2026-11-28 15:44 ` [PATCH 0/2] listns(): validate the reserved spare2 field Bradley Morgan
2026-11-28 15:49 ` Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®