summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorPaolo Abeni <pabeni@redhat.com>2026-02-26 13:10:05 +0300
committerPaolo Abeni <pabeni@redhat.com>2026-02-26 13:10:06 +0300
commitf0a2f2aadbef0d44e6df7b43a32b509fbbf39349 (patch)
treed00d3bb96d13214ca2a927071ef16b3e8d135c95 /net
parent97f87e578883abe2c8bec947dbdfdc4bf624f796 (diff)
parentb6302e057fdc8f199ddae736ecdf45029f892e5c (diff)
downloadlinux-f0a2f2aadbef0d44e6df7b43a32b509fbbf39349.tar.xz
Merge branch 'vsock-add-write-once-semantics-to-child_ns_mode'
Bobby Eshleman says: ==================== vsock: add write-once semantics to child_ns_mode Two administrator processes may race when setting child_ns_mode: one sets it to "local" and creates a namespace, but another changes it to "global" in between. The first process ends up with a namespace in the wrong mode. Make child_ns_mode write-once so that a namespace manager can set it once, check the value, and be guaranteed it won't change before creating its namespaces. Writing a different value after the first write returns -EBUSY. One patch for the implementation, one for docs, and one for tests. v2: https://lore.kernel.org/r/20260218-vsock-ns-write-once-v2-0-19e4c50d509a@meta.com v1: https://lore.kernel.org/r/20260217-vsock-ns-write-once-v1-1-a1fb30f289a9@meta.com ==================== Link: https://patch.msgid.link/20260223-vsock-ns-write-once-v3-0-c0cde6959923@meta.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/vmw_vsock/af_vsock.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index f4062c6a1944..2f7d94d682cb 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -90,16 +90,20 @@
*
* - /proc/sys/net/vsock/ns_mode (read-only) reports the current namespace's
* mode, which is set at namespace creation and immutable thereafter.
- * - /proc/sys/net/vsock/child_ns_mode (writable) controls what mode future
+ * - /proc/sys/net/vsock/child_ns_mode (write-once) controls what mode future
* child namespaces will inherit when created. The initial value matches
* the namespace's own ns_mode.
*
* Changing child_ns_mode only affects newly created namespaces, not the
* current namespace or existing children. A "local" namespace cannot set
- * child_ns_mode to "global". At namespace creation, ns_mode is inherited
- * from the parent's child_ns_mode.
+ * child_ns_mode to "global". child_ns_mode is write-once, so that it may be
+ * configured and locked down by a namespace manager. Writing a different
+ * value after the first write returns -EBUSY. At namespace creation, ns_mode
+ * is inherited from the parent's child_ns_mode.
*
- * The init_net mode is "global" and cannot be modified.
+ * The init_net mode is "global" and cannot be modified. The init_net
+ * child_ns_mode is also write-once, so an init process (e.g. systemd) can
+ * set it to "local" to ensure all new namespaces inherit local mode.
*
* The modes affect the allocation and accessibility of CIDs as follows:
*
@@ -2853,7 +2857,8 @@ static int vsock_net_child_mode_string(const struct ctl_table *table, int write,
new_mode == VSOCK_NET_MODE_GLOBAL)
return -EPERM;
- vsock_net_set_child_mode(net, new_mode);
+ if (!vsock_net_set_child_mode(net, new_mode))
+ return -EBUSY;
}
return 0;