* [PATCH net-next RFC 0/5] vsock: constify transports
@ 2026-12-03 16:32 Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 1/5] vsock/virtio: constify loopback_transport Michal Luczaj
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Hardening in the spirit of commit 56130915bbe3 ("VSOCK: constify
vsock_transport structure"), which constified the only vsock transport of
its time, but then effectively got reverted in commit c0cfa2d8a788 ("vsock:
add multi-transports support").
virtio_transport structs are immutable, move them to RO memory. No
functional change. Value added: less .data, fewer options to take over
function pointers [1].
File sizes are essentially unchanged (deltas -8 to +64 bytes, <= +0.01%).
Sizes of .text and .bss are unchanged, only movement being few hundred
bytes of the transport structs relocating from .data to .rodata:
.rodata .data
vsock.ko 0 0
vsock_loopback.ko +384 -384
vmw_vsock_virtio_transport.ko +384 -384
vmw_vsock_virtio_transport_common.ko 0 0
vmw_vsock_vmci_transport.ko +352 -352
hv_sock.ko +352 -352
vhost_vsock.ko +384 -384
[1] https://www.kernel.org/doc/html/v7.4-rc5/security/self-protection.html#function-pointers-and-sensitive-variables-must-not-be-writable
---
Michal Luczaj (5):
vsock/virtio: constify loopback_transport
vsock/virtio: constify virtio_transport
vsock/virtio: constify vhost_transport
vsock/vmci: constify vmci_transport
vsock/hyperv: constify hvs_transport
drivers/vhost/vsock.c | 2 +-
include/linux/virtio_vsock.h | 2 +-
include/net/af_vsock.h | 2 +-
net/vmw_vsock/af_vsock.c | 2 +-
net/vmw_vsock/hyperv_transport.c | 2 +-
net/vmw_vsock/virtio_transport.c | 4 ++--
net/vmw_vsock/virtio_transport_common.c | 4 ++--
net/vmw_vsock/vmci_transport.c | 4 ++--
net/vmw_vsock/vsock_loopback.c | 2 +-
9 files changed, 12 insertions(+), 12 deletions(-)
---
base-commit: ed3135d0881a926de56a7f490dea3d51698ba118
change-id: 20260116-vsock-constify-transports-16f3f5e28bab
Best regards,
--
Michal Luczaj <mhal@rbox.co>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next RFC 1/5] vsock/virtio: constify loopback_transport
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
@ 2026-12-03 16:32 ` Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 2/5] vsock/virtio: constify virtio_transport Michal Luczaj
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Struct is never modified. Add `const` qualifier, let it be moved to
read-only section.
No functional change intended.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
include/linux/virtio_vsock.h | 2 +-
net/vmw_vsock/virtio_transport_common.c | 4 ++--
net/vmw_vsock/vsock_loopback.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 46058d354940..08e9606b7e24 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -280,7 +280,7 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk,
void virtio_transport_destruct(struct vsock_sock *vsk);
-void virtio_transport_recv_pkt(struct virtio_transport *t,
+void virtio_transport_recv_pkt(const struct virtio_transport *t,
struct sk_buff *skb, struct net *net);
void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_buff *skb);
u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted);
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 027fe41c676a..8f8d0846885d 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1702,7 +1702,7 @@ static bool virtio_transport_space_update(struct sock *sk,
/* Handle server socket */
static int
virtio_transport_recv_listen(struct sock *sk, struct sk_buff *skb,
- struct virtio_transport *t)
+ const struct virtio_transport *t)
{
struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
struct vsock_sock *vsk = vsock_sk(sk);
@@ -1777,7 +1777,7 @@ static bool virtio_transport_valid_type(u16 type)
/* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex
* lock.
*/
-void virtio_transport_recv_pkt(struct virtio_transport *t,
+void virtio_transport_recv_pkt(const struct virtio_transport *t,
struct sk_buff *skb, struct net *net)
{
struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c
index cacd313a454b..02341064a716 100644
--- a/net/vmw_vsock/vsock_loopback.c
+++ b/net/vmw_vsock/vsock_loopback.c
@@ -60,7 +60,7 @@ static bool vsock_loopback_msgzerocopy_allow(void)
return true;
}
-static struct virtio_transport loopback_transport = {
+static const struct virtio_transport loopback_transport = {
.transport = {
.module = THIS_MODULE,
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next RFC 2/5] vsock/virtio: constify virtio_transport
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 1/5] vsock/virtio: constify loopback_transport Michal Luczaj
@ 2026-12-03 16:32 ` Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 3/5] vsock/virtio: constify vhost_transport Michal Luczaj
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Struct is never modified. Add `const` qualifier, let it be moved to
read-only section.
No functional change intended.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
include/net/af_vsock.h | 2 +-
net/vmw_vsock/af_vsock.c | 2 +-
net/vmw_vsock/virtio_transport.c | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index 3e28865578eb..0ddcf2325ba5 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -234,7 +234,7 @@ bool vsock_check_source(const struct vsock_sock *vsk,
const struct vsock_transport *transport,
const struct sockaddr_vm *src);
void vsock_remove_sock(struct vsock_sock *vsk);
-void vsock_for_each_connected_socket(struct vsock_transport *transport,
+void vsock_for_each_connected_socket(const struct vsock_transport *transport,
void (*fn)(struct sock *sk));
int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk);
bool vsock_find_cid(unsigned int cid);
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 1d7d53542724..22dd45bdfc5f 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -480,7 +480,7 @@ void vsock_remove_sock(struct vsock_sock *vsk)
}
EXPORT_SYMBOL_GPL(vsock_remove_sock);
-void vsock_for_each_connected_socket(struct vsock_transport *transport,
+void vsock_for_each_connected_socket(const struct vsock_transport *transport,
void (*fn)(struct sock *sk))
{
int i;
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index b39c001260a9..8e5eac76ea2d 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -25,7 +25,7 @@
static struct workqueue_struct *virtio_vsock_workqueue;
static struct virtio_vsock __rcu *the_virtio_vsock;
static DEFINE_MUTEX(the_virtio_vsock_mutex); /* protects the_virtio_vsock */
-static struct virtio_transport virtio_transport; /* forward declaration */
+static const struct virtio_transport virtio_transport; /* forward declaration */
struct virtio_vsock {
struct virtio_device *vdev;
@@ -554,7 +554,7 @@ static bool virtio_transport_has_remote_cid(struct vsock_sock *vsk, u32 cid)
return true;
}
-static struct virtio_transport virtio_transport = {
+static const struct virtio_transport virtio_transport = {
.transport = {
.module = THIS_MODULE,
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next RFC 3/5] vsock/virtio: constify vhost_transport
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 1/5] vsock/virtio: constify loopback_transport Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 2/5] vsock/virtio: constify virtio_transport Michal Luczaj
@ 2026-12-03 16:32 ` Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 4/5] vsock/vmci: constify vmci_transport Michal Luczaj
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Struct is never modified. Add `const` qualifier, let it be moved to
read-only section.
No functional change intended.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
drivers/vhost/vsock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 03a3b833640d..edb57b03c9e2 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -441,7 +441,7 @@ vhost_transport_stream_allow(struct vsock_sock *vsk, u32 cid, u32 port)
return true;
}
-static struct virtio_transport vhost_transport = {
+static const struct virtio_transport vhost_transport = {
.transport = {
.module = THIS_MODULE,
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next RFC 4/5] vsock/vmci: constify vmci_transport
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
` (2 preceding siblings ...)
2026-12-03 16:32 ` [PATCH net-next RFC 3/5] vsock/virtio: constify vhost_transport Michal Luczaj
@ 2026-12-03 16:32 ` Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport Michal Luczaj
2026-12-04 16:18 ` [PATCH net-next RFC 0/5] vsock: constify transports Bobby Eshleman
5 siblings, 0 replies; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Struct is never modified. Add `const` qualifier, let it be moved to
read-only section.
No functional change intended, compile tested only.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
net/vmw_vsock/vmci_transport.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index 282131544c42..2d03b5886311 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -75,7 +75,7 @@ static u32 vmci_transport_qp_resumed_sub_id = VMCI_INVALID_ID;
static int PROTOCOL_OVERRIDE = -1;
-static struct vsock_transport vmci_transport; /* forward declaration */
+static const struct vsock_transport vmci_transport; /* forward declaration */
/* Helper function to convert from a VMCI error code to a VSock error code. */
@@ -2073,7 +2073,7 @@ static u32 vmci_transport_get_local_cid(void)
return vmci_get_context_id();
}
-static struct vsock_transport vmci_transport = {
+static const struct vsock_transport vmci_transport = {
.module = THIS_MODULE,
.init = vmci_transport_socket_init,
.destruct = vmci_transport_destruct,
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
` (3 preceding siblings ...)
2026-12-03 16:32 ` [PATCH net-next RFC 4/5] vsock/vmci: constify vmci_transport Michal Luczaj
@ 2026-12-03 16:32 ` Michal Luczaj
2026-12-03 20:14 ` Hamza Mahfooz
2026-12-04 16:18 ` [PATCH net-next RFC 0/5] vsock: constify transports Bobby Eshleman
5 siblings, 1 reply; 8+ messages in thread
From: Michal Luczaj @ 2026-12-03 16:32 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui
Cc: virtualization, kvm, netdev, linux-kernel, linux-hyperv,
Michal Luczaj
Struct is never modified. Add `const` qualifier, let it be moved to
read-only section.
No functional change intended, compile tested only.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
net/vmw_vsock/hyperv_transport.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index 551eabe69014..274b707e0da3 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -862,7 +862,7 @@ int hvs_notify_set_rcvlowat(struct vsock_sock *vsk, int val)
return -EOPNOTSUPP;
}
-static struct vsock_transport hvs_transport = {
+static const struct vsock_transport hvs_transport = {
.module = THIS_MODULE,
.get_local_cid = hvs_get_local_cid,
--
2.56.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport
2026-12-03 16:32 ` [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport Michal Luczaj
@ 2026-12-03 20:14 ` Hamza Mahfooz
0 siblings, 0 replies; 8+ messages in thread
From: Hamza Mahfooz @ 2026-12-03 20:14 UTC (permalink / raw)
To: Michal Luczaj
Cc: Stefan Hajnoczi, Stefano Garzarella, Bobby Eshleman,
Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui, virtualization, kvm, netdev, linux-kernel,
linux-hyperv
On Thu, Dec 03, 2026 at 05:32:21PM +0100, Michal Luczaj wrote:
> Struct is never modified. Add `const` qualifier, let it be moved to
> read-only section.
>
> No functional change intended, compile tested only.
>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Hamza Mahfooz <hamza@kernel.org>
> ---
> net/vmw_vsock/hyperv_transport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
> index 551eabe69014..274b707e0da3 100644
> --- a/net/vmw_vsock/hyperv_transport.c
> +++ b/net/vmw_vsock/hyperv_transport.c
> @@ -862,7 +862,7 @@ int hvs_notify_set_rcvlowat(struct vsock_sock *vsk, int val)
> return -EOPNOTSUPP;
> }
>
> -static struct vsock_transport hvs_transport = {
> +static const struct vsock_transport hvs_transport = {
> .module = THIS_MODULE,
>
> .get_local_cid = hvs_get_local_cid,
>
> --
> 2.56.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next RFC 0/5] vsock: constify transports
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
` (4 preceding siblings ...)
2026-12-03 16:32 ` [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport Michal Luczaj
@ 2026-12-04 16:18 ` Bobby Eshleman
5 siblings, 0 replies; 8+ messages in thread
From: Bobby Eshleman @ 2026-12-04 16:18 UTC (permalink / raw)
To: Michal Luczaj
Cc: Stefan Hajnoczi, Stefano Garzarella, Michael S. Tsirkin,
Jason Wang, Eugenio Pérez, Xuan Zhuo, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Simon Horman, Bryan Tan, Vishnu Dasa,
Broadcom internal kernel review list, Haiyang Zhang, Wei Liu,
Dexuan Cui, virtualization, kvm, netdev, linux-kernel,
linux-hyperv
On Thu, Dec 03, 2026 at 05:32:16PM +0100, Michal Luczaj wrote:
> Hardening in the spirit of commit 56130915bbe3 ("VSOCK: constify
> vsock_transport structure"), which constified the only vsock transport of
> its time, but then effectively got reverted in commit c0cfa2d8a788 ("vsock:
> add multi-transports support").
>
> virtio_transport structs are immutable, move them to RO memory. No
> functional change. Value added: less .data, fewer options to take over
> function pointers [1].
>
> File sizes are essentially unchanged (deltas -8 to +64 bytes, <= +0.01%).
> Sizes of .text and .bss are unchanged, only movement being few hundred
> bytes of the transport structs relocating from .data to .rodata:
>
> .rodata .data
> vsock.ko 0 0
> vsock_loopback.ko +384 -384
> vmw_vsock_virtio_transport.ko +384 -384
> vmw_vsock_virtio_transport_common.ko 0 0
> vmw_vsock_vmci_transport.ko +352 -352
> hv_sock.ko +352 -352
> vhost_vsock.ko +384 -384
>
> [1] https://www.kernel.org/doc/html/v7.4-rc5/security/self-protection.html#function-pointers-and-sensitive-variables-must-not-be-writable
>
[...]
>
> Best regards,
> --
> Michal Luczaj <mhal@rbox.co>
>
Thanks for following up on this. All LGTM. Sorry for letting it slip
through the cracks in my series.
Best,
Bobby
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-04 16:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:32 [PATCH net-next RFC 0/5] vsock: constify transports Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 1/5] vsock/virtio: constify loopback_transport Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 2/5] vsock/virtio: constify virtio_transport Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 3/5] vsock/virtio: constify vhost_transport Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 4/5] vsock/vmci: constify vmci_transport Michal Luczaj
2026-12-03 16:32 ` [PATCH net-next RFC 5/5] vsock/hyperv: constify hvs_transport Michal Luczaj
2026-12-03 20:14 ` Hamza Mahfooz
2026-12-04 16:18 ` [PATCH net-next RFC 0/5] vsock: constify transports Bobby Eshleman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox