Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5045423pxb; Mon, 15 Feb 2021 08:08:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjsBzEktYLyzSORKKdRPrBKz7pmxJLy32Vgl2kimlwVvP9M2dfYZgZnL/3rgNonnGMNRsD X-Received: by 2002:a17:906:3603:: with SMTP id q3mr15456949ejb.201.1613405282795; Mon, 15 Feb 2021 08:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613405282; cv=none; d=google.com; s=arc-20160816; b=jqkZJsOubkx9RcQtZnArgXQdIXUiiNNuKXd+HziYKpw+2r0BX3BIFRphGtKvDqaZeb FOLPW8Mv33xCX/oigvdnJnLSy/d1N+9nbdeoeuehHzECrYP+4GcUAurOQjSIIBRrgUiM SD3IXQrOPeWfrLKJqeCrIo/PioAj5AERqJUQlN1WAw6vzRcCLK4vIT0NClM5Qcm1SMv0 LPslHc9DgKpfR01I0Zmao+tRzM03P5GTOAqFstxndd0hZG9FnLHBFwtkl5pCcRlMOoRM /PyB8dYrYCGixJKVkbEEHp0tmX6dkxxMqU4xH6VrFjVscMI/RDuDmWXyvWcuGwewpDtV 2iOw== 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=rs43L8uX5gzKjxPy00gsNtCWhYyXtVnNxuA6JMJBhM8=; b=iiV4G4kDOgWQYcLt5cONSI4auU69ksMZu/EBz/XGlylY+YWauEvmL6b2s8fzTE4edA L7+bKt4i1lP1tGcoF6G/wdXlS/SyP5MPsCwzy64lHNqSyuVASBdTQGUuN+jxgmCj2Xyt T/k3aa5oYYekeVifGRkZCnie/rNOZfFdwprHIk4syj+Hr+E6g6WGipOGBJdKrCarJtSE jT9xCkJrfEVeTj5NPYbSVgqQDVI9Ge2DOjnD2DRGBPw5gqWiVEhtUY5gpIa1ohKqIWWp jUqohEk9rS9BOEVD594dNMde2KXroN3Z1Et9o32LJ5PLVCBYJ0D24GOWeRUHe2jyLITO pzQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NhVZdQBX; 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=pass (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 he44si11878239ejc.386.2021.02.15.08.07.38; Mon, 15 Feb 2021 08:08:02 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=NhVZdQBX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbhBOQEi (ORCPT + 99 others); Mon, 15 Feb 2021 11:04:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:45562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbhBOPdE (ORCPT ); Mon, 15 Feb 2021 10:33:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 825DC64E40; Mon, 15 Feb 2021 15:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403036; bh=NOyyeL77NUTv98Y848xGO+3HSM9x62gtqcGywx7QLbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NhVZdQBXd2toEh0MHjFa/LAw3Gbm887K5uuN+46SWn3YHzJAfjfi0ZB7aK2hHTXhV rnAPQmsO2bzjJlrlLHcHgxbpZk5l4dTK1BqC0ZV6Try2bScNaMia6s5y2zODKYeCDE /cnLNpoj8Aj9j7h+IyTH/ENQNLCq0YjaSER3Btfk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Norbert Slusarek , Stefano Garzarella , Jakub Kicinski Subject: [PATCH 5.4 54/60] net/vmw_vsock: improve locking in vsock_connect_timeout() Date: Mon, 15 Feb 2021 16:27:42 +0100 Message-Id: <20210215152717.106683626@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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: Norbert Slusarek commit 3d0bc44d39bca615b72637e340317b7899b7f911 upstream. A possible locking issue in vsock_connect_timeout() was recognized by Eric Dumazet which might cause a null pointer dereference in vsock_transport_cancel_pkt(). This patch assures that vsock_transport_cancel_pkt() will be called within the lock, so a race condition won't occur which could result in vsk->transport to be set to NULL. Fixes: 380feae0def7 ("vsock: cancel packets when failing to connect") Reported-by: Eric Dumazet Signed-off-by: Norbert Slusarek Reviewed-by: Stefano Garzarella Link: https://lore.kernel.org/r/trinity-f8e0937a-cf0e-4d80-a76e-d9a958ba3ef1-1612535522360@3c-app-gmx-bap12 Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/af_vsock.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1099,7 +1099,6 @@ static void vsock_connect_timeout(struct { struct sock *sk; struct vsock_sock *vsk; - int cancel = 0; vsk = container_of(work, struct vsock_sock, connect_work.work); sk = sk_vsock(vsk); @@ -1110,11 +1109,9 @@ static void vsock_connect_timeout(struct sk->sk_state = TCP_CLOSE; sk->sk_err = ETIMEDOUT; sk->sk_error_report(sk); - cancel = 1; + vsock_transport_cancel_pkt(vsk); } release_sock(sk); - if (cancel) - vsock_transport_cancel_pkt(vsk); sock_put(sk); }