From patchwork Fri Jun 29 18:46:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10497237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 52CB060230 for ; Fri, 29 Jun 2018 18:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FF152984A for ; Fri, 29 Jun 2018 18:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 336A42984C; Fri, 29 Jun 2018 18:47:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C50B22982A for ; Fri, 29 Jun 2018 18:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Wx1tNRH36o5aFVOd8u91zEwYAW+qtaYGF/lOfDjceTw=; b=rEyva+xB6Kz+rw 4cfiNYZRwBTDRxoGHqQZIWlPJ1InNIg0bdBnarlWRv6rnbh+qZpDOa9aUBo6SxsrCQiIiyvs8EaEb fOFCrz6RYx+g1ewuQAXezVoC3HpCscWIBF2RfNi1C1aTiG49zdts2GaVOocmOnoMz51SWCs6k3loX ww0RXpESkut8fMpjnAt3kFjuv2khdXIZJVn04a+RJ4goL/bB4vz4/BkepT7l3kCnbrcqamjWNfoUR H2XL1lSZZmN64Loph+unTfj6jGsbfsoLWYWF3WMOf4bdIK/JPKOGo3s7zdt4bxGp600KDugHhl/We N6CXwyRHr/3PjB0TqIRA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYyQK-0003gs-HR; Fri, 29 Jun 2018 18:47:12 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYyPf-0003C2-Cy for linux-arm-kernel@lists.infradead.org; Fri, 29 Jun 2018 18:46:33 +0000 Received: by mail-pg0-x243.google.com with SMTP id q14-v6so4344833pgt.13 for ; Fri, 29 Jun 2018 11:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=Ww7LnS+ED+uus7+k/xyuZ455j+pUcX68Gc3gh1nhoHk=; b=iPDwYqFxueQtfo5ez5Bw+de+S/L1Rn5HbBVLEsH9oknUqVdFrcqo/UITgPagMq8sMQ xOlbKT0OSYYL2iXKaeCBx2D5mij/X7KEA8mwAlTqTCKj2AwgTyxTFDsC5duglO02vBDo 1widtyxGF1WS4IXfy3pqKkWaRrfwbHr9YiPRY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Ww7LnS+ED+uus7+k/xyuZ455j+pUcX68Gc3gh1nhoHk=; b=rAjbraQ0S3XE86j9dmeADWN9AroNuV8TgyUNhDt0Thz0cwFx8qC3dOU7mG3/KOsoom XhNxiYsgiOXXBVSlb4Bgj9jSePqiuXxLsGPV3gk9Yp34ksu2NKL6pKBRDgJZMLyAXd87 uYTt/nxsyKtvyT/yJdXyukKV/uVbMT3T4+Nv1N8wbzl9XTJMSBMdoZ7efPPtplxzKyrP bkk/pcCn5Tcp7BbgPeznQW+epbhjDyEhRIbOrFgs0R1vuKWGu6Mpm5VySir8eUIzqR8r 9iyFuH3KNCnNNufjmRonAphX7hTqRC70YQg7F2l4mytmEzAvllgld/GQj7tLcx9YAgnp SfMg== X-Gm-Message-State: APt69E0GGtQUQD5AQe5pc2Q4U8loXfXcDGH5uWNWqcnzjwi3barwIcRS ix/1yabErrh1FqxPsWbIlJY5rA== X-Google-Smtp-Source: ADUXVKK6cd20yzntVlakGt+Vs98VhGZCsN0bqc83Q8XzlqPtcdRYablIVEr7GS5Ja7CoI9Heq34A+g== X-Received: by 2002:a63:24c4:: with SMTP id k187-v6mr13485065pgk.434.1530297980578; Fri, 29 Jun 2018 11:46:20 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id q188-v6sm3435240pfb.141.2018.06.29.11.46.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jun 2018 11:46:19 -0700 (PDT) Date: Fri, 29 Jun 2018 11:46:18 -0700 From: Kees Cook To: Christoffer Dall Subject: [PATCH] KVM: arm64: vgic-its: Remove VLA usage Message-ID: <20180629184618.GA37364@beast> MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180629_114631_524260_6D6C3A72 X-CRM114-Status: GOOD ( 14.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Andre Przywara , linux-kernel@vger.kernel.org, Eric Auger , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In the quest to remove all stack VLA usage from the kernel[1], this switches to using a maximum size and adds sanity checks. Additionally cleans up some of the int-vs-u32 usage and adds additional bounds checking. As it currently stands, this will always be 8 bytes until the ABI changes. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Christoffer Dall Cc: Marc Zyngier Cc: Eric Auger Cc: Andre Przywara Cc: linux-arm-kernel@lists.infradead.org Cc: kvmarm@lists.cs.columbia.edu Signed-off-by: Kees Cook --- virt/kvm/arm/vgic/vgic-its.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 4ed79c939fb4..3143fc047fcf 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -168,8 +168,14 @@ struct vgic_its_abi { int (*commit)(struct vgic_its *its); }; +#define ABI_0_ESZ 8 +#define ESZ_MAX ABI_0_ESZ + static const struct vgic_its_abi its_table_abi_versions[] = { - [0] = {.cte_esz = 8, .dte_esz = 8, .ite_esz = 8, + [0] = { + .cte_esz = ABI_0_ESZ, + .dte_esz = ABI_0_ESZ, + .ite_esz = ABI_0_ESZ, .save_tables = vgic_its_save_tables_v0, .restore_tables = vgic_its_restore_tables_v0, .commit = vgic_its_commit_v0, @@ -180,10 +186,12 @@ static const struct vgic_its_abi its_table_abi_versions[] = { inline const struct vgic_its_abi *vgic_its_get_abi(struct vgic_its *its) { + if (WARN_ON(its->abi_rev >= NR_ITS_ABIS)) + return NULL; return &its_table_abi_versions[its->abi_rev]; } -int vgic_its_set_abi(struct vgic_its *its, int rev) +static int vgic_its_set_abi(struct vgic_its *its, u32 rev) { const struct vgic_its_abi *abi; @@ -1881,16 +1889,19 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *entry, * Return: < 0 on error, 0 if last element was identified, 1 otherwise * (the last element may not be found on second level tables) */ -static int scan_its_table(struct vgic_its *its, gpa_t base, int size, int esz, +static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, int start_id, entry_fn_t fn, void *opaque) { struct kvm *kvm = its->dev->kvm; unsigned long len = size; int id = start_id; gpa_t gpa = base; - char entry[esz]; + char entry[ESZ_MAX]; int ret; + if (WARN_ON(esz > ESZ_MAX)) + return -EINVAL; + memset(entry, 0, esz); while (len > 0) {