public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init()
@ 2026-04-01  9:21 Stefano Garzarella
  2026-04-01 17:33 ` Bobby Eshleman
  2026-04-02 15:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Stefano Garzarella @ 2026-04-01  9:21 UTC (permalink / raw)
  To: netdev
  Cc: Stefano Garzarella, David S. Miller, linux-kernel, Bobby Eshleman,
	Jakub Kicinski, Simon Horman, virtualization, Eric Dumazet,
	Paolo Abeni, Jin Liu

From: Stefano Garzarella <sgarzare@redhat.com>

The `child_ns_mode_locked` field lives in `struct net`, which persists
across vsock module reloads. When the module is unloaded and reloaded,
`vsock_net_init()` resets `mode` and `child_ns_mode` back to their
default values, but does not reset `child_ns_mode_locked`.

The stale lock from the previous module load causes subsequent writes
to `child_ns_mode` to silently fail: `vsock_net_set_child_mode()` sees
the old lock, skips updating the actual value, and returns success
when the requested mode matches the stale lock. The sysctl handler
reports no error, but `child_ns_mode` remains unchanged.

Steps to reproduce:
    $ modprobe vsock
    $ echo local > /proc/sys/net/vsock/child_ns_mode
    $ cat /proc/sys/net/vsock/child_ns_mode
    local
    $ modprobe -r vsock
    $ modprobe vsock
    $ echo local > /proc/sys/net/vsock/child_ns_mode
    $ cat /proc/sys/net/vsock/child_ns_mode
    global    <--- expected "local"

Fix this by initializing `child_ns_mode_locked` to 0 (unlocked) in
`vsock_net_init()`, so the write-once mechanism works correctly after
module reload.

Fixes: 102eab95f025 ("vsock: lock down child_ns_mode as write-once")
Cc: bobbyeshleman@meta.com
Reported-by: Jin Liu <jinl@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 2f7d94d682cb..d912ed2f012a 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2928,6 +2928,7 @@ static void vsock_net_init(struct net *net)
 		net->vsock.mode = vsock_net_child_mode(current->nsproxy->net_ns);
 
 	net->vsock.child_ns_mode = net->vsock.mode;
+	net->vsock.child_ns_mode_locked = 0;
 }
 
 static __net_init int vsock_sysctl_init_net(struct net *net)
-- 
2.53.0


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

* Re: [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init()
  2026-04-01  9:21 [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init() Stefano Garzarella
@ 2026-04-01 17:33 ` Bobby Eshleman
  2026-04-02 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Bobby Eshleman @ 2026-04-01 17:33 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: netdev, David S. Miller, linux-kernel, Bobby Eshleman,
	Jakub Kicinski, Simon Horman, virtualization, Eric Dumazet,
	Paolo Abeni, Jin Liu

On Wed, Apr 01, 2026 at 11:21:53AM +0200, Stefano Garzarella wrote:
> From: Stefano Garzarella <sgarzare@redhat.com>
> 
> The `child_ns_mode_locked` field lives in `struct net`, which persists
> across vsock module reloads. When the module is unloaded and reloaded,
> `vsock_net_init()` resets `mode` and `child_ns_mode` back to their
> default values, but does not reset `child_ns_mode_locked`.
> 
> The stale lock from the previous module load causes subsequent writes
> to `child_ns_mode` to silently fail: `vsock_net_set_child_mode()` sees
> the old lock, skips updating the actual value, and returns success
> when the requested mode matches the stale lock. The sysctl handler
> reports no error, but `child_ns_mode` remains unchanged.
> 
> Steps to reproduce:
>     $ modprobe vsock
>     $ echo local > /proc/sys/net/vsock/child_ns_mode
>     $ cat /proc/sys/net/vsock/child_ns_mode
>     local
>     $ modprobe -r vsock
>     $ modprobe vsock
>     $ echo local > /proc/sys/net/vsock/child_ns_mode
>     $ cat /proc/sys/net/vsock/child_ns_mode
>     global    <--- expected "local"
> 
> Fix this by initializing `child_ns_mode_locked` to 0 (unlocked) in
> `vsock_net_init()`, so the write-once mechanism works correctly after
> module reload.
> 
> Fixes: 102eab95f025 ("vsock: lock down child_ns_mode as write-once")
> Cc: bobbyeshleman@meta.com
> Reported-by: Jin Liu <jinl@redhat.com>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.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 2f7d94d682cb..d912ed2f012a 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -2928,6 +2928,7 @@ static void vsock_net_init(struct net *net)
>  		net->vsock.mode = vsock_net_child_mode(current->nsproxy->net_ns);
>  
>  	net->vsock.child_ns_mode = net->vsock.mode;
> +	net->vsock.child_ns_mode_locked = 0;
>  }
>  
>  static __net_init int vsock_sysctl_init_net(struct net *net)
> -- 
> 2.53.0
> 

Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>

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

* Re: [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init()
  2026-04-01  9:21 [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init() Stefano Garzarella
  2026-04-01 17:33 ` Bobby Eshleman
@ 2026-04-02 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-02 15:30 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: netdev, davem, linux-kernel, bobbyeshleman, kuba, horms,
	virtualization, edumazet, pabeni, jinl

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  1 Apr 2026 11:21:53 +0200 you wrote:
> From: Stefano Garzarella <sgarzare@redhat.com>
> 
> The `child_ns_mode_locked` field lives in `struct net`, which persists
> across vsock module reloads. When the module is unloaded and reloaded,
> `vsock_net_init()` resets `mode` and `child_ns_mode` back to their
> default values, but does not reset `child_ns_mode_locked`.
> 
> [...]

Here is the summary with links:
  - [net] vsock: initialize child_ns_mode_locked in vsock_net_init()
    https://git.kernel.org/netdev/net/c/b18c83388874

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-04-02 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01  9:21 [PATCH net] vsock: initialize child_ns_mode_locked in vsock_net_init() Stefano Garzarella
2026-04-01 17:33 ` Bobby Eshleman
2026-04-02 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox