Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2500751imm; Mon, 24 Sep 2018 05:32:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaDAJMp04pWPamNMLtp5wWeIQKcd75Fg5HtzzyomGnRMRAvtOmOl1z9hxYSNfPKxH58I/OJ X-Received: by 2002:a62:9c17:: with SMTP id f23-v6mr10173378pfe.209.1537792341380; Mon, 24 Sep 2018 05:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792341; cv=none; d=google.com; s=arc-20160816; b=ZUfbbSdnPt3XPni6vWpd0I+JFv6hkQ+jJDIkfk5WArFr4SyfuG/ClxAI4wDtGGB3tC 19UF4H8Vv/Z5P1jmU6RLA+GQkVxq+D0PqWOaFzlsQZYqOmZFku4pGAB9ePZRCmqHfoWr sRjtSJoztM61BCq1sn4PSjbXHjdi7Y8yQ5awe5gVHcHoUZACLFiLOXR1wcMe0dFQyGdM JKncyfnZ8l4+KlBIsFMEMsiBc44v2GduTb9YV4XMwrgRzKoR1XJpFnyfLQJxRm+1Gekc LHZUYQuzLTH/VWBFWLm8lTUFGfkMgskvQTsHnKitr2Df9HLMPKha45a90COBxZwskQ28 0Lag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=DJ74j/gPuwDrh7eGCYlKztxJKoUkrEavjHfcSpizuKw=; b=a6pv3G0Y5sHiOTvEkRHTumVl4Ml7r63d5/we2RQWZrX1rgTXgycqZI8jWZ/tTbQKX+ CAkfpN4pZM8zSxTmxXPMGKuC0F3SqRa6CdqG4q4Oqe2BH+Wq3CvvXXzRJU01ljcH0zNX glqMfGMbCRv6JgMiz5Ob4jcDO5tsAwO9pgPYG6lujusAqKiPQQHjFpwczeLxBNB/DhAy gSS8fvVljJumbamSmm2oLBWxq7yLHR0qikHE1gkJn44jaRqjJKCVxkLyKejeLex3xuPC mcsLNhjRoneBW2dH42dAkefOQ65AgyytYPpQ9CN1EmcPEHoe36gTl2l0ye25QivGf20p ehZw== 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 m21-v6si38025132pgd.48.2018.09.24.05.32.05; Mon, 24 Sep 2018 05:32:21 -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 S2387991AbeIXSdH (ORCPT + 99 others); Mon, 24 Sep 2018 14:33:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57936 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730258AbeIXSdH (ORCPT ); Mon, 24 Sep 2018 14:33:07 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EC8DC1098; Mon, 24 Sep 2018 12:31:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Catalin Marinas , Will Deacon , Sasha Levin Subject: [PATCH 4.18 073/235] arm64: fix possible spectre-v1 write in ptrace_hbp_set_event() Date: Mon, 24 Sep 2018 13:50:59 +0200 Message-Id: <20180924113112.513448138@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Rutland [ Upstream commit 14d6e289a89780377f8bb09de8926d3c62d763cd ] 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 Signed-off-by: Will Deacon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/ptrace.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -277,19 +277,22 @@ static int ptrace_hbp_set_event(unsigned 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; }