Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3521609imu; Mon, 7 Jan 2019 05:02:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN5qEDiv8LMW/yg0siHQiBK4F+u8lbOTX71WDyUHIFSR3RWG3fEFXAWXI1L2d2nZUV7/HJXE X-Received: by 2002:a63:1204:: with SMTP id h4mr10835386pgl.51.1546866167292; Mon, 07 Jan 2019 05:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546866167; cv=none; d=google.com; s=arc-20160816; b=t7nXL7XXQZG8AZsN+XLJtZGB4usD/iOBZpvgnX0I/0kI0sgVjOEsdHJ6yZrOonuT/Y 2HGTfD3Ik8wQlXTPSbGvhdD0RdFBRsQdo/7GdJ74yzc7rwvMSWLs2USc9zBniGsdS7WX IHK529P5TFbToPn90CW5BxXsll7VeiWrwar8jOeYx2P/wHjb3kim8hp73AXku87iSC3B 2SyXDjLzoGvW0oui09t9MJKWraM/xkDo0LaVWAapSWYGT+oHgCYZbVaagJZO3Op4Sf2/ Xo+s59ruZCwhDZ/iYXT2qdW+CgZ3BLi5Vq6dqOcFYzoXjmm/q6Ed8jffN2aMC8BErpuu yt7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hVa56L+TqEgcxUy4Is9DnAGhdkIAt3fe35FNUC7voK4=; b=X7/tWQVmccunigPQz+WUEYKJj0GxoAY7cd4pUJrZIMqyN0JKz/en4VyAhZpxtm8sem 83HdVoftDC13CwYI0VrOsCbw5+EKwlc1+QujeKUy+mWxRBoERgjJXtmg8u2orRTSu+N+ erQKTGoTs4xpTpcNPpCmsMB0aXuCxikWAlMGQkzDvRvLhmKJ/2JPmw5VLBbFWwngJRYV Je2BghPn8KeBPadVo0GT9MTwRelXl7+QF9MCPYWJSPI8gDE8prIohQncuHte9KJS2IG1 UyzKaPPG9vBhtaJUnlhBkFdviBWAl9eVXz89JyTZqBgDNb3OHL4IslQuHf9hTDh3PY2y 1wMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MxW4Fjk3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24si14598408pgd.248.2019.01.07.05.02.31; Mon, 07 Jan 2019 05:02:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MxW4Fjk3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730244AbfAGNAn (ORCPT + 99 others); Mon, 7 Jan 2019 08:00:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:48138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730223AbfAGNAk (ORCPT ); Mon, 7 Jan 2019 08:00:40 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 E32CF2089F; Mon, 7 Jan 2019 13:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866039; bh=AQf9W1ipM8DhB5Vm0utMkTnZlww5C3IHpDfX70Y3MGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MxW4Fjk3Xpolyk2rRFpH6rtqqh+72kemWjreYabVo5OEEfO4kby3kZSkdsV19y/Tt 4q4jKzflGV6GfSru+t0LxKZOrdKWLpsl7yAKujq15k6clk2VBPmMReEezs6VENwMtw 1Yx1ZRLt25qMUJAcchp1dLwaLgZYbrSZiWTR7I6U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adit Ranadive , Vishnu Dasa , Jorgen Hansen , "David S. Miller" Subject: [PATCH 4.14 025/101] VSOCK: Send reset control packet when socket is partially bound Date: Mon, 7 Jan 2019 13:32:13 +0100 Message-Id: <20190107105334.305474407@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.372621917@linuxfoundation.org> References: <20190107105330.372621917@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jorgen Hansen [ Upstream commit a915b982d8f5e4295f64b8dd37ce753874867e88 ] If a server side socket is bound to an address, but not in the listening state yet, incoming connection requests should receive a reset control packet in response. However, the function used to send the reset silently drops the reset packet if the sending socket isn't bound to a remote address (as is the case for a bound socket not yet in the listening state). This change fixes this by using the src of the incoming packet as destination for the reset packet in this case. Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Reviewed-by: Adit Ranadive Reviewed-by: Vishnu Dasa Signed-off-by: Jorgen Hansen Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/vmci_transport.c | 67 ++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 17 deletions(-) --- a/net/vmw_vsock/vmci_transport.c +++ b/net/vmw_vsock/vmci_transport.c @@ -265,6 +265,31 @@ vmci_transport_send_control_pkt_bh(struc } static int +vmci_transport_alloc_send_control_pkt(struct sockaddr_vm *src, + struct sockaddr_vm *dst, + enum vmci_transport_packet_type type, + u64 size, + u64 mode, + struct vmci_transport_waiting_info *wait, + u16 proto, + struct vmci_handle handle) +{ + struct vmci_transport_packet *pkt; + int err; + + pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); + if (!pkt) + return -ENOMEM; + + err = __vmci_transport_send_control_pkt(pkt, src, dst, type, size, + mode, wait, proto, handle, + true); + kfree(pkt); + + return err; +} + +static int vmci_transport_send_control_pkt(struct sock *sk, enum vmci_transport_packet_type type, u64 size, @@ -273,9 +298,7 @@ vmci_transport_send_control_pkt(struct s u16 proto, struct vmci_handle handle) { - struct vmci_transport_packet *pkt; struct vsock_sock *vsk; - int err; vsk = vsock_sk(sk); @@ -285,17 +308,10 @@ vmci_transport_send_control_pkt(struct s if (!vsock_addr_bound(&vsk->remote_addr)) return -EINVAL; - pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); - if (!pkt) - return -ENOMEM; - - err = __vmci_transport_send_control_pkt(pkt, &vsk->local_addr, - &vsk->remote_addr, type, size, - mode, wait, proto, handle, - true); - kfree(pkt); - - return err; + return vmci_transport_alloc_send_control_pkt(&vsk->local_addr, + &vsk->remote_addr, + type, size, mode, + wait, proto, handle); } static int vmci_transport_send_reset_bh(struct sockaddr_vm *dst, @@ -313,12 +329,29 @@ static int vmci_transport_send_reset_bh( static int vmci_transport_send_reset(struct sock *sk, struct vmci_transport_packet *pkt) { + struct sockaddr_vm *dst_ptr; + struct sockaddr_vm dst; + struct vsock_sock *vsk; + if (pkt->type == VMCI_TRANSPORT_PACKET_TYPE_RST) return 0; - return vmci_transport_send_control_pkt(sk, - VMCI_TRANSPORT_PACKET_TYPE_RST, - 0, 0, NULL, VSOCK_PROTO_INVALID, - VMCI_INVALID_HANDLE); + + vsk = vsock_sk(sk); + + if (!vsock_addr_bound(&vsk->local_addr)) + return -EINVAL; + + if (vsock_addr_bound(&vsk->remote_addr)) { + dst_ptr = &vsk->remote_addr; + } else { + vsock_addr_init(&dst, pkt->dg.src.context, + pkt->src_port); + dst_ptr = &dst; + } + return vmci_transport_alloc_send_control_pkt(&vsk->local_addr, dst_ptr, + VMCI_TRANSPORT_PACKET_TYPE_RST, + 0, 0, NULL, VSOCK_PROTO_INVALID, + VMCI_INVALID_HANDLE); } static int vmci_transport_send_negotiate(struct sock *sk, size_t size)