Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2565583ybd; Thu, 27 Jun 2019 14:52:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHYiBMaeo95G9BpVN02EHdRlbjD2UzNoukodkSQhoRUB+3Nool15vMnwY4QPLXe+lLYj/t X-Received: by 2002:a65:6497:: with SMTP id e23mr455762pgv.89.1561672349333; Thu, 27 Jun 2019 14:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561672349; cv=none; d=google.com; s=arc-20160816; b=CA7lObm8hVMEl8xFWGqDxaysl0pG+dtGYfcaMVp73o5o0PybQrcTMHbVzxitPQQKua XasTTlQmBF+b1nZ0xyQ5TCbQcE36Jur/nReAnHhYjwv2jKYvrLlygs7PT0erMuea0XA5 WrpMFkHJTddI+Epjas3dbclk9z1hfsH2+/ZrT9cyNCAUl8QJv27wERrBwnE2jxPsEcDc mO6tWZRK/uXD5Zr3W1PDLwpRGXX9Kp2aaR8Zm771ED61EGyqw4BuwaGGAqqNGR++pGJR EjmcZ0wd6K9FxPHAV4ur0kmThoOGjX13Tm6+9W3luWbGiPw9DY3T5CFeBNbnn6pCjoMQ EvWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=IKXKz9MOR485MGNyLlQ8hSJHcee3ENsDy3/j9pz90pA=; b=T6UCF6KNQNFV8+VnOabhNpQ2Fdc9kUWl9LQ/rcsQcyEAEK9VCwwJZht5bJcyAnQa3c Iy4eHuNle9oUjLgKuBmGFE5Nb6d8gkjh1qtO9OWh2FkdNdoPjHVZPa3Z2x4lkxbjvUeL sTb3iAQnbAYCJUOsR3PtAJcXlsrXucdwLX2iZkkHGD6heOPzQUlo/+g4G3flHF3vI5m8 Ffv+JHjoHlR1Zt5rgx7ieqpWAX8u3jHXAu5GmvtDXLFHlN2LN2cKBHOF3KD7PEotn9cn 3IQF/sISOPD/BaK6GqgsGkhWSmRmep+l1uEbJJshp6SGqpcPKHMqLow6JRvcy3TVFpYA c0kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b=BqiOtcMv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6si265281pgu.154.2019.06.27.14.52.12; Thu, 27 Jun 2019 14:52: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=@zytor.com header.s=2019061801 header.b=BqiOtcMv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726531AbfF0VwH (ORCPT + 99 others); Thu, 27 Jun 2019 17:52:07 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53967 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbfF0VwH (ORCPT ); Thu, 27 Jun 2019 17:52:07 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x5RLq0nd464952 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 27 Jun 2019 14:52:00 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x5RLq0nd464952 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1561672321; bh=IKXKz9MOR485MGNyLlQ8hSJHcee3ENsDy3/j9pz90pA=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=BqiOtcMv3dp6AhndbAAIhINa5XuKa9j4QumszoTPnE14dfDZla/b877M177Uomyhc DFgAoS+9xesUbFICgwEPVhDzT1psESDpJAguzJPdnHwyAu3fE4bQ7nNGGRKsmBtU8f BhMFxK3AS9m9KH0LSjQQqtd/2bTmu1BttOrbvgyXKBiZ/vd2rus1JejG9nPdo7L842 8tQytJBCzEcLpr8qkPVls9GIJjudtfeJUV5v8uwbzGWT5BNIXtZq09FQ25EbBOT1H7 N8nqdpQf6Hdr8bKvb8NfMRmVtFVN9Aq4DwMbwtJ0xDNdsP6jCYaTcWTZhJGDkjwwIB 1eYrbGUmh3oIA== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x5RLq0so464949; Thu, 27 Jun 2019 14:52:00 -0700 Date: Thu, 27 Jun 2019 14:52:00 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dianzhang Chen Message-ID: Cc: dianzhangchen0@gmail.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de Reply-To: linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, dianzhangchen0@gmail.com In-Reply-To: <1561476617-3759-1-git-send-email-dianzhangchen0@gmail.com> References: <1561476617-3759-1-git-send-email-dianzhangchen0@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg() Git-Commit-ID: 31a2fbb390fee4231281b939e1979e810f945415 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=2.4 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_12_24,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, DKIM_VALID_EF,FREEMAIL_FORGED_REPLYTO,FREEMAIL_REPLYTO_END_DIGIT autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 31a2fbb390fee4231281b939e1979e810f945415 Gitweb: https://git.kernel.org/tip/31a2fbb390fee4231281b939e1979e810f945415 Author: Dianzhang Chen AuthorDate: Tue, 25 Jun 2019 23:30:17 +0800 Committer: Thomas Gleixner CommitDate: Thu, 27 Jun 2019 23:48:04 +0200 x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg() 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 --- arch/x86/kernel/ptrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index a166c960bc9e..cbac64659dc4 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -643,9 +644,11 @@ static unsigned long ptrace_get_debugreg(struct task_struct *tsk, int n) { 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;