Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2274850pxb; Mon, 11 Jan 2021 05:48:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhqDj2pskGUGtKkHT8V4+maJGMO1BYmnKOtuj506157E5Jlsjm312bw4GK52FvAAjTzZs6 X-Received: by 2002:a50:ce13:: with SMTP id y19mr14283497edi.241.1610372913215; Mon, 11 Jan 2021 05:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372913; cv=none; d=google.com; s=arc-20160816; b=0ke/rB8jL2keO9254P78azVbnJy++QPoJVcF2o/q092WfMUdP5x9ui3BGPpZJL0gJI cVMJOdElXeEUuJIyLwr9uopICs9xvJ5OZmgpI6BMUmQV/AUta3hv4YXOk4qBdcaacFKF p0RDX8yRQeymC+X+TV7tRD/N3nk4dZ3qkxY8koIxpfn8KizhbRHK9JsaQUE7xLYVS9ZM auOiY1cv+ek/26P7ThTKQmyc4hFwFz/nO/ODU9LJNT7Lq/XQvPlw9Yfik/glCXI98woF qyEjFmsY9RLfAq+ASnuA2a4/Fo+76lzX62BnLQFtoesFXfNRl4VLupd3R1guc4F2Fteg k/iw== 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=nhbL/QlNWHcSPewqjxeaIVXbuqsG+rSLAOGMaJE81mE=; b=Kzh7lGIRMNNQojollfew+aZiBM/hFr1CdQXURrLjTb73J0euWX09Vs2ECxbfYHEeSF vEBTYa1VBaCazsIBjCN9VJoiuZt7+Ccni49sI9SyJeVY9EGG169hbqV0JhCdmAd8F5EB acU0nq3KLMIatr96bn4Fl0F7eYDn2yCT+YTTTk3fAxeXAqBYWhz7tC5r+3K0R4VEI6fJ ZMM+gqVAgvIgHo8Dz7uL76Gv2X2ge/sHp+pYAsMkvxaoddDY/0GO5bIU25qsPKdFDAdQ jayfJrIp64NyVs4eXuFQotQOkwv9PVFoOQD+AgJYRP7R2QRTOQRXiM/egFDmBsyUi02K tj4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ob6qxVXy; 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 dc28si6634143edb.219.2021.01.11.05.48.09; Mon, 11 Jan 2021 05:48:33 -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=ob6qxVXy; 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 S1731796AbhAKNpN (ORCPT + 99 others); Mon, 11 Jan 2021 08:45:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:58878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731439AbhAKNLl (ORCPT ); Mon, 11 Jan 2021 08:11:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 273BC229C4; Mon, 11 Jan 2021 13:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370660; bh=blUMQHoXIKTmHAs/tkVLjkrrjh9v/Zn/TYAiAvccOzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ob6qxVXyBLhThBKuYRT8tRibskfvl4fbGvARofEhCMnTsHrkDmCtpvROvlqlqL1lP mTBPHkk7mzjzDvvWRyR6r6ckXcF1+oYnWWQx8kHatifVPj0qX455ghmjFjZ1uK6EBH MceoX6QbrM040ntdQWvf7vxBRe+nKWHZ4U6jF+IA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunjian Wang , Willem de Bruijn , "Michael S. Tsirkin" , Jason Wang , Jakub Kicinski Subject: [PATCH 5.4 43/92] vhost_net: fix ubuf refcount incorrectly when sendmsg fails Date: Mon, 11 Jan 2021 14:01:47 +0100 Message-Id: <20210111130041.220554024@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@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: Yunjian Wang [ Upstream commit 01e31bea7e622f1890c274f4aaaaf8bccd296aa5 ] Currently the vhost_zerocopy_callback() maybe be called to decrease the refcount when sendmsg fails in tun. The error handling in vhost handle_tx_zerocopy() will try to decrease the same refcount again. This is wrong. To fix this issue, we only call vhost_net_ubuf_put() when vq->heads[nvq->desc].len == VHOST_DMA_IN_PROGRESS. Fixes: bab632d69ee4 ("vhost: vhost TX zero-copy support") Signed-off-by: Yunjian Wang Acked-by: Willem de Bruijn Acked-by: Michael S. Tsirkin Acked-by: Jason Wang Link: https://lore.kernel.org/r/1609207308-20544-1-git-send-email-wangyunjian@huawei.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -860,6 +860,7 @@ static void handle_tx_zerocopy(struct vh size_t len, total_len = 0; int err; struct vhost_net_ubuf_ref *uninitialized_var(ubufs); + struct ubuf_info *ubuf; bool zcopy_used; int sent_pkts = 0; @@ -892,9 +893,7 @@ static void handle_tx_zerocopy(struct vh /* use msg_control to pass vhost zerocopy ubuf info to skb */ if (zcopy_used) { - struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head); vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS; ubuf->callback = vhost_zerocopy_callback; @@ -924,7 +923,8 @@ static void handle_tx_zerocopy(struct vh err = sock->ops->sendmsg(sock, &msg, len); if (unlikely(err < 0)) { if (zcopy_used) { - vhost_net_ubuf_put(ubufs); + if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) + vhost_net_ubuf_put(ubufs); nvq->upend_idx = ((unsigned)nvq->upend_idx - 1) % UIO_MAXIOV; }