Received: by 10.192.165.156 with SMTP id m28csp194552imm; Tue, 10 Apr 2018 19:39:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx486zs4Oj/eIrWvAsew0xgPyFZ/jbzJVZKwQvjOHLwiQzbQihxNRSZzC/9odXiKQiqooOtj/ X-Received: by 2002:a17:902:206:: with SMTP id 6-v6mr3003297plc.376.1523414368897; Tue, 10 Apr 2018 19:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523414368; cv=none; d=google.com; s=arc-20160816; b=xTeG8y28DoUC+4kZOmsp8O9pWACS/k6O348w3eluESUvzLlLLx8TIchTXXMdz4BTND 9ESUUNVeUMc35UkozGHpLIgLhk6lt6ay8Pp/MAGuxnshSP1I1VjGIyvdx7jb5RVG9NVP A1twjaXlb7W480BAMCpUroL2eCJmBeHlfnpbGTyCkRdfysPbMlBXUK1MLmAQFoxh1Zg8 aFzfPZQ1kRHbXnj3bp9LSYh4TKScKaASv/dTewDW9eAQbiSY2/0J9f+Sg19DZz1hxO5F cJ2BQUSZ06P9D+58SHNTCDVTsC510qLYY1YhreoT0DCCh+uy1sO6s4wQs1SBugZJpN0O ss0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=BeVD8JTo9G4ZbV299iazC5WwP0HXcR4rOR6SEaOeyic=; b=uZeMe27ZTH+UpcFaFzkCSFQv6B8IXWHhW/w6kH5oqU3DE5c9/2LEkrrq/DDkwtzVe3 LPoi9TKsOmIPAoU4fGGCT8+5DyaxgRLcQgYIORsVW48boZajox9nPm8k/sOC6jVUUd5U UOgzBl6FEO/hKH6w2oayIr2yHA9ZT/znIYIiBiqEFdnk8bdEkRxUQOkYm8r0cAWfbLw3 sXLXksFu1iNjrEhTC5Cd80zmhP7U7GanW5MAcdd7YBEVJPKKGZJjsfRz+CJs/1I3jh8c z032Tw11cqROfyG4U+oCOibmelqLbnRSBdpwceiDD0tKCpEhWeLSHbJ4QSwl14LPMLxI SJTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si138028plx.148.2018.04.10.19.38.52; Tue, 10 Apr 2018 19:39:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752915AbeDKCf6 (ORCPT + 99 others); Tue, 10 Apr 2018 22:35:58 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54078 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752850AbeDKCf4 (ORCPT ); Tue, 10 Apr 2018 22:35:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6B924075A66; Wed, 11 Apr 2018 02:35:55 +0000 (UTC) Received: from localhost (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0393084452; Wed, 11 Apr 2018 02:35:49 +0000 (UTC) From: Stefan Hajnoczi To: virtualization@lists.linux-foundation.org Cc: Linus Torvalds , jasowang@redhat.com, mst@redhat.com, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Hajnoczi Subject: [PATCH v3 1/2] vhost: fix vhost_vq_access_ok() log check Date: Wed, 11 Apr 2018 10:35:40 +0800 Message-Id: <20180411023541.15776-2-stefanha@redhat.com> In-Reply-To: <20180411023541.15776-1-stefanha@redhat.com> References: <20180411023541.15776-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 11 Apr 2018 02:35:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 11 Apr 2018 02:35:55 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit d65026c6c62e7d9616c8ceb5a53b68bcdc050525 ("vhost: validate log when IOTLB is enabled") introduced a regression. The logic was originally: if (vq->iotlb) return 1; return A && B; After the patch the short-circuit logic for A was inverted: if (A || vq->iotlb) return A; return B; This patch fixes the regression by rewriting the checks in the obvious way, no longer returning A when vq->iotlb is non-NULL (which is hard to understand). Reported-by: syzbot+65a84dde0214b0387ccd@syzkaller.appspotmail.com Cc: Jason Wang Signed-off-by: Stefan Hajnoczi --- drivers/vhost/vhost.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index bec722e41f58..fc805b7fad9d 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1244,10 +1244,12 @@ static int vq_log_access_ok(struct vhost_virtqueue *vq, /* Caller should have vq mutex and device mutex */ int vhost_vq_access_ok(struct vhost_virtqueue *vq) { - int ret = vq_log_access_ok(vq, vq->log_base); + if (!vq_log_access_ok(vq, vq->log_base)) + return 0; - if (ret || vq->iotlb) - return ret; + /* Access validation occurs at prefetch time with IOTLB */ + if (vq->iotlb) + return 1; return vq_access_ok(vq, vq->num, vq->desc, vq->avail, vq->used); } -- 2.14.3