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; }