Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp550331ybk; Sat, 9 May 2020 10:41:12 -0700 (PDT) X-Google-Smtp-Source: APiQypLPe1cK6vwRtUHAqYte4KzljXRJa0f47sVRw9lgLFllmCOZ4LZd2Z9CEEN48RyXsBlots6+ X-Received: by 2002:a17:907:2170:: with SMTP id rl16mr7128653ejb.238.1589046072746; Sat, 09 May 2020 10:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589046072; cv=none; d=google.com; s=arc-20160816; b=beIKiSbvkWLFMS95vYqwiWDTuykeMzB2DpiHAQhfVMWnqugM7xkpJk5M8hw52m5Gpr m5SqcdIhmnh5mSwxDJw36CHpog+8k73YXRAN4hqE8Oyk7xYq6aYVw23YftmcwGOh94PM yZlf8MeLUMZzaJWcAtmiG/o45pUyjwjB/EGQOQxUJT84xPT97QRNZCsTrHUQk+3FswX1 tXz4CtWhQ/uRXiZBxjDlmunvoMchEJaWmgjPxNuu2eLvMeZrWqPZnpIVAKiU9z0aI4wG SYzKzvmveuKNmeB/DesZsl60o02NEx5zliJwG7olwvmQIzIdNlIPKpAGiU0sZh9t1MBT 1wWA== 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=NZHc/tbrJlWqKlupHF2XDiizvvP2fm9yGiNUDbXo42o=; b=Jm38lNoYXqbWTJKgReXk5rCpHPnkqm4GH0scQrXAiGBU1OAt1KSpa0kNSoGRpEwoxc 5Dk6yLUCXOREi7c0dU6uYYUJuE4RnKaLpddS6M0yjsGWya7mfa/3xsoa18mMyFfcAmv9 DaqYRfAS2HpRpZTluvEJ6B0+BZU/LaIRiksKV5KNH/x7UDbHjK8tcDO5QAFROwvw/GWj NT7av9XYIrCHoroMlaW9oRP0IrmCSqtyWnQXLsmn15sALVnNPqleznMeXssxSSYC/PWT G49EpUjn33nBDhZI74sExZ11mO/jon2Zvkn+hbVWx8ZAQUOtp1TME13MT63Oe6WD9yxq 84Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UC41KBEx; 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 z21si3039509edr.368.2020.05.09.10.40.50; Sat, 09 May 2020 10:41:12 -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=UC41KBEx; 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 S1728648AbgEIRhY (ORCPT + 99 others); Sat, 9 May 2020 13:37:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:54720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728626AbgEIRhV (ORCPT ); Sat, 9 May 2020 13:37:21 -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 C06262495E; Sat, 9 May 2020 17:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589045840; bh=yGsErY4lfF05kcjCufjLjwlqkaM13VlRZt3xQ4e1M44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UC41KBExq7q+iBJDE8pxwPd04nzGgcnwKeHTiHsN9WkFxXQa59SZg37icY1MRhy7p /mB8+EMJYyGc0AOoJqIKr8jRstb2KbtB5IKQBvzQEQQD9Mc9K/7F9FdpC34u4BFNDA i2TU6XJ4Z9YVOSHFYtg4B4qxDUT4lXHdCGwpGj0M= 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 15/18] selftests/x86/fsgsbase: Test ptracer-induced GS base write with FSGSBASE Date: Sat, 9 May 2020 13:36:52 -0400 Message-Id: <20200509173655.13977-16-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" This validates that GS selector and base are independently preserved in ptrace commands. 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 --- 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 950a48b2e3662..9a4349813a30a 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.20.1