Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2344795ybz; Thu, 23 Apr 2020 16:25:40 -0700 (PDT) X-Google-Smtp-Source: APiQypKmf/jsoC1fD3R0lagId3Z8yk3pxGNAyyzv8+PZ+0j0MwgRjW3oM3JGYB3CrJOmKdz/dMpf X-Received: by 2002:a05:6402:75a:: with SMTP id p26mr4867184edy.311.1587684340097; Thu, 23 Apr 2020 16:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684340; cv=none; d=google.com; s=arc-20160816; b=CVTOyASx5HXcPCsAtg5YJS1PFBWzrsqsuOYd2Os9sRc1fy9ucru4g0i+KnAVASd3ss cWRf2iXAUNNg3DlDo7UWgr50bn3zNfDuSOgFKJ0B2TpgrJLsaKvmnYOBpyj/vvEpI8A3 V0+g+4m9MXtTiIUjE3mYnYfYEdA9K4+RBNAWQyBbXkulr5ty3dcenQPpTIkR1pHf9KAZ +YiwEJl+fch1tL6S9Itof3IQ6mY1hA8b3xv1a8Inr//SpF8rkMR+xO0Kw7Oi/YzpxzpU uuqxAFHLGFTGg4tyyTf0RNafYoNTsis8vhUiiodlZbowJHmnsBlPeaw1irc4SmLSuEwz ZHKQ== 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=q39h1qAFWYc8acRiJjXuZIRFewmjjTsNvaQoZ7FZjkY=; b=R95HZVaICveEqD5FwhSURGKBXLOVrDgU1s6q0wuNbXbRZ5uFG3PM9wmqK0DEv64swO y9/suxPOp4Iil3MpUskCURkOpJptuii0Ch3Hzcr3RGJ8W1l8sIWvYx+B8ibaKh7TDw1+ OI6YmyqUrY9bKsUuCqYQAsrulS8tOVXBsh2OTWEoVpMxpGlLTTgTUwV0LWAqXGzfiWbu REMW7Q1c1u0GKP7fskrIZ3YLhf6otq3n9mYR4bRJ5Uno5enrAj6/3ZK9fZX6qDHPj8nM yP8As9V7azIBGlFaTBnl3vLgBPhHki8ysxiCYvS8FHnWBVSwf+hsay/+lCvtK3QCxSay NeDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F7GUsPIe; 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 a88si2211575edf.379.2020.04.23.16.25.16; Thu, 23 Apr 2020 16:25:40 -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=F7GUsPIe; 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 S1728555AbgDWXXU (ORCPT + 99 others); Thu, 23 Apr 2020 19:23:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:58804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728674AbgDWXWO (ORCPT ); Thu, 23 Apr 2020 19:22:14 -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 CFFD721D79; Thu, 23 Apr 2020 23:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587684133; bh=QYkHWatvG/hcgVw6oFC51lqgf5Ht3+Uf11iSODW8HgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7GUsPIeI44bMRlTZP/n14mDu97/YrqI7D7NpX2NokPAOE3ViQYkHmJ434KhSj4qQ QOZWl9cxg4f9+okGgrE8ECGwRCZhOPrwqaiYrAgYmxu4ATBIZTCtcwdD8puyJNonKt qu27V/nvM5TfnbtQ4rEl9rOWeDegDQDHBnEyY4a0= 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 v10 02/18] selftests/x86/fsgsbase: Test GS selector on ptracer-induced GS base write Date: Thu, 23 Apr 2020 19:21:51 -0400 Message-Id: <20200423232207.5797-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200423232207.5797-1-sashal@kernel.org> References: <20200423232207.5797-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" The test validates that the selector is not changed when a ptracer writes the ptracee's GS base. Originally-by: Andy Lutomirski Signed-off-by: Chang S. Bae 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 Signed-off-by: Sasha Levin --- tools/testing/selftests/x86/fsgsbase.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index 15a329da59fa3..950a48b2e3662 100644 --- a/tools/testing/selftests/x86/fsgsbase.c +++ b/tools/testing/selftests/x86/fsgsbase.c @@ -465,7 +465,7 @@ static void test_ptrace_write_gsbase(void) wait(&status); if (WSTOPSIG(status) == SIGTRAP) { - unsigned long gs, base; + unsigned long gs; unsigned long gs_offset = USER_REGS_OFFSET(gs); unsigned long base_offset = USER_REGS_OFFSET(gs_base); @@ -481,7 +481,6 @@ static void test_ptrace_write_gsbase(void) err(1, "PTRACE_POKEUSER"); gs = ptrace(PTRACE_PEEKUSER, child, gs_offset, NULL); - base = ptrace(PTRACE_PEEKUSER, child, base_offset, NULL); /* * In a non-FSGSBASE system, the nonzero selector will load @@ -489,11 +488,21 @@ static void test_ptrace_write_gsbase(void) * selector value is changed or not by the GSBASE write in * a ptracer. */ - if (gs == 0 && base == 0xFF) { - printf("[OK]\tGS was reset as expected\n"); - } else { + if (gs != *shared_scratch) { nerrs++; - printf("[FAIL]\tGS=0x%lx, GSBASE=0x%lx (should be 0, 0xFF)\n", gs, base); + printf("[FAIL]\tGS changed to %lx\n", gs); + + /* + * On older kernels, poking a nonzero value into the + * base would zero the selector. On newer kernels, + * this behavior has changed -- poking the base + * changes only the base and, if FSGSBASE is not + * available, this may not effect. + */ + if (gs == 0) + printf("\tNote: this is expected behavior on older kernels.\n"); + } else { + printf("[OK]\tGS remained 0x%hx\n", *shared_scratch); } } -- 2.20.1