Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp834263imj; Fri, 15 Feb 2019 07:34:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4AOudgpF7+j6iATLu2+71ScSNthezZc1jUBxy6ImyY2Xm4M8Nz8PIeOjr7yXn1UrzWb+p X-Received: by 2002:a17:902:2b8a:: with SMTP id l10mr10324360plb.70.1550244881385; Fri, 15 Feb 2019 07:34:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550244881; cv=none; d=google.com; s=arc-20160816; b=R03K2KOu0jhYTntyraGE2wbBd8Z4hH47FeT2jfbKGzYkrO6mn7hmet19NeszS0wIgc mQPv6Virq1eHhaP0fhBjlA1FoXfH8bqpmLwx5Rtnd1jA67kMHhg2cuiL/WlVJVMtFTnd y59JuI2c0KISJlgMoIZxBEzUrSckCRrjFeo1YQUXISCp4QieQ5GguWJHbAl2NQx2NCn8 plLdZSlcgWQNqYV4FLQEQIaWI9jSVo2w6PLaNkxtp0NT8a7xsq9Ivbfl56G6jBR6EqpP snAlTd411lF3UxSTwvxjDT9PnKcKJodHofQdS77R1/muResIXADen+h5ikwTl9OAuXLq 9DHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=zpwq7oM1Rb+OhGvcOLStcRAosoJCIn5WpinWWOxQf/o=; b=Zs5VimGNQnqVX4lHBmpPj745EBGNBW7/ma5R/TijFbTN+6grJYCbUr5htYteMWhqYk AUsznUhqkqI1Wj6fWDVWH/pPIPedv25L6kOQL8rCUkfbPNMLyBBLSHB37f5ssllNdH4G bE9Zuhl2o8b0wG7oFiazWUCrEU1et4RUpHhMlNUNcG4/AxSLVY92UGbzUR0xdH81H8ZH 5imPS8Yaj2ZGRrUV2EDIz0vzqBrYcOJu4M5IxvMyGVa63pdfsYixKAQSzhnZe1t43HQW 63AFwoQ4QV/nE9jurXUSe7zCZhbbbuJCUXQULBLJaYFRnnfI4F6P7UbICCoBpk9RuqlM BA0Q== 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 x7si5340826pgr.149.2019.02.15.07.34.24; Fri, 15 Feb 2019 07:34:41 -0800 (PST) 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 S2403806AbfBOHxb (ORCPT + 99 others); Fri, 15 Feb 2019 02:53:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56896 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbfBOHxb (ORCPT ); Fri, 15 Feb 2019 02:53:31 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C899414409B; Fri, 15 Feb 2019 07:53:30 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-183.pek2.redhat.com [10.72.12.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5907A5D9C6; Fri, 15 Feb 2019 07:53:26 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stephen@networkplumber.org Subject: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used() Date: Fri, 15 Feb 2019 15:53:24 +0800 Message-Id: <20190215075324.18891-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Feb 2019 07:53:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When fail, translate_desc() returns negative value, otherwise the number of iovs. So we should fail when the return value is negative instead of a blindly check against zero. Reported-by: Stephen Hemminger Fixes: cc5e71075947 ("vhost: log dirty page correctly") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 24a129fcdd61..a2e5dc7716e2 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1788,7 +1788,7 @@ static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len) ret = translate_desc(vq, (uintptr_t)vq->used + used_offset, len, iov, 64, VHOST_ACCESS_WO); - if (ret) + if (ret < 0) return ret; for (i = 0; i < ret; i++) { -- 2.17.1