Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5074894pxb; Mon, 15 Feb 2021 08:51:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxx+5tzTocbyMpR8ZlbGHbQ/7n2oTx+8d2yJNHEi7xQFULTk1lzt6Jg5+17TqJrHmdBCmYK X-Received: by 2002:a17:906:4e45:: with SMTP id g5mr1778601ejw.186.1613407898109; Mon, 15 Feb 2021 08:51:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613407898; cv=none; d=google.com; s=arc-20160816; b=FR13ugQZJRNiXTRAuAz5GOqkCpuGO18ZJONF5wnQwUiZTysiTqsQl5r5RZ5qjVzcO1 owX0FqLeeR6byjrsGoFYDAQ14b+rONOeH5yl7FTxz9kYI17UzbE6TDEREhND5uUX2hry Z58YDL8G7a1wkizjuc1u7TtP50Vj4XSEq+zjE0IYF3B4oOJPGSch2huiktLvdRLDIeui Izr6PJWcERdTOb7MkNOahBJJmrHpC84AX2OgpSH8lQyTQjAZRnuVzFJNCvxLqipkpPMo m8WivQ/n+dUgtllJdWni5jP1n85iSIJ8L/+RYQyxIvaqSzrwDRoG7wg0XKpDHClQ3nJn S4lQ== 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=vlnljOwSHenGKYbQDMRIprgMj14ENWWvX0L/wEg8hKY=; b=VNG3ONV30CT9fe4B06zBg2J3ogeWDCj0cqWaZbnfI0wEti1WpMV4NgYtMJB6yfJxW7 PIkRppQKlRR5L+c2sonFS82+k29dExcqJReU76FazpksTXewldlI8H3MM6wtvz5FPf/8 z8k2y3LnwCkt4zVJCrbCxQld8L4g1AqE3VcvbQNynaLiazvH4Edvopf22Zw1HYtzQ9DI V7m1dyl4vwc7jsQj+pAq7mCT7GqmWqNwmVtw7Iqr9893YV7II+Yrt/clxepXwDIid2Em Jr0gQgBPOWhXtc5Ch+6WElnbGFXWlntSfIB8DH9lFy+EkcTFwED0L731G9gSEi9Nppav nvOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CgZl1J1k; 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 s22si3070654eja.338.2021.02.15.08.51.13; Mon, 15 Feb 2021 08:51:38 -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=CgZl1J1k; 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 S231186AbhBOQue (ORCPT + 99 others); Mon, 15 Feb 2021 11:50:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:49638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbhBOPiX (ORCPT ); Mon, 15 Feb 2021 10:38:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BAED664EFA; Mon, 15 Feb 2021 15:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403289; bh=Ep7ueRS3pWvf+wcVb/DumE+C/snQ9vS6/p6iQUmTIZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CgZl1J1kB9dE0a9zsOUOij+22b46HRNWd3mD0ZJJUsWZQVWaCgsdtGhyTFlf5arJC CuTadd+SJuh0UtPG6DjpcoEBQVlQhp9GjqUVtXPyN10MVM9OHUle8A6Lbs+u6Pz0Lw cenEElgRtRoG1bGsz1HxtHxGXFmAEDAEpZZS2cb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , "Michael S. Tsirkin" , Jakub Kicinski Subject: [PATCH 5.10 099/104] vsock/virtio: update credit only if socket is not closed Date: Mon, 15 Feb 2021 16:27:52 +0100 Message-Id: <20210215152722.667509924@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: Stefano Garzarella commit ce7536bc7398e2ae552d2fabb7e0e371a9f1fe46 upstream. If the socket is closed or is being released, some resources used by virtio_transport_space_update() such as 'vsk->trans' may be released. To avoid a use after free bug we should only update the available credit when we are sure the socket is still open and we have the lock held. Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko") Signed-off-by: Stefano Garzarella Acked-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20210208144454.84438-1-sgarzare@redhat.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/virtio_transport_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct vi vsk = vsock_sk(sk); - space_available = virtio_transport_space_update(sk, pkt); - lock_sock(sk); /* Check if sk has been closed before lock_sock */ @@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct vi goto free_pkt; } + space_available = virtio_transport_space_update(sk, pkt); + /* Update CID in case it has changed after a transport reset event */ vsk->local_addr.svm_cid = dst.svm_cid;