Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp834018ybi; Fri, 12 Jul 2019 05:25:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWK5CxvxcwMDaX4LU1yTOSxoZHfWfEq5UKqqhsJsXaAEXT28UrE6zlZ27gZT4i1QPXyvuq X-Received: by 2002:a63:6f8f:: with SMTP id k137mr10564596pgc.90.1562934330766; Fri, 12 Jul 2019 05:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934330; cv=none; d=google.com; s=arc-20160816; b=dVOGOXLY7lxn8ZwF5mQlygiMLldgRwPkfBiDOamx0Zs/HTY/sa5lehqvKo8YI1nyH/ x/xE130ksg7nu0PUDD7Di6lvnkNPdDf6ZDZlxFOGoOxTR/1r07vIoJnALQMHlScsPxxu zPRItT+v64u+8v6UVMsyL1b9KvCZVk1kk00dCjYlRuBBkXxNoOSK6hTghAkUIrgQmJZW j3pIX8N0ldgtHR4LyOYi+1PU2jaPhV7HUgE2HEwM+9h2BYEaVm0qwvmEhUjFLl+6QigC qAZpt0XyCs5x1fLn4Pfo9iF/bVH/QXG5K/GkQeGHYi3VB4h3dNEghnY41iCHuqLEZaRF 6aIw== 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:dkim-signature; bh=8ALkOKwy/nNhmHJfh5rsC3+hQvyCDQlGfe2+QzaEoPk=; b=JhHmveAZXFNLUiNrh3/yYw4p/Ov/3f9fDrsoqU+JFYdZEMBbIH+iLvS3uT7tlnx6p7 bd60nxt8KFfvmA7xsH0tDcbRPG91VDsJETKlqFVS+5qNtxRSA2YJYEf7WKxjROGOPF6h XE6fVhU7NTH2UurL49Q0Qz1I6BULv44z3eOvoBT/w8sZ9rSdbJdZEgqleGmFqzsout5X WG0nLz9vduif6nOCblZFKuFewD1bH48SJ7UCKjtLHngifXbRgcP0ojIZUVe02i1rHItK Je5BRQeycW2tlVnBg0k+bQ/Y00nNi/VZUxHuXkiYrRA7JVTVURB2bFujUNescuR6qiTe PTwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jTqI2qMi; 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 b28si8732765pfp.92.2019.07.12.05.25.15; Fri, 12 Jul 2019 05:25:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=jTqI2qMi; 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 S1727843AbfGLMXD (ORCPT + 99 others); Fri, 12 Jul 2019 08:23:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:58196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727839AbfGLMXC (ORCPT ); Fri, 12 Jul 2019 08:23:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B616E21670; Fri, 12 Jul 2019 12:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934181; bh=jIGF3tGsUd16gUWn6GBhxSJaxsz9nGgZeR+K3j5UKXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jTqI2qMiYmi1LdotQD+nfmCq5vobwtwI+FKxWDJJIsAN7VhGUh/mcLisMBltB8gmn 0ymuUuATPBCXvkqTzPO759RoegR0csv7ADvKrvWDG9r26Mdsfila7NK8zBF3qk2Px7 Xux5wnRaLLeJLqBsNJ4dj+VslLVDvzwTGdKbHAGw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dianzhang Chen , Thomas Gleixner , bp@alien8.de, hpa@zytor.com Subject: [PATCH 4.19 63/91] x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg() Date: Fri, 12 Jul 2019 14:19:06 +0200 Message-Id: <20190712121625.214928205@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121621.422224300@linuxfoundation.org> References: <20190712121621.422224300@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Dianzhang Chen commit 31a2fbb390fee4231281b939e1979e810f945415 upstream. The index to access the threads ptrace_bps is controlled by userspace via syscall: sys_ptrace(), hence leading to a potential exploitation of the Spectre variant 1 vulnerability. The index can be controlled from: ptrace -> arch_ptrace -> ptrace_get_debugreg. Fix this by sanitizing the user supplied index before using it access thread->ptrace_bps. Signed-off-by: Dianzhang Chen Signed-off-by: Thomas Gleixner Cc: bp@alien8.de Cc: hpa@zytor.com Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1561476617-3759-1-git-send-email-dianzhangchen0@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/ptrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -651,9 +652,11 @@ static unsigned long ptrace_get_debugreg { struct thread_struct *thread = &tsk->thread; unsigned long val = 0; + int index = n; if (n < HBP_NUM) { - struct perf_event *bp = thread->ptrace_bps[n]; + index = array_index_nospec(index, HBP_NUM); + struct perf_event *bp = thread->ptrace_bps[index]; if (bp) val = bp->hw.info.address;