From patchwork Tue Jul 10 18:01:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141647 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4204252ljj; Tue, 10 Jul 2018 11:19:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeBkB0WowKe5uQ+y+mCYUje8GELHHJ3pGemt5t4h1re6yuuAyRYzhqotp5MWWPzn9AB8KNh X-Received: by 2002:a63:fd06:: with SMTP id d6-v6mr20620425pgh.348.1531246744162; Tue, 10 Jul 2018 11:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531246744; cv=none; d=google.com; s=arc-20160816; b=AXA0UTHOpxjaPYw1zOgEbqkLLfufd5Tb3/SIAvP7Msr2Qwvo/S4oB+Zk0mHAaD/rSO ytDwpvZNSLAK9dLy/xvP8ZEHY8v4MDqs1ALS6YRUhVgMmxefvPPKZfkLcM8HyGit0KCV vhgeAorTLTb2DZu+icpIq2Wynu/dpPRg03WnjI47zmFjKHpMSBi13fkK8+ld2TADBOtR XRsJiF5wpc0RCrJ9MZOQeeBbmvqRW6qZF1/xkiiDowPy2trv5Yp6isOxPurWytGuDWSV gkJBFOs3CO/9O+l3qLJPPGUZl4XLIUJcCZD4wTwzrKQcFwxv9Xl3YMG81BvzJCWcqVcx TfiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=doLt5b9a36wo4M2BUutMu2CYnzOt9SrSUL7TPEDERLI=; b=M4tTw+0P51VwqbX7ju9FEt/yvwUKLZYhuYjgK56HHQSvQcF6UK18b6SzwTkLJahL35 +rj+9pIBjOZjq8kQl8bz9tfWKhQVeZ0QvZxPj3wbOAVj0gnNTQg6QgxVcq3DaSITEUqQ 0vjwhHr+Qrse6dyHlqobIaf7VwiAPRrejGCx6lqOrNKBmNkTtcwCyST0Gb1DEIz94M+q jLCW0F+uIiPxv027hcL5iRdY0cJ0/+6Fc/ZrQCRKltNAfjx1SIP2OOn3YF+oVYgO9ZVf OXJ+C1TmWlBLBhkVrHuv7lUuAGHZKG1EhpcD60lThMC3bDSzkNo+1k1V/gBoRpsAHGBd +cpQ== 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 i184-v6si16542816pge.405.2018.07.10.11.19.03; Tue, 10 Jul 2018 11:19:04 -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 S1732414AbeGJSSh (ORCPT + 18 others); Tue, 10 Jul 2018 14:18:37 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51612 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732372AbeGJSSh (ORCPT ); Tue, 10 Jul 2018 14:18:37 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 42D081BC0; Tue, 10 Jul 2018 11:01:34 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B6DC03F589; Tue, 10 Jul 2018 11:01:32 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, christoffer.dall@arm.com, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, mark.rutland@arm.com, will.deacon@arm.com Subject: [PATCH 2/2] KVM: arm/arm64: vgic: fix possible spectre-v1 write in vgic_mmio_write_apr() Date: Tue, 10 Jul 2018 19:01:23 +0100 Message-Id: <20180710180123.56461-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180710180123.56461-1-mark.rutland@arm.com> References: <20180710180123.56461-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible for userspace to control n. Sanitize n when using it as an array index, to inhibit the potential spectre-v1 write gadget. Note that while it appears that n must be bound to the interval [0,3] due to the way it is extracted from addr, we cannot guarantee that compiler transformations (and/or future refactoring) will ensure this is the case, and given this is a slow path it's better to always perform the masking. Found by smatch. Signed-off-by: Mark Rutland Cc: Christoffer Dall Cc: Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu --- virt/kvm/arm/vgic/vgic-mmio-v2.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.11.0 diff --git a/virt/kvm/arm/vgic/vgic-mmio-v2.c b/virt/kvm/arm/vgic/vgic-mmio-v2.c index ffc587bf4742..64e571cc02df 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v2.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v2.c @@ -352,6 +352,9 @@ static void vgic_mmio_write_apr(struct kvm_vcpu *vcpu, if (n > vgic_v3_max_apr_idx(vcpu)) return; + + n = array_index_nospec(n, 4); + /* GICv3 only uses ICH_AP1Rn for memory mapped (GICv2) guests */ vgicv3->vgic_ap1r[n] = val; }