* [PATCH] vsock: preserve child namespace mode on an empty write
@ 2026-09-15 11:14 Aldo Ariel Panzardo
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
2026-09-17 14:20 ` [PATCH] vsock: preserve child namespace mode on an empty write netdev-bot+sashiko
0 siblings, 2 replies; 10+ messages in thread
From: Aldo Ariel Panzardo @ 2026-09-15 11:14 UTC (permalink / raw)
To: Stefano Garzarella
Cc: virtualization, netdev, linux-kernel, stable, Aldo Ariel Panzardo
__vsock_net_mode_string() returns success without updating new_mode when
the write length is zero. Its caller then reads the uninitialized enum and
may permanently store a stack-derived value in the write-once child mode.
Initialize new_mode from the current child mode so that an empty write is
a no-op.
Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
net/vmw_vsock/af_vsock.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 622dbd0467..61163357ae 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2878,6 +2878,7 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
int ret;
net = container_of(table->data, struct net, vsock.child_ns_mode);
+ new_mode = vsock_net_child_mode(net);
ret = __vsock_net_mode_string(table, write, buffer, lenp, ppos,
vsock_net_child_mode(net), &new_mode);
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] vsock: ignore empty child namespace mode writes
2026-09-15 11:14 [PATCH] vsock: preserve child namespace mode on an empty write Aldo Ariel Panzardo
@ 2026-09-15 14:15 ` Aldo Ariel Panzardo
2026-09-15 16:32 ` Luigi Leonardi
` (3 more replies)
2026-09-17 14:20 ` [PATCH] vsock: preserve child namespace mode on an empty write netdev-bot+sashiko
1 sibling, 4 replies; 10+ messages in thread
From: Aldo Ariel Panzardo @ 2026-09-15 14:15 UTC (permalink / raw)
To: Stefano Garzarella
Cc: virtualization, netdev, linux-kernel, stable, Aldo Ariel Panzardo
__vsock_net_mode_string() returns success without updating new_mode when
the transfer length is zero. Its caller then reads the uninitialized enum
and may permanently store a stack-derived value in the write-once child
mode.
Return before inspecting or storing new_mode when no bytes were
transferred. This also prevents an empty write from locking the current
mode.
Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
net/vmw_vsock/af_vsock.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 622dbd0467..816d25b314 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2883,6 +2883,8 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
vsock_net_child_mode(net), &new_mode);
if (ret)
return ret;
+ if (!*lenp)
+ return 0;
if (write) {
/* Prevent a "local" namespace from escalating to "global",
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] vsock: ignore empty child namespace mode writes
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
@ 2026-09-15 16:32 ` Luigi Leonardi
2026-09-15 16:57 ` Stefano Garzarella
2026-09-15 16:50 ` Stefano Garzarella
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Luigi Leonardi @ 2026-09-15 16:32 UTC (permalink / raw)
To: Aldo Ariel Panzardo
Cc: Stefano Garzarella, virtualization, netdev, linux-kernel, stable
Hi Aldo,
On Tue, Sep 15, 2026 at 11:15:47AM -0300, Aldo Ariel Panzardo wrote:
>__vsock_net_mode_string() returns success without updating new_mode when
>the transfer length is zero. Its caller then reads the uninitialized enum
>and may permanently store a stack-derived value in the write-once child
>mode.
>
>Return before inspecting or storing new_mode when no bytes were
>transferred. This also prevents an empty write from locking the current
>mode.
>
>Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
>Cc: stable@vger.kernel.org
>Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
>---
> net/vmw_vsock/af_vsock.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 622dbd0467..816d25b314 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -2883,6 +2883,8 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
> vsock_net_child_mode(net), &new_mode);
> if (ret)
> return ret;
>+ if (!*lenp)
>+ return 0;
>
> if (write) {
> /* Prevent a "local" namespace from escalating to "global",
>--
>2.43.0
>
Code LGTM.
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
To reproduce it, I suppose we need a kernel that does not come with
`CONFIG_INIT_STACK_ALL_ZERO` set.
@Stefano do you think it's worth adding a test for this case?
Just out of curiosity, how did you find this bug?
Thanks,
Luigi
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] vsock: ignore empty child namespace mode writes
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
2026-09-15 16:32 ` Luigi Leonardi
@ 2026-09-15 16:50 ` Stefano Garzarella
2026-09-15 17:29 ` Aldo Ariel Panzardo
2026-09-15 17:30 ` [PATCH v3] " Aldo Ariel Panzardo
3 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2026-09-15 16:50 UTC (permalink / raw)
To: Aldo Ariel Panzardo
Cc: virtualization, netdev, linux-kernel, stable, Bobby Eshleman
CCing Bobby (and I guess you're missing several maintainers in CC)
On Tue, Sep 15, 2026 at 11:15:47AM -0300, Aldo Ariel Panzardo wrote:
>__vsock_net_mode_string() returns success without updating new_mode when
>the transfer length is zero. Its caller then reads the uninitialized enum
>and may permanently store a stack-derived value in the write-once child
>mode.
>
>Return before inspecting or storing new_mode when no bytes were
>transferred. This also prevents an empty write from locking the current
>mode.
>
>Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
>Cc: stable@vger.kernel.org
>Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
>---
> net/vmw_vsock/af_vsock.c | 2 ++
> 1 file changed, 2 insertions(+)
A changelog after --- or a reply to v1 to explain why sending a v2,
would be nice to have.
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 622dbd0467..816d25b314 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -2883,6 +2883,8 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
> vsock_net_child_mode(net), &new_mode);
> if (ret)
> return ret;
>+ if (!*lenp)
>+ return 0;
Better to move this before calling __vsock_net_mode_string(), no?
That said, __vsock_net_mode_string() needs some cleanup IMO but I guess
something for net-next.
Thanks,
Stefano
>
> if (write) {
> /* Prevent a "local" namespace from escalating to "global",
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] vsock: ignore empty child namespace mode writes
2026-09-15 16:32 ` Luigi Leonardi
@ 2026-09-15 16:57 ` Stefano Garzarella
0 siblings, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2026-09-15 16:57 UTC (permalink / raw)
To: Luigi Leonardi
Cc: Aldo Ariel Panzardo, virtualization, netdev, linux-kernel, stable
On Tue, Sep 15, 2026 at 06:32:59PM +0200, Luigi Leonardi wrote:
>Hi Aldo,
>
>On Tue, Sep 15, 2026 at 11:15:47AM -0300, Aldo Ariel Panzardo wrote:
>>__vsock_net_mode_string() returns success without updating new_mode when
>>the transfer length is zero. Its caller then reads the uninitialized enum
>>and may permanently store a stack-derived value in the write-once child
>>mode.
>>
>>Return before inspecting or storing new_mode when no bytes were
>>transferred. This also prevents an empty write from locking the current
>>mode.
>>
>>Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
>>Cc: stable@vger.kernel.org
>>Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
>>---
>>net/vmw_vsock/af_vsock.c | 2 ++
>>1 file changed, 2 insertions(+)
>>
>>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>>index 622dbd0467..816d25b314 100644
>>--- a/net/vmw_vsock/af_vsock.c
>>+++ b/net/vmw_vsock/af_vsock.c
>>@@ -2883,6 +2883,8 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
>> vsock_net_child_mode(net), &new_mode);
>> if (ret)
>> return ret;
>>+ if (!*lenp)
>>+ return 0;
>>
>> if (write) {
>> /* Prevent a "local" namespace from escalating to "global",
>>--
>>2.43.0
>>
>
>Code LGTM.
>Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
>
>To reproduce it, I suppose we need a kernel that does not come with
>`CONFIG_INIT_STACK_ALL_ZERO` set.
>
>@Stefano do you think it's worth adding a test for this case?
Not a strong opinion on this on my side.
Thanks,
Stefano
>
>Just out of curiosity, how did you find this bug?
>
>Thanks,
>Luigi
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] vsock: ignore empty child namespace mode writes
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
2026-09-15 16:32 ` Luigi Leonardi
2026-09-15 16:50 ` Stefano Garzarella
@ 2026-09-15 17:29 ` Aldo Ariel Panzardo
2026-09-15 17:30 ` [PATCH v3] " Aldo Ariel Panzardo
3 siblings, 0 replies; 10+ messages in thread
From: Aldo Ariel Panzardo @ 2026-09-15 17:29 UTC (permalink / raw)
To: Luigi Leonardi, Stefano Garzarella
Cc: Bobby Eshleman, davem, edumazet, kuba, pabeni, horms,
virtualization, netdev, linux-kernel, stable,
Aldo Ariel Panzardo
Hi Luigi, Stefano,
Thanks for taking a look.
Luigi — nothing fancy, I was just reading sysctl handlers and
noticed that __vsock_net_mode_string() bails early on a zero-length
write without touching new_mode. Since the child mode can only be
set once, an empty write that sneaks through locks it with whatever
was on the stack. CONFIG_INIT_STACK_ALL_ZERO hides the whole thing,
which is probably why nobody hit it in practice.
Stefano — yeah, makes more sense to bail before calling the helper
at all. Fixed in v3, and I added the CCs I missed.
Cheers,
Aldo
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3] vsock: ignore empty child namespace mode writes
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
` (2 preceding siblings ...)
2026-09-15 17:29 ` Aldo Ariel Panzardo
@ 2026-09-15 17:30 ` Aldo Ariel Panzardo
2026-09-16 15:38 ` Stefano Garzarella
2026-09-16 16:53 ` Bobby Eshleman
3 siblings, 2 replies; 10+ messages in thread
From: Aldo Ariel Panzardo @ 2026-09-15 17:30 UTC (permalink / raw)
To: Stefano Garzarella
Cc: Bobby Eshleman, Luigi Leonardi, davem, edumazet, kuba, pabeni,
horms, virtualization, netdev, linux-kernel, stable,
Aldo Ariel Panzardo
__vsock_net_mode_string() returns success without updating new_mode when
the transfer length is zero. Its caller then reads the uninitialized enum
and may permanently store a stack-derived value in the write-once child
mode.
Return before calling __vsock_net_mode_string() when *lenp is zero so
that the helper is never invoked with nothing to parse and new_mode is
never read uninitialized. This also prevents an empty write from
locking the current mode.
Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
Cc: stable@vger.kernel.org
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
Changes in v3:
- Move the !*lenp early return before __vsock_net_mode_string()
instead of after it, as suggested by Stefano Garzarella.
- Add missing maintainer CCs per get_maintainer.pl.
- Add Luigi's Reviewed-by.
Changes in v2:
- Return early instead of initializing new_mode to the current
value, which would silently consume the write-once transition.
net/vmw_vsock/af_vsock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 622dbd0467..XXXXXXX 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2879,6 +2879,9 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
net = container_of(table->data, struct net, vsock.child_ns_mode);
+ if (!*lenp)
+ return 0;
+
ret = __vsock_net_mode_string(table, write, buffer, lenp, ppos,
vsock_net_child_mode(net), &new_mode);
if (ret)
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] vsock: ignore empty child namespace mode writes
2026-09-15 17:30 ` [PATCH v3] " Aldo Ariel Panzardo
@ 2026-09-16 15:38 ` Stefano Garzarella
2026-09-16 16:53 ` Bobby Eshleman
1 sibling, 0 replies; 10+ messages in thread
From: Stefano Garzarella @ 2026-09-16 15:38 UTC (permalink / raw)
To: Aldo Ariel Panzardo
Cc: Bobby Eshleman, Luigi Leonardi, davem, edumazet, kuba, pabeni,
horms, virtualization, netdev, linux-kernel, stable
On Tue, Sep 15, 2026 at 02:30:50PM -0300, Aldo Ariel Panzardo wrote:
>__vsock_net_mode_string() returns success without updating new_mode when
>the transfer length is zero. Its caller then reads the uninitialized enum
>and may permanently store a stack-derived value in the write-once child
>mode.
>
>Return before calling __vsock_net_mode_string() when *lenp is zero so
>that the helper is never invoked with nothing to parse and new_mode is
>never read uninitialized. This also prevents an empty write from
>locking the current mode.
>
>Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
>Cc: stable@vger.kernel.org
>Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
>Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
>---
>
>Changes in v3:
> - Move the !*lenp early return before __vsock_net_mode_string()
> instead of after it, as suggested by Stefano Garzarella.
> - Add missing maintainer CCs per get_maintainer.pl.
> - Add Luigi's Reviewed-by.
>
>Changes in v2:
> - Return early instead of initializing new_mode to the current
> value, which would silently consume the write-once transition.
>
> net/vmw_vsock/af_vsock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 622dbd0467..XXXXXXX 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -2879,6 +2879,9 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
>
> net = container_of(table->data, struct net, vsock.child_ns_mode);
>
>+ if (!*lenp)
>+ return 0;
>+
I would have moved it even before the net assignmet, but in any case, it
doesn't make much difference:
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] vsock: ignore empty child namespace mode writes
2026-09-15 17:30 ` [PATCH v3] " Aldo Ariel Panzardo
2026-09-16 15:38 ` Stefano Garzarella
@ 2026-09-16 16:53 ` Bobby Eshleman
1 sibling, 0 replies; 10+ messages in thread
From: Bobby Eshleman @ 2026-09-16 16:53 UTC (permalink / raw)
To: Aldo Ariel Panzardo
Cc: Stefano Garzarella, Bobby Eshleman, Luigi Leonardi, davem,
edumazet, kuba, pabeni, horms, virtualization, netdev,
linux-kernel, stable
On Tue, Sep 15, 2026 at 02:30:50PM -0300, Aldo Ariel Panzardo wrote:
> __vsock_net_mode_string() returns success without updating new_mode when
> the transfer length is zero. Its caller then reads the uninitialized enum
> and may permanently store a stack-derived value in the write-once child
> mode.
>
> Return before calling __vsock_net_mode_string() when *lenp is zero so
> that the helper is never invoked with nothing to parse and new_mode is
> never read uninitialized. This also prevents an empty write from
> locking the current mode.
>
> Fixes: eafb64f40ca4 ("vsock: add netns to vsock core")
> Cc: stable@vger.kernel.org
> Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
> Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
> ---
>
> Changes in v3:
> - Move the !*lenp early return before __vsock_net_mode_string()
> instead of after it, as suggested by Stefano Garzarella.
> - Add missing maintainer CCs per get_maintainer.pl.
> - Add Luigi's Reviewed-by.
>
> Changes in v2:
> - Return early instead of initializing new_mode to the current
> value, which would silently consume the write-once transition.
>
> net/vmw_vsock/af_vsock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 622dbd0467..XXXXXXX 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -2879,6 +2879,9 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
>
> net = container_of(table->data, struct net, vsock.child_ns_mode);
>
> + if (!*lenp)
> + return 0;
> +
> ret = __vsock_net_mode_string(table, write, buffer, lenp, ppos,
> vsock_net_child_mode(net), &new_mode);
> if (ret)
>
> --
> 2.43.0
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vsock: preserve child namespace mode on an empty write
2026-09-15 11:14 [PATCH] vsock: preserve child namespace mode on an empty write Aldo Ariel Panzardo
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
@ 2026-09-17 14:20 ` netdev-bot+sashiko
1 sibling, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-09-17 14:20 UTC (permalink / raw)
To: qwe.aldo; +Cc: sgarzare, virtualization, netdev, linux-kernel, stable, kuba
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0
- [High] Incomplete fix: a zero-length write to
/proc/sys/net/vsock/child_ns_mode still consumes the write-once child-…
Pre-existing issues:
- [Medium] Non-atomic publication in vsock_net_set_child_mode()
(include/net/af_vsock.h:289-302): child_ns_mode_locked is published by…
--
vsock: preserve child namespace mode on an empty write
This initializes new_mode in vsock_net_child_mode_string() from the current
child mode, so the caller no longer reads an uninitialized enum when
__vsock_net_mode_string() returns success for a zero-length write.
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index f840498b58afb..9f89f199478b9 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -2888,6 +2888,7 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
> int ret;
>
> net = container_of(table->data, struct net, vsock.child_ns_mode);
> + new_mode = vsock_net_child_mode(net);
>
> ret = __vsock_net_mode_string(table, write, buffer, lenp, ppos,
> vsock_net_child_mode(net), &new_mode);
[Severity: High]
The changelog says "Initialize new_mode from the current child mode so that
an empty write is a no-op." Is the empty write really a no-op after this
change?
A zero-length write still reaches the handler with write == 1 and
*lenp == 0. fs/read_write.c:vfs_write() has no count == 0 early return
(rw_verify_area() only rejects negative counts), and
fs/proc/proc_sysctl.c:proc_sys_call_handler() does not short-circuit
either:
if (write) {
error = -EFAULT;
if (!copy_from_iter_full(kbuf, count, iter))
goto out_free_buf;
kbuf[count] = '\0';
}
...
error = table->proc_handler(table, write, kbuf, &count, &iocb->ki_pos);
copy_from_iter_full(kbuf, 0, iter) returns true, so
vsock_net_child_mode_string() is entered with *lenp == 0.
__vsock_net_mode_string() then returns 0 without parsing anything:
if (!table->data || !table->maxlen || !*lenp) {
*lenp = 0;
return 0;
}
Since that return value is indistinguishable from "a mode was parsed",
vsock_net_child_mode_string() falls into its write block anyway:
if (write) {
...
if (!vsock_net_set_child_mode(net, new_mode))
return -EBUSY;
}
so vsock_net_set_child_mode() is still called, now with the seeded current
mode rather than a stack value.
Does that still consume the write-once latch? In
include/net/af_vsock.h:vsock_net_set_child_mode():
int new_locked = mode + 1;
int old_locked = 0; /* unlocked */
if (try_cmpxchg(&net->vsock.child_ns_mode_locked,
&old_locked, new_locked)) {
WRITE_ONCE(net->vsock.child_ns_mode, mode);
return true;
}
On a fresh namespace vsock_net_init() leaves child_ns_mode_locked at 0, so
the cmpxchg succeeds and the mode is latched permanently.
Would this sequence then break a later legitimate lockdown on a global-mode
namespace?
write(fd, "", 0); /* returns 0, latches GLOBAL+1 */
echo local > .../child_ns_mode /* cmpxchg fails, -EBUSY */
Documentation/admin-guide/sysctl/net.rst describes the behaviour as:
The first write to ``child_ns_mode`` locks its value. Subsequent writes of
the same value succeed, but writing a different value returns ``-EBUSY``.
which ties the lock and the -EBUSY to writing a mode value, not to a write
that supplies no value.
Would it be more in line with the changelog to skip the write handling
entirely when nothing was parsed, for example an early
"if (write && !*lenp) return 0;" in vsock_net_child_mode_string(), or having
__vsock_net_mode_string() report "no value parsed" distinctly from success,
instead of re-applying the current mode through the cmpxchg?
[Severity: Medium]
This is a pre-existing issue and not introduced by this patch, but while
looking at vsock_net_set_child_mode() in include/net/af_vsock.h: is the
publication of the lock and of the mode value atomic with respect to
namespace creation?
if (try_cmpxchg(&net->vsock.child_ns_mode_locked,
&old_locked, new_locked)) {
WRITE_ONCE(net->vsock.child_ns_mode, mode);
return true;
}
return old_locked == new_locked;
The lock becomes observable before the child_ns_mode store, and a second
writer of the same mode returns success from the last line without waiting
for that store:
CPU0 (writes "local" on a global-mode netns)
try_cmpxchg() succeeds, child_ns_mode_locked = LOCAL+1
/* preempted here, before WRITE_ONCE(child_ns_mode, LOCAL) */
CPU1 (writes "local")
try_cmpxchg() fails, old_locked == LOCAL+1 == new_locked
return true; /* sysctl write reports success */
CPU2 (creates a netns after CPU1's write returned)
net/vmw_vsock/af_vsock.c:vsock_net_init()
net->vsock.mode = vsock_net_child_mode(current->nsproxy->net_ns);
net->vsock.child_ns_mode = net->vsock.mode;
Can the new namespace read VSOCK_NET_MODE_GLOBAL here and permanently
inherit the more permissive mode even though userspace was told the "local"
lockdown was committed?
A barrier does not seem sufficient, since the reader has already observed
the lock publication that precedes the value store. Would publishing the
mode and its locked state together help, for example deriving child_ns_mode
from child_ns_mode_locked, or adding an in-progress state that the second
writer waits on?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260915111417.2726515-1-qwe.aldo%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-09-17 14:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 11:14 [PATCH] vsock: preserve child namespace mode on an empty write Aldo Ariel Panzardo
2026-09-15 14:15 ` [PATCH v2] vsock: ignore empty child namespace mode writes Aldo Ariel Panzardo
2026-09-15 16:32 ` Luigi Leonardi
2026-09-15 16:57 ` Stefano Garzarella
2026-09-15 16:50 ` Stefano Garzarella
2026-09-15 17:29 ` Aldo Ariel Panzardo
2026-09-15 17:30 ` [PATCH v3] " Aldo Ariel Panzardo
2026-09-16 15:38 ` Stefano Garzarella
2026-09-16 16:53 ` Bobby Eshleman
2026-09-17 14:20 ` [PATCH] vsock: preserve child namespace mode on an empty write netdev-bot+sashiko
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®