Linux virtualization list
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: netdev@vger.kernel.org
Cc: "Simon Horman" <horms@kernel.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	linux-kernel@vger.kernel.org,
	"Eric Dumazet" <edumazet@google.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Wongi Lee" <qwerty@theori.io>,
	"David S. Miller" <davem@davemloft.net>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Bobby Eshleman" <bobby.eshleman@bytedance.com>,
	virtualization@lists.linux.dev,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Luigi Leonardi" <leonardi@redhat.com>,
	bpf@vger.kernel.org, "Jakub Kicinski" <kuba@kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Hyunwoo Kim" <v4bel@theori.io>, "Michal Luczaj" <mhal@rbox.co>,
	kvm@vger.kernel.org
Subject: [PATCH net 1/2] vsock/virtio: discard packets if the transport changes
Date: Wed,  8 Jan 2025 19:06:16 +0100	[thread overview]
Message-ID: <20250108180617.154053-2-sgarzare@redhat.com> (raw)
In-Reply-To: <20250108180617.154053-1-sgarzare@redhat.com>

If the socket has been de-assigned or assigned to another transport,
we must discard any packets received because they are not expected
and would cause issues when we access vsk->transport.

A possible scenario is described by Hyunwoo Kim in the attached link,
where after a first connect() interrupted by a signal, and a second
connect() failed, we can find `vsk->transport` at NULL, leading to a
NULL pointer dereference.

Fixes: c0cfa2d8a788 ("vsock: add multi-transports support")
Reported-by: Hyunwoo Kim <v4bel@theori.io>
Reported-by: Wongi Lee <qwerty@theori.io>
Closes: https://lore.kernel.org/netdev/Z2LvdTTQR7dBmPb5@v4bel-B760M-AORUS-ELITE-AX/
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 net/vmw_vsock/virtio_transport_common.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 9acc13ab3f82..51a494b69be8 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1628,8 +1628,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
 
 	lock_sock(sk);
 
-	/* Check if sk has been closed before lock_sock */
-	if (sock_flag(sk, SOCK_DONE)) {
+	/* Check if sk has been closed or assigned to another transport before
+	 * lock_sock (note: listener sockets are not assigned to any transport)
+	 */
+	if (sock_flag(sk, SOCK_DONE) ||
+	    (sk->sk_state != TCP_LISTEN && vsk->transport != &t->transport)) {
 		(void)virtio_transport_reset_no_sock(t, skb);
 		release_sock(sk);
 		sock_put(sk);
-- 
2.47.1


  reply	other threads:[~2025-01-08 18:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 18:06 [PATCH net 0/2] vsock: some fixes due to transport de-assignment Stefano Garzarella
2025-01-08 18:06 ` Stefano Garzarella [this message]
2025-01-08 19:31   ` [PATCH net 1/2] vsock/virtio: discard packets if the transport changes Hyunwoo Kim
2025-01-09  9:01     ` Stefano Garzarella
2025-01-09  9:06       ` Michael S. Tsirkin
2025-01-09  9:13       ` Hyunwoo Kim
2025-01-09 10:59         ` Stefano Garzarella
2025-01-09 11:10           ` Hyunwoo Kim
2025-01-09 13:34   ` Michal Luczaj
2025-01-09 13:42     ` Stefano Garzarella
2025-01-09 15:27       ` Michal Luczaj
2025-01-10  8:39     ` Stefano Garzarella
2025-01-21 17:30     ` Luigi Leonardi
2025-01-21 18:06       ` Michal Luczaj
2025-01-08 18:06 ` [PATCH net 2/2] vsock/bpf: return early if transport is not assigned Stefano Garzarella
2025-01-08 19:37   ` Hyunwoo Kim
2025-01-09  9:07   ` Michael S. Tsirkin
2025-01-09  9:24   ` Luigi Leonardi
2025-01-09 13:14   ` Michal Luczaj

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250108180617.154053-2-sgarzare@redhat.com \
    --to=sgarzare@redhat.com \
    --cc=bobby.eshleman@bytedance.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=horms@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=leonardi@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhal@rbox.co \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qwerty@theori.io \
    --cc=stefanha@redhat.com \
    --cc=v4bel@theori.io \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox