Received: by 10.192.165.156 with SMTP id m28csp292125imm; Tue, 17 Apr 2018 10:11:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49LJQM24CdbAV56OcPWf90FEdTSptTZpyVXi+cY9yPr8Qq8+428gxM7e3L3vCuu/CGcQgnx X-Received: by 10.99.115.14 with SMTP id o14mr2490474pgc.121.1523985083420; Tue, 17 Apr 2018 10:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523985083; cv=none; d=google.com; s=arc-20160816; b=vZtFxNdmDwgshp+nRf9t7MIUCuASYfLkO25T2+854TGMjfSagundcAHjkGPWgEwCxg FNi7sfNY65Lp6aFaZd9YZUJc9tY7S5//P6FOoLbeVtELnQu+PzlysgiLRbeR/5KcFnM0 Gg0QA+4ttBD0U2GP7WjY/GIusWJmJ60IoVcyG31rXYE8NtLxR8OiwpREbKQBOPSkLGVm bjhE3JLlBh7SHjQvLjoT3onEwQ8ggzWbvVhzUSwDFIEmuxJEb0tFYmQ7QZF1VgvebXQa ea874eMpCIcDpMEfngXiq4N+4pCNf6x4Fv8B947KkpGVpOwbDZR9QgNoOC6oNarLJdCO z+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=T2pRhT17wl/YRwiNCVXRMv1KLzJ5zm9XMJ3bZoO1XMo=; b=eUJpZ6QMP1fHfy2jVx2P9W6CqE14NrNsyS80iRq4La8w88suxRcEjhFqukGBSQPOe6 M8QpfMl3eP4n53m1Ebj+vfI5kxJodLbmkcyscubjm48YJ3ujJhhDQ+U6UlBiBLdqpR2j GohQJiE4H4UtlC8j8lsUB3e2/7dvlJ3y1li3jwUudVi2JcF9Y5neWhqIG6d3hsUsJwPc fFpHPSqVGxw+pR0RourGDt2wtL6qiqFqU2XAVsbnXzpCnEkh9Q4/XYZrwIEi9kOnlQyW tJPvb3Kvon8NJvprHxW54fVubj2VgMv3J1IGUqMu/ZxT3JrfYCpRXM71WHaGbFsvZpqa HMqg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q127si1125586pga.326.2018.04.17.10.11.09; Tue, 17 Apr 2018 10:11:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753760AbeDQRIG (ORCPT + 99 others); Tue, 17 Apr 2018 13:08:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60208 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659AbeDQQAq (ORCPT ); Tue, 17 Apr 2018 12:00:46 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 10C07D92; Tue, 17 Apr 2018 16:00:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+65a84dde0214b0387ccd@syzkaller.appspotmail.com, Jason Wang , Stefan Hajnoczi , "Michael S. Tsirkin" , "David S. Miller" Subject: [PATCH 4.16 04/68] vhost: fix vhost_vq_access_ok() log check Date: Tue, 17 Apr 2018 17:57:17 +0200 Message-Id: <20180417155749.519346445@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155749.341779147@linuxfoundation.org> References: <20180417155749.341779147@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stefan Hajnoczi [ Upstream commit d14d2b78090c7de0557362b26a4ca591aa6a9faa ] 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 Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vhost.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1244,10 +1244,12 @@ static int vq_log_access_ok(struct vhost /* 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); }