Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1576263ybk; Sun, 10 May 2020 21:58:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9qTqWgIjyaaV8h1AX0ZJAk/ccoindzRwuTqQ9Tc2L3eduPPUIFjHR7QAbL/Usg/03fGi5 X-Received: by 2002:a17:906:9384:: with SMTP id l4mr691239ejx.168.1589173110941; Sun, 10 May 2020 21:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173110; cv=none; d=google.com; s=arc-20160816; b=U+bB47zEK/4HHwFGZpiGKVPsgj05kQEf75Fy/iA2ovSVqDqDeaPMwUxwbFK5nWGLhT Qhbeyf5KJl96JhhobGpIwCyQCQSZdH7tSyKqwQJuvRQ5/RuPeeMpwhQpU0kGJpJYCIcX k5Ahf514iHlZJOOTSlEtv2U/FSFaYp7IV4G8ENi2fns4sMTL1KQFISnWZcFokSnJL6F/ 2iEYzJd9rQKqofrla0PKI3xlCFrsNWrZfJ4/aytYaMhJkTLsGvAeV/M1GWIDpn45QTAY bI5kQfB7UlY1iN7ETjhBgRcBzkN9ujOTfqKTYEFF0PdRcynEoPCs/QWkvlwKlOo0CEi3 zaFg== 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=EdLkcfzx2rTZUKiFufGmgZZlepmGO5mkdIj8FFOzGY9nNZ73sCLqkfc1rnYYxu0hPa z+vaLKu/LEPSDhpKC9eWkUw0HAmJJ8cmUjtll82t+G339GeCOFPsb8gzjOsNuqMdKi/W feY2vh5akgHxoltkcB+2BHCjEONW//oY15wwGbgG5tH5d5saiPsohg9v3pt/63MGd9fS PJ7KZgp571557jZMiZN6BtZgEeBlyoU4mvgTTLzBHJIls/SnMOB+3EW+A76b1JsiIcxl i8qNti54uUsACztsrByasRKccMlVcDvYgNIrTh2CF+H8KG2jfVVmqIDYVyO68p2MadrY ZetQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0jSHPIIZ; 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 v23si5294124ejo.321.2020.05.10.21.58.01; Sun, 10 May 2020 21:58:30 -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=0jSHPIIZ; 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 S1728058AbgEKExa (ORCPT + 99 others); Mon, 11 May 2020 00:53:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:37108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726071AbgEKEx2 (ORCPT ); Mon, 11 May 2020 00:53:28 -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 3F5942184D; Mon, 11 May 2020 04:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172808; bh=NWCdWvrnftahbOeAAAbo3rET17oclfuJbv2R+igmKSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0jSHPIIZm4bPQsKV4zhO2mMN7Tzl07Tv6CdlDC0ZsVIDZoa+GqVcB6XDuDI8SI9cO A7YlQ8Igz2pqCmOnaUasI7628HcM9OYsWS1dBcvCnucESOk3RmMII3UB5Czlh+bkYn Jb0uezZNoLxhwuP6iCq49s07pbRCPYUw6L6lXFpg= 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 01/18] x86/ptrace: Prevent ptrace from clearing the FS/GS selector Date: Mon, 11 May 2020 00:52:54 -0400 Message-Id: <20200511045311.4785-2-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 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