Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1697356ybi; Wed, 17 Jul 2019 20:19:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxX3E7m//Ufw1ytLGcyuEkzLalI5l76jD2krBLuuF/xRNdstG4RjK8Ly6rV/1d8KkHIkfJq X-Received: by 2002:a17:902:b206:: with SMTP id t6mr48108764plr.195.1563419947863; Wed, 17 Jul 2019 20:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563419947; cv=none; d=google.com; s=arc-20160816; b=Z8J/B2EJhch2iJXJlCIrhgBy74UruaiWgwqgkcTqEHU6df1mP0hh9gIsFU0xnsu8nF RcODY9x/UPubwK8Zo/+SPTFsUFyAOqq7PVR07H7MNmo6QoJlC0lDiIEZJhKGDFwCKBVy nFv5iCrOZ68D9aGuSehKNeGXtzFFFOF6/qs8GprlAx+hjQu5IIsPina4TY/LjmWl2+kD S5EUpd4idoTTZBUz7Z+Z1GGS9r7tPRgnqqF7orHYU8UpIRz6/wTgyvftKIc5dY14r3J1 aBiL/JJKHgbszRpxv7gmaKcPSv7+2hFkB3fYe+YVZKdCa/5DPA/TG4fvA4zR9zpllUYy 3PaA== 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=fVVQIJlCsC9xBH3ssoGqi/VUjXSVYszptY84EyD0NaY=; b=ty7nmYOQQFVGfM6D4rQidIGNw1V65UV1wGXhsBH+HXExpmUUe2P+Ds6MYKFPePvtT7 AQ06V/dxaNN7XI3Rq7e1iN9xTUaHRvRCjmUsXrtHzaGjnKj/9QOXSJPxk1z7ElIM2VwF CKGpRALvCaC07OxvPmeU790JoaPEewcYyauoVpy6fzVTusUH8oATFtbu6XBmKzHMqvoi UdAOS8vPFbd85InxEk9X5NBxyC3fQb3hV1TJCHUkQsGkLb1STUJsLxUUxl6iDheuPDeG d9paiBKxGf1VyAQ/wK2IF/5kboSPxXXMnREjq/8qiHWucReIOvZYsnInmV11uqC0ZPWJ N9iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xwWK1609; 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 o12si370655pjp.72.2019.07.17.20.18.51; Wed, 17 Jul 2019 20:19:07 -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=xwWK1609; 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 S2391065AbfGRDPO (ORCPT + 99 others); Wed, 17 Jul 2019 23:15:14 -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: 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 @@ -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;