Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1004153pxb; Wed, 1 Sep 2021 15:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSM0lRrohssqIqG2WddhzHj3EIVrFRuEiB3JC2CrJqD+uJEEcmYASsDDEtSfQIMdBdsICV X-Received: by 2002:a5d:8588:: with SMTP id f8mr36324ioj.46.1630533817427; Wed, 01 Sep 2021 15:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630533817; cv=none; d=google.com; s=arc-20160816; b=VhvDe7CYFajAFcdQzQorVMOjcoPcirVXgfRyI8zcWqSXPyQAuBm7x8hFpIRNe6NSF3 2VXRyo9A5jnXJ/YSNLQvKondaFG7eLrp6XrQ2+mmCCsBmfR7IL8kUh0ZxlwlqmAnNr6w vWkQYmvwi1HoEWJTGt9XBaMPoLKKYMTAqFEhCDSSk7miXA/BTpF/hEDuaV23pedkGc0u 7H4l0CvRLdwN+CSf44MXeabulXf0QyuD0gOsY+2Xm9cu7s8LbJQnnFcrxB3JBywXkAi5 LlHDiw9pYV1MBfhT074OYz9cjjykp08WqoSQlKSIkEbWViYGdgl6m4LtR0ks05nLZcBI yBpQ== 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=UDOemSK/K8ZlBn71LeAW2uPk6wW01fyzjq+mrF+nNy8=; b=PCTrpivEfIH5hN0dxb6AwiPELtOP7nuBCXRwdiIL0PqSM2KeTenDbCJSc98+Z4F84g pZcho+C1FS6Xdbo1OArjoRryYTEER8pcd2gX8uoCmDVK3fZW/x/Rq3o3C/PV9VbmYlbP TZp0D1i7QN8kRh+4aKO4Z8ndPVkohGCtBi4qd2gsAMRvnvCcBk32EtnVZlfa0sN4REN/ Q8+ESu2FWuGYtPaL1g9DP2HHD31zS8Bgm/hzKHzH/j4daHVTUz07KokzIePthKiPaTRm y8e8llPZGrezM/0f4qd18XYwedvNzpXRWlK7GksYX9yGN0q3Fsjugu1KoPvTf5Svac1E TQQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NZfCutLw; 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 f7si23907ilq.58.2021.09.01.15.03.25; Wed, 01 Sep 2021 15:03:37 -0700 (PDT) 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=NZfCutLw; 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 S1345162AbhIAMnB (ORCPT + 99 others); Wed, 1 Sep 2021 08:43:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:43738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344661AbhIAMjw (ORCPT ); Wed, 1 Sep 2021 08:39:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 07B1E610CF; Wed, 1 Sep 2021 12:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499740; bh=wcH7vU2eTeQRAkcXC8NdS1JplMlqCQXC0XZMfkTE6z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NZfCutLwdShNLNECQ9462PpzDL5HHdT70VVeYzx30jjLdP//y5VRm/3Ow2HqOTXwK xgOh4H9FTQchw56p1DVlKpAaTYabZMsfJUtO4l62YDPWJcIFrUj+NUuP5NtE4OduZf RfJSVBX/BsadMR5jtAiYtDiYhk4+21TQiyPyxI1I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Wang , Stefano Garzarella , Neeraj Upadhyay , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 5.10 060/103] vringh: Use wiov->used to check for read/write desc order Date: Wed, 1 Sep 2021 14:28:10 +0200 Message-Id: <20210901122302.584020524@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122300.503008474@linuxfoundation.org> References: <20210901122300.503008474@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: Neeraj Upadhyay [ Upstream commit e74cfa91f42c50f7f649b0eca46aa049754ccdbd ] As __vringh_iov() traverses a descriptor chain, it populates each descriptor entry into either read or write vring iov and increments that iov's ->used member. So, as we iterate over a descriptor chain, at any point, (riov/wriov)->used value gives the number of descriptor enteries available, which are to be read or written by the device. As all read iovs must precede the write iovs, wiov->used should be zero when we are traversing a read descriptor. Current code checks for wiov->i, to figure out whether any previous entry in the current descriptor chain was a write descriptor. However, iov->i is only incremented, when these vring iovs are consumed, at a later point, and remain 0 in __vringh_iov(). So, correct the check for read and write descriptor order, to use wiov->used. Acked-by: Jason Wang Reviewed-by: Stefano Garzarella Signed-off-by: Neeraj Upadhyay Link: https://lore.kernel.org/r/1624591502-4827-1-git-send-email-neeraju@codeaurora.org Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/vhost/vringh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index b7403ba8e7f7..0bd7e64331f0 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -341,7 +341,7 @@ __vringh_iov(struct vringh *vrh, u16 i, iov = wiov; else { iov = riov; - if (unlikely(wiov && wiov->i)) { + if (unlikely(wiov && wiov->used)) { vringh_bad("Readable desc %p after writable", &descs[i]); err = -EINVAL; -- 2.30.2