Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp848352ybi; Fri, 12 Jul 2019 05:39:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkykMXLirk59e4EfcA7G55QiVH8HaYbSCXP/hmq7uAQPlbBKe+eFVCGVVhBxWR1lw5Z0w0 X-Received: by 2002:a17:902:e282:: with SMTP id cf2mr11336114plb.301.1562935169094; Fri, 12 Jul 2019 05:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935169; cv=none; d=google.com; s=arc-20160816; b=VLsRS9TQTXFcQfj+US8klMLi/tcszErazxwMHLcNRZmJQ8ABkK9zWqceOjeMzYxM4I FHgNQFKiQ6/4l0R3/Xi/wLSMQrhqI8YwhX6BVuDHZJkd0SSDQIjdkogEghWfHcNAwvKE rjJaG7wWT2Zi8BSkp4PhkzJKGIthzKdzVXj501e1pV3l5+Q/7B3UmDczmC+ZQWX51/VQ SQehlzm0+E+a0GRjrxFcUgprghyj5viYoV01kb6I1ZEzLKr40DDyEc1lx+ORbgbfwRqu OmAeBgyDUds/TqpfMCtkItnhDi9xae4V7V7f1wKvbqPw2+JnuPsjNU5BQDkjmy9AQmK7 VngA== 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=QpdZ8OThC0NYqCHRCAsVgzFeAjti+SqHdEDNdphs8tc=; b=qsS4wjq/WbTtLiW5nfKqNkU8O4BYRAoMVzYn+8tD/h2Eyxi6E9PtFnxYVie9FPfInE d36oAQI02yquQ2N8Yopw4rGiuL4fFEuka+cm0EZqbAkV3/R/jayziW/AJ4Gj3rMnV4kB MgXG3Hx4JQaPF5+tivHuYVDpvTcWLypxVfxldWL7s/u8iE7wTNTiDqpYvfFSFkDvYlp9 7Bign/uUOSesH8ijyedRRR/6Peop7BOztcbJR+net1DWwOLLc+w7HAKnhbWtNPOT28tu yPiYBx0j5Z1qBaqQbHIWte3GCVnbEC46hkEhA4XWcqlbisGifb0EGwZJPU6qgaKE/tzq FODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ai/anIo3"; 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 ck13si7705419pjb.47.2019.07.12.05.39.13; Fri, 12 Jul 2019 05:39:29 -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="ai/anIo3"; 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 S1728687AbfGLM3q (ORCPT + 99 others); Fri, 12 Jul 2019 08:29:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:44750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbfGLM3l (ORCPT ); Fri, 12 Jul 2019 08:29:41 -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 31D82208E4; Fri, 12 Jul 2019 12:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934580; bh=im/5EH16z/2KM02dgV1PXQid8Mz1fZ2RuFwbckq6wCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ai/anIo3fF168WMRQK/um+b05w4MSCl6TDv+1CwvAmAS7jq7oUJ89r46WajgbdeMU Z12A6065u0s2RbDOdcpiATKeJXG2KEtI0eN3R59Q798ztRUZCFyCuqoN4hm+1ICOTZ oABzWngn+3IH7e4+WOYnMrnwaMY7rHWSxBW30nlI= 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 5.1 102/138] x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg() Date: Fri, 12 Jul 2019 14:19:26 +0200 Message-Id: <20190712121632.679106042@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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 @@ -642,9 +643,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;