Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1575661ybk; Sun, 10 May 2020 21:57:02 -0700 (PDT) X-Google-Smtp-Source: APiQypJSZUVvMvs9r2EW83x5GkFFeoe9JAorcKVxcibfl1xdAL0qoYWPsyAU3GTddO2Yk+94iJg7 X-Received: by 2002:a17:906:b253:: with SMTP id ce19mr12191009ejb.341.1589173022418; Sun, 10 May 2020 21:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173022; cv=none; d=google.com; s=arc-20160816; b=NxdkT6uG18a3wRUJ5XAszpWmnl0TUf0PbJdeFpJdkL0jnaKcaQgifVlH8EcKy+lnaZ 93NtMrQhYf1r2+N7U1MygNu3dco6AV9V6/4n6lz2X0WM/cw2pT0Js/Qvj5x/B/pXhdM+ 0cCiBtnnamkeoU89pmUrbuEhKeF1JXYCv62wZqMYOwEg2GvbdBHt/vXxPoHYJTF+kPKY DScOkJVA1hWiONn0h+ITBJcvHDgYiYfE6bRVnBggS5tvrKfNB4hAk05Zeg8mtIYL/GwG gyBCHwaRUxz1t9Apa7QmuMlsQ4opgMoqJMAaLj9ojKOSrn390JHSlkGQTWbvMWLLjGSZ UuNA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1eWwP3EWrxqzEbKqwLXQ7tkJFyoAzI8+45TWVPIIGq0=; b=R8EYRsjSj4RPGTJ1jvc+j3hJBLqfUBiozJ6Omua/ECrpu7otcgRiutChwWVxy17Tco mUY/CzOrbM9Bn73/wRmogVtwV4G3JXAem6oighlhjzR+xMWl0CFC6o/kKuhKEh31cJCm 16o8UtjQ8AJUeIwVm9ErTRqIjvrWAuLTW/GbSS5POWx2gDV5xE7J0lWo4T55AHDpy001 Z7JxNnrYg0o4qBhi9UhXda1EYW82HT8niOXJ6E/gi5fYPebX97KsZYfMM/AQNkuZhzrH eYcSTb0a4T9LimfjwF0DNV+LBoT5LGBDBaB0DgQiJ+2KmriKNsfFP2ygdXGsQW0K0ozG 3vVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e96y07+O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt17si2376627edb.224.2020.05.10.21.56.35; Sun, 10 May 2020 21:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e96y07+O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729255AbgEKEyL (ORCPT + 99 others); Mon, 11 May 2020 00:54:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728702AbgEKExp (ORCPT ); Mon, 11 May 2020 00:53:45 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 870BE20820; Mon, 11 May 2020 04:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172824; bh=8moYjDH0vKaHVvSmmvJ+iPsPxHby3FvbWhV8B4oCY9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e96y07+OMcSoPsdQHcWR3bQrGgMGWHIXD+RZTVIMJD/N4J6e0epOSKbuwSFkkUoLF N0pd8EuzqTU6l/rcPohfRCJGtzu7TJl3DInpzUCYVASW5MQvdSgbahm7RAucdFUNVB hOmHKcn6o+akzyLVqUm8ATGu3MNLFwFuPI/KnQZo= From: Sasha Levin To: linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org Cc: hpa@zytor.com, dave.hansen@intel.com, tony.luck@intel.com, ak@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com, Sasha Levin Subject: [PATCH v12 13/18] x86/fsgsbase/64: Use FSGSBASE instructions on thread copy and ptrace Date: Mon, 11 May 2020 00:53:06 -0400 Message-Id: <20200511045311.4785-14-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511045311.4785-1-sashal@kernel.org> References: <20200511045311.4785-1-sashal@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Chang S. Bae" When FSGSBASE is enabled, copying threads and reading FS/GS base using ptrace must read the actual values. When copying a thread, use fsgs_save() and copy the saved values. For ptrace, the bases must be read from memory regardless of the selector if FSGSBASE is enabled. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae Signed-off-by: Sasha Levin Reviewed-by: Tony Luck Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen --- arch/x86/kernel/process.c | 9 +++++---- arch/x86/kernel/process_64.c | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 9da70b279dad8..31dd24f9c8d8e 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -140,10 +140,11 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps)); #ifdef CONFIG_X86_64 - savesegment(gs, p->thread.gsindex); - p->thread.gsbase = p->thread.gsindex ? 0 : current->thread.gsbase; - savesegment(fs, p->thread.fsindex); - p->thread.fsbase = p->thread.fsindex ? 0 : current->thread.fsbase; + save_fsgs(current); + p->thread.fsindex = current->thread.fsindex; + p->thread.fsbase = current->thread.fsbase; + p->thread.gsindex = current->thread.gsindex; + p->thread.gsbase = current->thread.gsbase; savesegment(es, p->thread.es); savesegment(ds, p->thread.ds); #else diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 4be88124d81ea..57cdbbb0381ac 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -346,7 +346,8 @@ unsigned long x86_fsbase_read_task(struct task_struct *task) if (task == current) fsbase = x86_fsbase_read_cpu(); - else if (task->thread.fsindex == 0) + else if (static_cpu_has(X86_FEATURE_FSGSBASE) || + (task->thread.fsindex == 0)) fsbase = task->thread.fsbase; else fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex); @@ -360,7 +361,8 @@ unsigned long x86_gsbase_read_task(struct task_struct *task) if (task == current) gsbase = x86_gsbase_read_cpu_inactive(); - else if (task->thread.gsindex == 0) + else if (static_cpu_has(X86_FEATURE_FSGSBASE) || + (task->thread.gsindex == 0)) gsbase = task->thread.gsbase; else gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex); -- 2.20.1