Skip to contentSkip to conversation

vsock/virtio: update credit only if socket is not closed

PATCH Applied Stefano Garzarella 3 participants 3 messages Feb 8, 2021

Subsystems (6)
lore
Share & tools
lore

Stefano Garzarella

author maintainer
#0 lore raw

PATCH 1/1 vsock/virtio: update credit only if socket is not closed

If the socket is closed or is being released, some resources used by virtio_transport_space_update() such as 'vsk->trans' may be released.

To avoid a use after free bug we should only update the available credit when we are sure the socket is still open and we have the lock held.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
---
 net/vmw_vsock/virtio_transport_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/vmw_vsock/virtio_transport_common.c +2 -2
index 5956939eebb7..e4370b1b7494 100644
@@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 
 	vsk = vsock_sk(sk);
 
-	space_available = virtio_transport_space_update(sk, pkt);
-
 	lock_sock(sk);
 
 	/* Check if sk has been closed before lock_sock */
@@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 		goto free_pkt;
 	}
 
+	space_available = virtio_transport_space_update(sk, pkt);
+
 	/* Update CID in case it has changed after a transport reset event */
 	vsk->local_addr.svm_cid = dst.svm_cid;
 
Signature · 6 lines
2.29.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Stefano Garzarella

If the socket is closed or is being released, some resources used by virtio_transport_space_update() such as 'vsk->trans' may be released.

To avoid a use after free bug we should only update the available credit when we are sure the socket is still open and we have the lock held.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")

Probably stable material.

Quoted 28 lines
---
 net/vmw_vsock/virtio_transport_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/vmw_vsock/virtio_transport_common.c +2 -2
index 5956939eebb7..e4370b1b7494 100644
@@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 
 	vsk = vsock_sk(sk);
 
-	space_available = virtio_transport_space_update(sk, pkt);
-
 	lock_sock(sk);
 
 	/* Check if sk has been closed before lock_sock */
@@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 		goto free_pkt;
 	}
 
+	space_available = virtio_transport_space_update(sk, pkt);
+
 	/* Update CID in case it has changed after a transport reset event */
 	vsk->local_addr.svm_cid = dst.svm_cid;
 
Signature · 1 line
2.29.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw
In reply to Stefano Garzarella
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 10 lines · On Mon, 8 Feb 2021 15:44:54 +0100 you wrote:

If the socket is closed or is being released, some resources used by virtio_transport_space_update() such as 'vsk->trans' may be released.

To avoid a use after free bug we should only update the available credit when we are sure the socket is still open and we have the lock held.

Fixes 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")

[...]

Here is the summary with links:
- [net] vsock/virtio: update credit only if socket is not closed

    https://git.kernel.org/netdev/net/c/ce7536bc7398

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