From patchwork Fri Oct 13 13:17:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 115770 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp722728qgn; Fri, 13 Oct 2017 06:17:38 -0700 (PDT) X-Received: by 10.159.206.199 with SMTP id x7mr1406144plo.342.1507900658111; Fri, 13 Oct 2017 06:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507900658; cv=none; d=google.com; s=arc-20160816; b=sPiNVKbteAjX24wsBHGz472xXlfJbOCp77kOFA+WaMRdjSubQuJX+0N6hs/NjaLQNZ tM5zBcP3rhyNypi+5P9PpwassZZdBH+BQeTtHox7DnO9gs6F1h28kOQuCh88GCi8Dat4 hZYnRdb02rDk6bPjuC+08luoL1oFdJBSZM6smJO5pJ2y6FZugNWN9p3nkLfGBjJKhPBV xyaz5yC3ocQ9pqADJHgxutZuu165UUByq5mykQJUuO37JjhjuC7Oz9V/YDkknr9APKX9 VYviAUwiI/mINGE9quvRxXdCo25t6SIsj8JxVM3TJZ45dAcpcEADBbE3/BpnowpuObax a3Fg== 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 :dkim-signature:arc-authentication-results; bh=uiyKC+vbq8ciVaK2vS03iL6PXdCc6d1J65vT9wthQGg=; b=XTxWtEApT7Tu9DK8rBMJwQYx8YG5ZcgQqcDOCpaujLSvNzkDY7Qj+5ijRVi7wLM+WM qyjHO47ZWlcpZP7LNu3Ngx4rggO/CY7Zc07viMojpKWpfJDy5zGWkm/0t37ua76ngFNl Zsov7FAMJFuT1fTppF1DB0PX53uA3edBda6pj4G8Agf7YyenESBO5OdYsiVrN2PejMGJ hgHUl7+8zqPYaOxL2thuaDbo/nRzNROVAYJ9ezHZBINHwWNBHhxrUvRqYCjca+lJtcMv 2m5LgDIaxDpyWwWVAtpEwW9NjEN5oiZOrQ9TemulSgtG5fYYrHnI6ER41AHcjixsARmp Mw+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S2XicngT; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m16si565446pgn.520.2017.10.13.06.17.37; Fri, 13 Oct 2017 06:17:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S2XicngT; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbdJMNRf (ORCPT + 9 others); Fri, 13 Oct 2017 09:17:35 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:54086 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753446AbdJMNRe (ORCPT ); Fri, 13 Oct 2017 09:17:34 -0400 Received: by mail-wm0-f45.google.com with SMTP id q132so21745438wmd.2 for ; Fri, 13 Oct 2017 06:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=uiyKC+vbq8ciVaK2vS03iL6PXdCc6d1J65vT9wthQGg=; b=S2XicngTdvo66H/F3M77v5HKu9xVyF9RdeffC5JOiM8kZaQkTr/vKH4ELZjCw2yhE0 kYqTXI1EKziTrdRcpIJgFzEDWZnwgN1HdPm+4A+UKasff4Aonx3UtXRZobtte1DDXUNT wKpRqce9lbrQHlzYjsId0Xkwhe/pIIZZgDgpg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uiyKC+vbq8ciVaK2vS03iL6PXdCc6d1J65vT9wthQGg=; b=YJhL3Zy1cQNqcuxVVrnHMpR+akM5pPgnMKcnzwnGdwr05upb9j+qc6qUAvTZERq11U vUsDCVK1sI1ky9K+lZhdXz6wnIKrzWM40yB0EgMbharFjzLd6mPOrYTI55o6RpSjtUkB CgwMiaUZPaYE9q1kJUcwiDJdmRiZzTvm/KiB/4vgOmZ0LWgXwefblOigC40fs7l81ItC p43DSuccZ7our5HE0GnU6h+6bv67NWIPQiLTcj5X8n6Ck1sW8zE/iE5vQECWLuP+LfHC NMazyf3Rx0Xe2XCsXETTgDlppqG+Fyt7iLYwm9lQXWHtRsQm6FT9mSeYW1zIOQxhlV/U hWFw== X-Gm-Message-State: AMCzsaXxF1IBpXM3LVp8GDahTIz7/z9NJ+9182YVQQ2LhTyhEVZijxoV 2AwbMNnSoztX9UarAtU7gUL8IiEYM7Q= X-Google-Smtp-Source: AOwi7QCQrV9GFz0PxCJpJHBjM4pnXuWPSTesT7LdhmnQjvrKqk1UBnJKcBYVSnV89jntmV+sWAqZ1w== X-Received: by 10.80.128.133 with SMTP id 5mr2201176edb.114.1507900653266; Fri, 13 Oct 2017 06:17:33 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id i61sm801849edc.32.2017.10.13.06.17.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Oct 2017 06:17:32 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Andre Przywara , Christoffer Dall , stable@vger.kernel.org Subject: [PATCH v2] KVM: arm64: its: Fix missing dynamic allocation check in scan_its_table Date: Fri, 13 Oct 2017 15:17:34 +0200 Message-Id: <20171013131734.16485-1-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org We currently allocate an entry dynamically, but we never check if the allocation actually succeeded. We actually don't need a dynamic allocation, because we know the maximum size of an ITS table entry, so we can simply use an allocation on the stack. Cc: Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-its.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) -- 2.9.0 Reviewed-by: Marc Zyngier diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index f51c1e1..1d2668b 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1801,37 +1801,33 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *entry, static int scan_its_table(struct vgic_its *its, gpa_t base, int size, int esz, int start_id, entry_fn_t fn, void *opaque) { - void *entry = kzalloc(esz, GFP_KERNEL); struct kvm *kvm = its->dev->kvm; unsigned long len = size; int id = start_id; gpa_t gpa = base; + char entry[esz] int ret; + memset(entry, 0, esz); + while (len > 0) { int next_offset; size_t byte_offset; ret = kvm_read_guest(kvm, gpa, entry, esz); if (ret) - goto out; + return ret; next_offset = fn(its, id, entry, opaque); - if (next_offset <= 0) { - ret = next_offset; - goto out; - } + if (next_offset <= 0) + return next_offset; byte_offset = next_offset * esz; id += next_offset; gpa += byte_offset; len -= byte_offset; } - ret = 1; - -out: - kfree(entry); - return ret; + return 1; } /**