Skip to contentSkip to conversation

vsock/vmci: Clear the vmci transport packet properly when initializing it

PATCH Applied Greg Kroah-Hartman 3 participants 6 messages Jul 1, 2025 – Jul 3, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsock/vmci: Clear the vmci transport packet properly when initializing it

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Cc Bryan Tan <[email protected]>
Cc Vishnu Dasa <[email protected]>
Cc Broadcom internal kernel review list
Cc Stefano Garzarella <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc stable <[email protected]>

---
Tweaked from original version by rewording the text and adding a blank line and correctly sending it to the proper people for inclusion in net.

 net/vmw_vsock/vmci_transport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/vmw_vsock/vmci_transport.c +2 -2
index b370070194fa..7eccd6708d66 100644
@@ -119,6 +119,8 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 			   u16 proto,
 			   struct vmci_handle handle)
 {
+	memset(pkt, 0, sizeof(*pkt));
+
 	/* We register the stream control handler as an any cid handle so we
 	 * must always send from a source address of VMADDR_CID_ANY
 	 */
@@ -131,8 +133,6 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 	pkt->type = type;
 	pkt->src_port = src->svm_port;
 	pkt->dst_port = dst->svm_port;
-	memset(&pkt->proto, 0, sizeof(pkt->proto));
-	memset(&pkt->_reserved2, 0, sizeof(pkt->_reserved2));
 
 	switch (pkt->type) {
 	case VMCI_TRANSPORT_PACKET_TYPE_INVALID:
Signature · 1 line
2.50.0
#1 lore raw
Quoted 5 lines · Greg Kroah-Hartman

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Usually I would suggest inserting a Fixes tag, but if you didn't put it, there's probably a reason :-)

If we are going to add it, I think it should be:

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
Quoted 36 lines
Cc Bryan Tan <[email protected]>
Cc Vishnu Dasa <[email protected]>
Cc Broadcom internal kernel review list
Cc Stefano Garzarella <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc stable <[email protected]>

---
Tweaked from original version by rewording the text and adding a blank line and correctly sending it to the proper people for inclusion in net.

net/vmw_vsock/vmci_transport.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
net/vmw_vsock/vmci_transport.c +2 -0
index b370070194fa..7eccd6708d66 100644
@@ -119,6 +119,8 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 			   u16 proto,
 			   struct vmci_handle handle)
 {
+	memset(pkt, 0, sizeof(*pkt));
+
 	/* We register the stream control handler as an any cid handle so we
 	 * must always send from a source address of VMADDR_CID_ANY
 	 */

net/vmw_vsock/vmci_transport.c vmci_transport_packet_init(struct vmci_transport_packet *pkt, · line 135

Quoted 5 lines
net/vmw_vsock/vmci_transport.c +0 -2
@@ -131,8 +133,6 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 	pkt->type = type;
 	pkt->src_port = src->svm_port;
 	pkt->dst_port = dst->svm_port;
-	memset(&pkt->proto, 0, sizeof(pkt->proto));
-	memset(&pkt->_reserved2, 0, sizeof(pkt->_reserved2));

Should we also remove some cases in the following switch? I mean something like this:

net/vmw_vsock/vmci_transport.c +0 -10
index b370070194fa..d821ddcc62d8 100644
@@ -135,10 +135,6 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
        memset(&pkt->_reserved2, 0, sizeof(pkt->_reserved2));
 
        switch (pkt->type) {
-       case VMCI_TRANSPORT_PACKET_TYPE_INVALID:
-               pkt->u.size = 0;
-               break;
-
        case VMCI_TRANSPORT_PACKET_TYPE_REQUEST:
        case VMCI_TRANSPORT_PACKET_TYPE_NEGOTIATE:
                pkt->u.size = size;
@@ -149,12 +145,6 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
                pkt->u.handle = handle;
                break;
 
-       case VMCI_TRANSPORT_PACKET_TYPE_WROTE:
-       case VMCI_TRANSPORT_PACKET_TYPE_READ:
-       case VMCI_TRANSPORT_PACKET_TYPE_RST:
-               pkt->u.size = 0;
-               break;
-
        case VMCI_TRANSPORT_PACKET_TYPE_SHUTDOWN:
                pkt->u.mode = mode;
                break;

Thanks,
Stefano

Quoted 6 lines
net/vmw_vsock/vmci_transport.c +0 -0
 	switch (pkt->type) {
 	case VMCI_TRANSPORT_PACKET_TYPE_INVALID:
Signature · 1 line
2.50.0
#2 lore raw
Quoted 7 lines · Stefano Garzarella
Quoted 5 lines · Greg Kroah-Hartman

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Quoted 6 lines

Usually I would suggest inserting a Fixes tag, but if you didn't put it, there's probably a reason :-)

If we are going to add it, I think it should be:

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

Yeah, I didn't think it was needed as this is obviously a "ever since this file has been there" type of thing, so it will be backported everywhere once it hits Linus's tree.

thanks,

greg k-h

#3 lore raw
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Stefano Garzarella
Quoted 5 lines · Greg Kroah-Hartman

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Usually I would suggest inserting a Fixes tag, but if you didn't put it, there's probably a reason :-)

Quoted 7 lines
Quoted 3 lines

If we are going to add it, I think it should be:

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

Yeah, I didn't think it was needed as this is obviously a "ever since this file has been there" type of thing, so it will be backported everywhere once it hits Linus's tree.

I see, thanks!
Stefano

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 20 lines · Greg Kroah-Hartman

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Cc Bryan Tan <[email protected]>
Cc Vishnu Dasa <[email protected]>
Cc Broadcom internal kernel review list
Cc Stefano Garzarella <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc stable <[email protected]>
Quoted 6 lines

---
Tweaked from original version by rewording the text and adding a blank line and correctly sending it to the proper people for inclusion in net.

net/vmw_vsock/vmci_transport.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

Patch LGTM, we can fix the switch later.

Stefano

Quoted 26 lines
net/vmw_vsock/vmci_transport.c +2 -2
index b370070194fa..7eccd6708d66 100644
@@ -119,6 +119,8 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 			   u16 proto,
 			   struct vmci_handle handle)
 {
+	memset(pkt, 0, sizeof(*pkt));
+
 	/* We register the stream control handler as an any cid handle so we
 	 * must always send from a source address of VMADDR_CID_ANY
 	 */
@@ -131,8 +133,6 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt,
 	pkt->type = type;
 	pkt->src_port = src->svm_port;
 	pkt->dst_port = dst->svm_port;
-	memset(&pkt->proto, 0, sizeof(pkt->proto));
-	memset(&pkt->_reserved2, 0, sizeof(pkt->_reserved2));
 
 	switch (pkt->type) {
 	case VMCI_TRANSPORT_PACKET_TYPE_INVALID:
Signature · 1 line
2.50.0
#5 lore raw
In reply to Greg Kroah-Hartman
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 21 lines · On Tue, 1 Jul 2025 14:22:54 +0200 you wrote:

From: HarshaVardhana S A <[email protected]>

In vmci_transport_packet_init memset the vmci_transport_packet before populating the fields to avoid any uninitialised data being left in the structure.

Cc Bryan Tan <[email protected]>
Cc Vishnu Dasa <[email protected]>
Cc Broadcom internal kernel review list
Cc Stefano Garzarella <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc stable <[email protected]>
Quoted 1 line

[...]

Here is the summary with links:
- [net] vsock/vmci: Clear the vmci transport packet properly when initializing it

    https://git.kernel.org/netdev/net/c/223e2288f4b8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html