Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp804671pxb; Tue, 3 Nov 2020 13:01:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJybv78lIsLQoRVM88lJkwL6521R+JEm05pbSNLOiW0I95sifBXqZdkSgc350DL7MZxHBFwh X-Received: by 2002:a17:907:420d:: with SMTP id oh21mr13229550ejb.429.1604437311896; Tue, 03 Nov 2020 13:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437311; cv=none; d=google.com; s=arc-20160816; b=tGiXlnl1ZQ7onyeJSydZiAXhJOk6ErquhoGSa+vopX0OwdtUsIFLV8bjgk7KvhEQuM JA16kTQ4sGqVeAvlvURAb09+50bIHryFXmvQwj0wWc78TLztg8PVIiaW+ZDeFB6yArdg NjpziQRxtv0bxUOnIG5BTycxZB+9wLJvjGsdbq6v1uOnhPNaYcExUICxLiKEC6QhzUnm 8cjqXNTb4k9JhAYnN2LJZjdRJ7MTN7jSh/r0oWad6L27zYrMwtTZIj5oZggi9gHc5o1d JfgRTKdKN5sWZYwwoqDpxggGhnp/pZ8uQ3Q2H0wu3QPxPhdD7GNilPKUwq0x6+BSeTQQ sp2Q== 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=SJN/2HUuB5U82vvsEJzmJcy28o2a5A03vei5f9OyiNA=; b=IgQ7skOcJamSHuMAc3x7TCWxjq2y5tVrB1tcDNZckN9wEtAIe+L6u2HlRuqddPspRQ 6wR3sa0NzHX+t3/VftZqJ0tlrz/olp/fRK1DocmErRtoCInw+YaEr95AT9EUp3GBKpfN 2xRR1+xrh1mZeFjPq8YI0JiS1zxPoejbOx6iVA4juB3N2dUItMJqP28tID0m480F04tX 79mYYZ5knrnc54STowK4Nw70d9yJEAbH2RdR0/a9a2F68BxXycfN6ZGVIxQ/E4iOOji6 gnM5KTrGvodBJBD6CKa2ht/fYhO0XKU2u8TqabuKLd97ELUx9HZ8CLdDIrKf6lYr43Gw EnNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1JScxD/j"; 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=fail (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 z22si6531ejx.130.2020.11.03.13.01.28; Tue, 03 Nov 2020 13:01: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=@kernel.org header.s=default header.b="1JScxD/j"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733200AbgKCVAN (ORCPT + 99 others); Tue, 3 Nov 2020 16:00:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:35754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733194AbgKCVAK (ORCPT ); Tue, 3 Nov 2020 16:00:10 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ED34822226; Tue, 3 Nov 2020 21:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437209; bh=KGj7hc9saSvkw5N+ZoDKkAxmzWc7OUOqDRpSDOrDoNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1JScxD/jDOk+0H18P0PePeLl3ngitMcDqUAVdKPPM0TNgcX3lGMaBBX6WF+K7sQg+ gqdSpm7tG3RphZTW/BN16eQEr6KQEwqtS3svjWcJpTyPWpps9kGs4V9VfynV9fHw3w 8PXR+tHg+yBzq6l9GtDmuzR+i9XI9kK5GA4r0c/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , "Michael S. Tsirkin" Subject: [PATCH 5.4 191/214] vringh: fix __vringh_iov() when riov and wiov are different Date: Tue, 3 Nov 2020 21:37:19 +0100 Message-Id: <20201103203308.577022545@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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 5745bcfbbf89b158416075374254d3c013488f21 upstream. If riov and wiov are both defined and they point to different objects, only riov is initialized. If the wiov is not initialized by the caller, the function fails returning -EINVAL and printing "Readable desc 0x... after writable" error message. This issue happens when descriptors have both readable and writable buffers (eg. virtio-blk devices has virtio_blk_outhdr in the readable buffer and status as last byte of writable buffer) and we call __vringh_iov() to get both type of buffers in two different iovecs. Let's replace the 'else if' clause with 'if' to initialize both riov and wiov if they are not NULL. As checkpatch pointed out, we also avoid crashing the kernel when riov and wiov are both NULL, replacing BUG() with WARN_ON() and returning -EINVAL. Fixes: f87d0fbb5798 ("vringh: host-side implementation of virtio rings.") Cc: stable@vger.kernel.org Signed-off-by: Stefano Garzarella Link: https://lore.kernel.org/r/20201008204256.162292-1-sgarzare@redhat.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vringh.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -274,13 +274,14 @@ __vringh_iov(struct vringh *vrh, u16 i, desc_max = vrh->vring.num; up_next = -1; + /* You must want something! */ + if (WARN_ON(!riov && !wiov)) + return -EINVAL; + if (riov) riov->i = riov->used = 0; - else if (wiov) + if (wiov) wiov->i = wiov->used = 0; - else - /* You must want something! */ - BUG(); for (;;) { void *addr;