From patchwork Tue Jul 10 18:01:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141649 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4204682ljj; Tue, 10 Jul 2018 11:19:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeJ2RK82n7xciua0Y9fyH+Ub8Ye+cT8bd8QC2GI9jh1JB4Im4CHm3/BB1H6+FMzuoSxHqLL X-Received: by 2002:a17:902:5a3:: with SMTP id f32-v6mr25405312plf.109.1531246773300; Tue, 10 Jul 2018 11:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531246773; cv=none; d=google.com; s=arc-20160816; b=h3nGdtSsOJASYtdvrA2+Oq54QqoiEWCALMgDGyMa3OPCBHTPP1r+5hqSTrvm8VlgAX tYEuJCdreuBkFjaGbuWYA0VyXaBo2TZuZeL+2HAky1kXfEe8c1DuHUIG8FH+blr4d8QO z+QYOmkjnb8xU4DM2YDuLPmHzz6T2VQgjoU1RoTkbQvuGmJ3sR1A3XH0KrzRtQYldx0M CEL2EBTTEn8RHDEMz4+8Giz0vnVQ8+dGtaDu3FIoUl/+mkEyfSQtO+o9lvOUtDDCjxq1 Y0trsukWXXl755uFiuVuizlAfMZCJ/cv576E8US7IsgyP+r+GXod+uU6VuNf9ACkGxJ4 9mSw== 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=Izf+yqSKhk3VwNhjjGRLH225Uc9k8ZVycmCx1bl0g6c=; b=th2ZLmTxCp5XYi6NxqNDfFAsC7kIcSo8Sqh382sKJT8rdIy40UJFu2CrC8whjaNCgD ncFjacyOUHwPHsx/3jzaQ/bwUYBvDeI+6SgJK0s9qRi9cK7rX4+xwjnD+oFi00zl8VNq BAnI8hhEU45QMonWwOPqMQs8Tfx1NBYTwda2DGzvIt2BV1WDzAWj8+nBZUcNr9KmCPnr 0AVOLku6KPupLmv9Cl/nIq60wzauF1Q0ysXz5IPs9cnnZ495ie9+3OKWNrp7xgBIe423 rJpp3S4y3aZC3zazWpYjl1TL/E2GVIfyDFn1KzMuXwnMxGcyHFs0XYwUgzBcnJQafbpS jTEw== 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 t22-v6si16933079plo.263.2018.07.10.11.19.33; Tue, 10 Jul 2018 11:19:33 -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 S1732388AbeGJSSh (ORCPT + 18 others); Tue, 10 Jul 2018 14:18:37 -0400 Received: from foss.arm.com ([217.140.101.70]:51614 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732200AbeGJSSh (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 00AD01BB2; Tue, 10 Jul 2018 11:01:32 -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 747493F589; Tue, 10 Jul 2018 11:01:30 -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 1/2] arm64: fix possible spectre-v1 write in ptrace_hbp_set_event() Date: Tue, 10 Jul 2018 19:01:22 +0100 Message-Id: <20180710180123.56461-2-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 idx. Sanitize idx when using it as an array index, to inhibit the potential spectre-v1 write gadget. Found by smatch. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/ptrace.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 5c338ce5a7fa..db5440339ab3 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -277,19 +277,22 @@ static int ptrace_hbp_set_event(unsigned int note_type, switch (note_type) { case NT_ARM_HW_BREAK: - if (idx < ARM_MAX_BRP) { - tsk->thread.debug.hbp_break[idx] = bp; - err = 0; - } + if (idx >= ARM_MAX_BRP) + goto out; + idx = array_index_nospec(idx, ARM_MAX_BRP); + tsk->thread.debug.hbp_break[idx] = bp; + err = 0; break; case NT_ARM_HW_WATCH: - if (idx < ARM_MAX_WRP) { - tsk->thread.debug.hbp_watch[idx] = bp; - err = 0; - } + if (idx >= ARM_MAX_WRP) + goto out; + idx = array_index_nospec(idx, ARM_MAX_WRP); + tsk->thread.debug.hbp_watch[idx] = bp; + err = 0; break; } +out: return err; } 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; }