From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0135.outbound.protection.outlook.com ([104.47.36.135]:30237 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726361AbeIGFPk (ORCPT ); Fri, 7 Sep 2018 01:15:40 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Mark Rutland , Catalin Marinas , Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL 4.18 64/88] arm64: fix possible spectre-v1 write in ptrace_hbp_set_event() Date: Fri, 7 Sep 2018 00:36:38 +0000 Message-ID: <20180907003547.57567-64-alexander.levin@microsoft.com> References: <20180907003547.57567-1-alexander.levin@microsoft.com> In-Reply-To: <20180907003547.57567-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: 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 --- arch/arm64/kernel/ptrace.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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_typ= e, =20 switch (note_type) { case NT_ARM_HW_BREAK: - if (idx < ARM_MAX_BRP) { - tsk->thread.debug.hbp_break[idx] =3D bp; - err =3D 0; - } + if (idx >=3D ARM_MAX_BRP) + goto out; + idx =3D array_index_nospec(idx, ARM_MAX_BRP); + tsk->thread.debug.hbp_break[idx] =3D bp; + err =3D 0; break; case NT_ARM_HW_WATCH: - if (idx < ARM_MAX_WRP) { - tsk->thread.debug.hbp_watch[idx] =3D bp; - err =3D 0; - } + if (idx >=3D ARM_MAX_WRP) + goto out; + idx =3D array_index_nospec(idx, ARM_MAX_WRP); + tsk->thread.debug.hbp_watch[idx] =3D bp; + err =3D 0; break; } =20 +out: return err; } =20 --=20 2.17.1