From patchwork Fri Oct 13 10:52:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 115751 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp581051qgn; Fri, 13 Oct 2017 03:52:58 -0700 (PDT) X-Received: by 10.159.234.3 with SMTP id be3mr1045880plb.5.1507891978602; Fri, 13 Oct 2017 03:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507891978; cv=none; d=google.com; s=arc-20160816; b=GoZxXXTk8veN9GsJnPNZCnyWwKuLF8uqIg3B8HHhSjrYOWhlYv4DGA62lGhaRw2h9w ufXjOBoKfM9Idwte29ynlv5tCgldwGgXq2Erklq04Srb/aP++bVJDFWAihSNxnR+pCTM /xXicYSSK3sA91xaX/4weWK1yeIqggj1ANfeCVEXR+xJhhH9d0YMh/tSsz49EEIjAs7D rMi7+LnkIpA9Sxo+AIcDDQCRmAhQ5EPgjmiqVYeN1TSmsfyqA2RBXYhGfZsuCpPZEGWR V97FxqUPtiRoYtYJiL/qW66T/WC6SNC/j82xQNhLOATxDAQsKM+JKUUH/J0pAW4c6b6R eNtg== 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=4erD49fNVn8pCRy6i+Q/2xrAZCPXgUudTB3Y8o3RQAM=; b=kMY96tDn6uLVlaDrTR9O0JIxHWbadJl+A9srLvVON0WPPH2IVYe7Ac/zb2qCWo6Eor oNYaX+Ru9ZmeTVEQtIWwrfIMK7IMAVhdC+c9f0x89aVoOUUmVcGA1iU2a9yUh0LfgmZe WmdfnCqODdYJwWp8Mv8/9SmiZA2iwCD0388xkld027ZNt0gvFwZjTU68VuNKawdVtXjh U7dwL4v+hiyv+naBL4SOya3Wcs+pgf8xdKIKwwaoEcL+rm7ovX9fiXHbCcQTvkpmOBQ9 fGXfvr19VMpH7Kie1oef+e8NtSc+JtZ044HZG6qex8lmbXrSXsF8YTY+Srvc4e1y+EZO jfsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y6UdtGIN; 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 1si481549plu.200.2017.10.13.03.52.58; Fri, 13 Oct 2017 03:52:58 -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=Y6UdtGIN; 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 S1751619AbdJMKw5 (ORCPT + 9 others); Fri, 13 Oct 2017 06:52:57 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:47425 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751468AbdJMKw4 (ORCPT ); Fri, 13 Oct 2017 06:52:56 -0400 Received: by mail-wm0-f51.google.com with SMTP id t69so20410937wmt.2 for ; Fri, 13 Oct 2017 03:52:55 -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=4erD49fNVn8pCRy6i+Q/2xrAZCPXgUudTB3Y8o3RQAM=; b=Y6UdtGINN5w9g+R9zccmzgVWoUzEToVXjqoy9U/X/ZmzQs58P+WXd6w6o3LyS4KcLx iIi/2YZ4RITdydEK/SpQWEluJvUvt/r8Q80VNfWA7uPtdq36nfMVQzbLAa8DALzxG/ZP jrfrcCu5MU+QXHof6iBYgfCWy83KbY6WNRXBk= 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=4erD49fNVn8pCRy6i+Q/2xrAZCPXgUudTB3Y8o3RQAM=; b=BPGKEo3fYxhYzuQ5eCu1D8GDDBkxZ526fgLWqnyzX2qwBI1rkrUapu9Bpuy+59p8NV vcWBcVnnF1CvGdVQA8gqQMpE4yzJG8sEeNzBZttoKG8pmYgfqH7FxdoADvsm3I9w/Ec4 w/6Vl/d7VbfL06tr97ZHfRJfl7sJcby0PtBveoYHjGChru0o5SlKwzHAt/O5JEEgwvHJ 9T36GbhSmlLqeeU7Jvblr2Oi11m1hqobBR+MwG4ysU603aAjBqLoSkCLZiEqCtMWoHj4 SvsMcE1R0Xsw55SuNS+EqPB1n2vzuADVATJeb7yu4Ih3Uj6cQudH2nmmgYH03CaUaDRX cteA== X-Gm-Message-State: AMCzsaWGdxzuaBQUeg8m/vFblc0hkJfRZhOZjKvr1kyvyOiSEnkv3END 2WvnxL3nBYU6MVMkVV+6Q3x7HA== X-Google-Smtp-Source: AOwi7QClWFeqQK46oumfoLZkIfRckAJ8lTUuUFbLxWxmj5Aym/XH+GdPjkBO9ehc50W+MBAROug8Tw== X-Received: by 10.80.151.22 with SMTP id c22mr1592828edb.247.1507891975205; Fri, 13 Oct 2017 03:52:55 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id n7sm618242edl.12.2017.10.13.03.52.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Oct 2017 03:52:54 -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] KVM: arm64: its: Fix missing dynamic allocation check in scan_its_table Date: Fri, 13 Oct 2017 12:52:59 +0200 Message-Id: <20171013105259.9728-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 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) -- 2.9.0 Acked-by: Marc Zyngier diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index f51c1e1..555f42f 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -176,6 +176,7 @@ static const struct vgic_its_abi its_table_abi_versions[] = { }; #define NR_ITS_ABIS ARRAY_SIZE(its_table_abi_versions) +#define MAX_ENTRY_SIZE 8 /* Max Entry size across all ABI versions */ inline const struct vgic_its_abi *vgic_its_get_abi(struct vgic_its *its) { @@ -1801,37 +1802,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[MAX_ENTRY_SIZE]; int ret; + memset(entry, 0, MAX_ENTRY_SIZE); + 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; } /**