Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1228220ybp; Fri, 4 Oct 2019 11:21:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8J/tfq/VpDJHRO1q+zg6d96RsO3snGURU7B/cMEvly8KG2bMuB350aGMzQ7O0Kw1B35Xd X-Received: by 2002:a17:906:e92:: with SMTP id p18mr13680162ejf.308.1570213301969; Fri, 04 Oct 2019 11:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570213301; cv=none; d=google.com; s=arc-20160816; b=DwfXXy7+Dcph7J5zCpVaoheQly2WZ4SWFCSeLAU9UdJWfcKS8YkRCqUKxiMV8N7IR/ VbDvPwtTIHDnqQ1eLzGPlCtgahx7m/jhuKkhGLVZ71S2Fr8UOT90MYnhcn18lvNngpAz Z9O19S7EbqQrjWRe5wr/gZRx+H1fiLOJI0FuT+TrgjJSiCASBog9QY4lFAs5FqeX90Io Cs/dm00/eVFT+i4Tu8X/731FKEdpQpsrKXWik7oHlMfxr7A5FmbVWLZ0rwBeMhlZDbHN LuFXxs/YK740Q2X8pk0dau5qRLmcwWzk4fi+Hmg/mcw3llfe58KZGdAkd4jN9yiH8Cat TS1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=NHls5l7/QizLnls1pYvloeqdoXUb9lvDKJJQ0ZtvyvQ=; b=pZIH+0aNO3zsSExKhXglcnV7k83C8rD9pBtJqTCh5dFO7f0PfgSC2rsejWcvXraT0v +v8DJdj+wA1pFhFuiMoZb22ChmJV+9XWrCJMFubXlThPpXo6MLXckfKKnLdou+n63jxO Qux3KTm0ivrTQtpiFcl4sn/cuwS+Uo4JcE4lG1BdJc+RYkjf/v6ZEZU5uZyom7bktu2r XL9qCr8IRGdi/HzIp0A36+0rdfgKPFErxET15aHU+tjqECl8DgHXzwMsoV1XVdBPttIp UqxFd0/GF9vj66dh4YJu9aEwvasXQtQPW3piFbqRummbAaM2oD6Q8GRAKhKnp2cNErxE wrrw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si3511919eju.87.2019.10.04.11.21.18; Fri, 04 Oct 2019 11:21:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388949AbfJDSRR (ORCPT + 99 others); Fri, 4 Oct 2019 14:17:17 -0400 Received: from mga07.intel.com ([134.134.136.100]:15531 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388610AbfJDSRH (ORCPT ); Fri, 4 Oct 2019 14:17:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Oct 2019 11:17:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,257,1566889200"; d="scan'208";a="204394817" Received: from chang-linux-3.sc.intel.com ([172.25.66.185]) by orsmga002.jf.intel.com with ESMTP; 04 Oct 2019 11:17:06 -0700 From: "Chang S. Bae" 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 Subject: [PATCH v9 14/17] selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE Date: Fri, 4 Oct 2019 11:16:06 -0700 Message-Id: <1570212969-21888-15-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1570212969-21888-1-git-send-email-chang.seok.bae@intel.com> References: <1570212969-21888-1-git-send-email-chang.seok.bae@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This validates that GS selector and base are independently preserved in ptrace commands. Suggested-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 --- Changes from v8: none Changes from v7: * Fixed the test message --- tools/testing/selftests/x86/fsgsbase.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index 950a48b..9a43498 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; + unsigned long gs, base; unsigned long gs_offset = USER_REGS_OFFSET(gs); unsigned long base_offset = USER_REGS_OFFSET(gs_base); @@ -481,6 +481,7 @@ 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 @@ -501,8 +502,14 @@ static void test_ptrace_write_gsbase(void) */ if (gs == 0) printf("\tNote: this is expected behavior on older kernels.\n"); + } else if (have_fsgsbase && (base != 0xFF)) { + nerrs++; + printf("[FAIL]\tGSBASE changed to %lx\n", base); } else { - printf("[OK]\tGS remained 0x%hx\n", *shared_scratch); + printf("[OK]\tGS remained 0x%hx", *shared_scratch); + if (have_fsgsbase) + printf(" and GSBASE changed to 0xFF"); + printf("\n"); } } -- 2.7.4