From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E7D2C76186 for ; Thu, 18 Jul 2019 03:16:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D2AC21849 for ; Thu, 18 Jul 2019 03:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419817; bh=tF80hbKqnnsdHN8PLM6yB9syN274WwkXVuBEAAZ5IHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1bIB8QJyonckgizVppEwBeaqL6t5/GcccBt2Mv7Fyd2GCHe+8kNp8aEQ8DLBPDZqm o1gWFC1QL/PLlqiJvsyxhP5Fwwwn/NtGP7jCXn/mTHTGs8PajbLDuKfQEGvwOemqco JM0Sm6YS0+FM3/JCb1+Y3OH6A+T/+yaIgsYvcQfc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391481AbfGRDPA (ORCPT ); Wed, 17 Jul 2019 23:15:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:51540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391900AbfGRDO6 (ORCPT ); Wed, 17 Jul 2019 23:14:58 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 90A6521851; Thu, 18 Jul 2019 03:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419697; bh=tF80hbKqnnsdHN8PLM6yB9syN274WwkXVuBEAAZ5IHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xwWK1609RXrXu5v+7800EuCPlozGxlDfvXfEQ5vDQsPtSIgzi0TmJipisWTG523ge Akvt4tWMJYKXHN8em7Z4u8xt7aDsuyhezFVVO34WzFHw0RbpRmWN+oXKW+y+dLNZx3 SpCNBT1xVmoipZp1CDcu7fU/puDHwkHco1k27Aa0= 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.4 13/40] x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg() Date: Thu, 18 Jul 2019 12:02:09 +0900 Message-Id: <20190718030043.255008862@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030039.676518610@linuxfoundation.org> References: <20190718030039.676518610@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -697,9 +698,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]; + struct perf_event *bp = thread->ptrace_bps[index]; + index = array_index_nospec(index, HBP_NUM); if (bp) val = bp->hw.info.address;