Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp551036ybk; Sat, 9 May 2020 10:42:54 -0700 (PDT) X-Google-Smtp-Source: APiQypLMFBOrMynO0bB3SSxv3YU9ZKnJDIqNkgWs4XPErdTLtLBXg6b/Xy87FpBPAafa0etiehB+ X-Received: by 2002:aa7:c402:: with SMTP id j2mr5418782edq.284.1589046174846; Sat, 09 May 2020 10:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589046174; cv=none; d=google.com; s=arc-20160816; b=Bz1hPz8r1MJ2s4u+O6NtUv1kEeQDgslr5NOPvGvcXwCQC5wt/zXFspD/mIZHYwqzgN 4JhTseuPZafVIQqNeRvV0eVo1ASjW1ogdJOqGXX5f2yv9ThT0cnMWq71saSqqI4FygbR mLVKlSV7eGe6JGO4HVQVBzpvWulazJ2yZafwgt34sl/lVMI/wbw+NxCaYdRoAeqkAGPz l/hoCzRhb7rACzkG17rUASIa2F2Qnwifc8zmZieYfMCl2nr50INnSytkFZrX6ejP6a3R eoPswOog/9v2/Lju2wB8AeQ97h9c6xUybeLgW+zkuQcV2oCNnci94pnJgIGd46yZL01V EOeQ== 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=rrHLcuTVnyoHBaq/mSxl66dx4HFId5DgV7pd/mx6+gM=; b=CO5ZcEO3VczyMaamncQVhiC77IdQXAbfPW8NdZFNQTFJIhD+iWVt3ddPlnH2Kizqc6 sI2MiWBwaVlHHcDenIKwtckITU7+SYKXHgELeemd+IK6ivTaGLfI6Sg6rIVFrECWNAWD mRVqmvxpQIDZJ6LXtNtVncWlNQuKXqdEF4cleBzsLOA4Xm2J5AdDbxX4sOa2GHn9uJYZ 8RzmDgXVN+fwvQG+unbfdJDiT5v2yS8lDkNigLXwa154aJOXLGI8H1JQZisCdq/9U/cf TsN/cEblhG2IpC1OpCVmyVq2tRtZ7UxlGctIDl8rAe8dMQS6naJFphxzloFvVyScsRR9 tk1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="EtG/aBps"; 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 u2si3245192ejr.370.2020.05.09.10.42.32; Sat, 09 May 2020 10:42:54 -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="EtG/aBps"; 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 S1728332AbgEIRhF (ORCPT + 99 others); Sat, 9 May 2020 13:37:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbgEIRhB (ORCPT ); Sat, 9 May 2020 13:37:01 -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 1C2A124954; Sat, 9 May 2020 17:37:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589045821; bh=NWCdWvrnftahbOeAAAbo3rET17oclfuJbv2R+igmKSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EtG/aBpsVsONCM9lpAtkKlSgXnAXoTLU9N/4f3oQTCzsWeGpI9sLYopVqj14/3s99 xNE5Buf/vU0Ma+yMrFL2yv4oXESyQEM+Glax2InGaYVJBLJu7LgSX0MyW/tGYjb1yf wwFjUYSoS7yACbKCYzvQ915k5Sml9gODUDNgZKjc= 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 v11 01/18] x86/ptrace: Prevent ptrace from clearing the FS/GS selector Date: Sat, 9 May 2020 13:36:38 -0400 Message-Id: <20200509173655.13977-2-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200509173655.13977-1-sashal@kernel.org> References: <20200509173655.13977-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 a ptracer writes a ptracee's FS/GS base with a different value, the selector is also cleared. While this behavior is incorrect as the selector should be preserved, most userspace applications did not notice that as they do not use non-zero segments to begin with. Instead, with this patch, when a tracee sets the base we will let it do so without clearing the selector. The change above means that a tracee that already has a selector set will fail in an attempt to set the base - the change won't stick and the value will be instead based on the value of the selector. As with the above, we haven't found userspace that would be affected by this change. Suggested-by: Andy Lutomirski Signed-off-by: Chang S. Bae [sasha: rewrite commit message] 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/ptrace.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index f0e1ddbc2fd78..cc56efb75d275 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -380,25 +380,12 @@ static int putreg(struct task_struct *child, case offsetof(struct user_regs_struct,fs_base): if (value >= TASK_SIZE_MAX) return -EIO; - /* - * When changing the FS base, use do_arch_prctl_64() - * to set the index to zero and to set the base - * as requested. - * - * NB: This behavior is nonsensical and likely needs to - * change when FSGSBASE support is added. - */ - if (child->thread.fsbase != value) - return do_arch_prctl_64(child, ARCH_SET_FS, value); + x86_fsbase_write_task(child, value); return 0; case offsetof(struct user_regs_struct,gs_base): - /* - * Exactly the same here as the %fs handling above. - */ if (value >= TASK_SIZE_MAX) return -EIO; - if (child->thread.gsbase != value) - return do_arch_prctl_64(child, ARCH_SET_GS, value); + x86_gsbase_write_task(child, value); return 0; #endif } -- 2.20.1