Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2671733pxb; Mon, 11 Jan 2021 16:44:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzo8l2KojSAWfro/ztxISiexqLtiJwSF3Q+Jdg8Ewx2J5B4VMHMLOSwTEXrx0F6iKulNtB X-Received: by 2002:a05:6402:13d1:: with SMTP id a17mr1374917edx.202.1610412291025; Mon, 11 Jan 2021 16:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610412291; cv=none; d=google.com; s=arc-20160816; b=YgyfXSWSr0sVXtNPqtTC13mGpOO7fVlxXtkmAG28q0Q1Izc7i34lPb1jrajJ7RNZm6 TM+3DK3cIFn+RL1XANJduoVnJS/nOM+SUflFDW5H/slmwG62g5DoIRohDRijBu7il/lo GUqJlO2RyRv1oqvagRinIL5Ey7kJjklztV5Gei82QJ36d+l3+tlSuSSdD2NVsVyJP/eR f0YVeOb9cmKZVPkzGYZ8exc60D+hLtIwRhuJJMWMSZl86UWdwxWskEJzK+HY6ajRzCf8 gkkHiKw4jWKn4H5Q3nfjKRZkwlMg3VyCmEHFlWs3QO93wAGGZd4RH3vwmkukpJMkjJP6 ZhMQ== 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=ppYEiS8imgPNrltTJLCQTBdWEQEe48WPIjAKCN1J3Sw=; b=swgdRCHi2aRnFatt8Ux2YP4Ma/phaFksswk2/td1xhB7hjTXUX/0njXkqPBsP+lcoj NLvTVVNSY/GTLNkT/Ji8KDPFU71nYl8hNEcmbYyLpxrlFJ9XLXIUY4BRhhLXeH+TTMQL gJQFoFOyvVGM7xIyjLp1JUS0uUavpDnYpZXiPqc4h+pr9MzZHGpgU9fRaBoPP9hasbGu sNhkyvoWKMJqqO8eraQM6b0QyPq2BgTOBuyPFgOMPIalGysIEkiA6TpKSHOr3Vl/luYG MlNz8ecQgOlbbmu3jBVQP4Ptf4b4WA8aqdzc4F3KczjdhI/2GQB63tfI1m78WbT11qJr 175Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nMX5e6XH; 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 r19si400697ejs.1.2021.01.11.16.44.27; Mon, 11 Jan 2021 16:44:51 -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=nMX5e6XH; 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 S1727866AbhAKNAv (ORCPT + 99 others); Mon, 11 Jan 2021 08:00:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:48498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727847AbhAKNAu (ORCPT ); Mon, 11 Jan 2021 08:00:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE7DE2251F; Mon, 11 Jan 2021 13:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370009; bh=8q5h240r0//eU8wdVDqG3rrKt+70xf4+EaErF+T3aSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nMX5e6XHsQBr+SzoAsh9bdV0We1Mvj9SGBfIAJZo3hVjoXsTcp6uGG+Y07I198sYy J9FuZyFhB17+aaxoehXlClekpnoZsV82HAUOBq/7aRZwzTUMPNZ1c1t4SgZGdfmlhm jntSsNYfOgGdym+g89x711o6JtavAbPCpq/tdMoQ= 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 4.4 11/38] vhost_net: fix ubuf refcount incorrectly when sendmsg fails Date: Mon, 11 Jan 2021 14:00:43 +0100 Message-Id: <20210111130033.012589871@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130032.469630231@linuxfoundation.org> References: <20210111130032.469630231@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 @@ -313,6 +313,7 @@ static void handle_tx(struct vhost_net * size_t hdr_size; struct socket *sock; struct vhost_net_ubuf_ref *uninitialized_var(ubufs); + struct ubuf_info *ubuf; bool zcopy, zcopy_used; int sent_pkts = 0; @@ -378,9 +379,7 @@ static void handle_tx(struct vhost_net * /* 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; @@ -399,7 +398,8 @@ static void handle_tx(struct vhost_net * 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; }