Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3389190pxk; Mon, 5 Oct 2020 08:29:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuhEaZqoNNT6gDPEH3Px9hCFxse7vZlUFRTXosnfSH7Gc2Sl8u89CxrFu1nKIn6f141L9k X-Received: by 2002:a17:906:e103:: with SMTP id gj3mr264488ejb.442.1601911787440; Mon, 05 Oct 2020 08:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601911787; cv=none; d=google.com; s=arc-20160816; b=RIBz6wDHwHE9a9Vw2OY1FMfGCx2HDXj11F7Duo0WBNMSEzPJ2XgIq5OloBkk3CvXm9 4kWbe61y/NznJ4LgazOEyzkJUWTxA7GoH8FYSgX5Bm+35f6E+aOUHNIJEVESjQjzxPSg 9zb+JWLGf8vstTaIKwaXdIuj5/2JtbXoHLOY9QW9B6tGXEZhbo7Ham5HAyitX+pRQgNT l/taKU732O95JY9LVRdmt9Tog3n+xAEVTsRn2QQB4+f/xLVMC4ZEFZMRJt3UB3eboXt3 l1nmiS6AprKy/fjsY+w7KYTQNZ1EDpuTa9FPvyOgoEeFy4G73Qz6GdJn8OormtgXSW6N OKlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mWdi8lIcTZ5ertbRXfAlEVJrbXMdytygCOxdORNfnwo=; b=ldNZbBF3cQLaqAr0dH8/AdOMwuVflQNfIdTXreUXXDh/fFbnlzgX4++sM81IqPdesd lOHSpOjetVi1BBNnmR0U/HlE/KfOBb9+lOmi/Ka6jRC5wYGIG9tXpaX3IbmAUGlPy4bl u5q3wlx7qW9s3ASppPF4iICE1hcO1vSSCY9QxPS4sOZrct8TPEUGzswxkuSGMeowTx3+ yusX8KWIS0gpbpcgD4YdS18EXENzK8yGFm3WhJ0GAGegcWaqBoOyqbh2+EETgBswW+QM Su3oLmRUwcqCnEW/YEtJQ0lBRO0WinNxSOZiC9x9a1lP92nEdocIiS4H6kgNC490ZZzP 4/Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="M2gD/cvd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si193169edn.390.2020.10.05.08.29.24; Mon, 05 Oct 2020 08:29:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="M2gD/cvd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727296AbgJEP1p (ORCPT + 99 others); Mon, 5 Oct 2020 11:27:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727227AbgJEP1h (ORCPT ); Mon, 5 Oct 2020 11:27:37 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF79A208B6; Mon, 5 Oct 2020 15:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601911656; bh=YIm/NKgFwN/Rmeq25z4SHAJ4G351QeXq9DAzZZWMcCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M2gD/cvdPyXJqyiGWGDXU4j3rsVYu8NfR/DEKIFaRCEM3Ft1vtNW2m9V7VmBqMPVb sslSnsCqy0QOuEpTYMlCMKu7FsRPgB0tHR74XPjziJYJ04xlhieJ2bDajBUfKqsPYv WwLlZfmogIje1yOg/iEEBh+2chOugDT5LY6u0I7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastien Boeuf , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 09/38] net: virtio_vsock: Enhance connection semantics Date: Mon, 5 Oct 2020 17:26:26 +0200 Message-Id: <20201005142109.111620438@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005142108.650363140@linuxfoundation.org> References: <20201005142108.650363140@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastien Boeuf [ Upstream commit df12eb6d6cd920ab2f0e0a43cd6e1c23a05cea91 ] Whenever the vsock backend on the host sends a packet through the RX queue, it expects an answer on the TX queue. Unfortunately, there is one case where the host side will hang waiting for the answer and might effectively never recover if no timeout mechanism was implemented. This issue happens when the guest side starts binding to the socket, which insert a new bound socket into the list of already bound sockets. At this time, we expect the guest to also start listening, which will trigger the sk_state to move from TCP_CLOSE to TCP_LISTEN. The problem occurs if the host side queued a RX packet and triggered an interrupt right between the end of the binding process and the beginning of the listening process. In this specific case, the function processing the packet virtio_transport_recv_pkt() will find a bound socket, which means it will hit the switch statement checking for the sk_state, but the state won't be changed into TCP_LISTEN yet, which leads the code to pick the default statement. This default statement will only free the buffer, while it should also respond to the host side, by sending a packet on its TX queue. In order to simply fix this unfortunate chain of events, it is important that in case the default statement is entered, and because at this stage we know the host side is waiting for an answer, we must send back a packet containing the operation VIRTIO_VSOCK_OP_RST. One could say that a proper timeout mechanism on the host side will be enough to avoid the backend to hang. But the point of this patch is to ensure the normal use case will be provided with proper responsiveness when it comes to establishing the connection. Signed-off-by: Sebastien Boeuf Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/virtio_transport_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index fae2bded5d519..5f8a72d34d313 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1060,6 +1060,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, virtio_transport_free_pkt(pkt); break; default: + (void)virtio_transport_reset_no_sock(t, pkt); virtio_transport_free_pkt(pkt); break; } -- 2.25.1