Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5074171pxb; Mon, 15 Feb 2021 08:50:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzc4Py2mPJyTRZ7yGebT1VucIykTHQDvwLeOXkbBAVYPXkgjcvmqLUZhWLtI9+X0sWLTdEl X-Received: by 2002:a17:906:b4a:: with SMTP id v10mr16085590ejg.382.1613407827785; Mon, 15 Feb 2021 08:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613407827; cv=none; d=google.com; s=arc-20160816; b=ovT/XCU4ZpoWQL0FX52oeBwaq+nmFl5Ro5XOmeHUvNjKjez8FzVJBXsz+TaNNXImdN nCL4QH5vFZ3/dBW6mXcGhkoOxEcbywA19HTZdvSOs8sqft5TEqCY8d1Vo291jCk93mPC DNkgFuBrYwe4rVqwOGqIv8lpLWSq8HDx/TW24ntWjL6phw4uWDWdYn86mG9AfOziLFif GV+UQVx2FnSstJ8TURSzg77cOc2DWxCMkV3O2YbhJ8nwq1BcythfxKCuLYWhi2TeG/a7 vS8J/zfzVPDPOKFTD3vs1HzPa6YsEdq5cg1oVWV3/RmLQyzXzsjWRJAyUcaqSv7ZUVpv gxFw== 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=BtwhI95GZMuTjM9s/kGoJ45M17hXAc+XJBCnr23OUGU=; b=GaP1bB/IALNDNHn1BsJe5U5Lxli1BKUG3HLHyQbIomlWwQXg25zFHNbS1UBosBRBeR P78h43abprg8TOdNjTzkwyBpFB92xekEq7RjYwsk0FE8uz/hJ2/XtdI1TfWLfKtvogue Z4sadE0D8kYrgPEpEek5ofMmIK8BNF9r5wQWdyHeMa6MOMvplVLn057A1wZE9y75U6PQ ksvzA1PH7n0gJIz05Gc0Y+oFiBgw/L48Qe9ydNU2W0h28QiBSiW9E5IXhpkwlx6HHLsf Y7xQlsmSVm657T7wOsCGKvCEOoPqkAAn2HFUDpTrBEJAfNWdYkBWPQsAppp5+RIQ8PPQ 6V/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J7cHcA1I; 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 r5si12417408edv.548.2021.02.15.08.50.04; Mon, 15 Feb 2021 08:50:27 -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=J7cHcA1I; 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 S231447AbhBOQtI (ORCPT + 99 others); Mon, 15 Feb 2021 11:49:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:50042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231233AbhBOPiP (ORCPT ); Mon, 15 Feb 2021 10:38:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 245D064EF6; Mon, 15 Feb 2021 15:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403278; bh=0AlPLogGtK1SwXe8ZdnVnb8dMs7TMLLOsQwwLeE2qT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J7cHcA1IcnY0LhdIOPqgmDD408IT1E89M1rs2lcl/yNFt7h6GMMr3zl0PSIJ+/uN8 GsEXB11owIoU/VVArcY9HMKTPHqUU4OEIm5aWtZQ+1WsLUixwmxOBqe1nPNbnrkvBo f+DSXvYOmpNeNANrFNR6L8Rne75R856QaFeCNTeM= 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.10 095/104] net/vmw_vsock: improve locking in vsock_connect_timeout() Date: Mon, 15 Feb 2021 16:27:48 +0100 Message-Id: <20210215152722.535194363@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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 @@ -1226,7 +1226,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); @@ -1237,11 +1236,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); }