Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp549312ybk; Sat, 9 May 2020 10:38:53 -0700 (PDT) X-Google-Smtp-Source: APiQypIREk3Vo1G/M7hcjY7om3kaG2/U7cxGB0ynmzQ0sXJxheoRpAVdjME5FZJGHRIZyHcKNgH3 X-Received: by 2002:a17:906:1fd6:: with SMTP id e22mr7147531ejt.150.1589045933437; Sat, 09 May 2020 10:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589045933; cv=none; d=google.com; s=arc-20160816; b=N87gqPN263e8LPMFlCZNXvjJRFr+GIfhpRYhg+1E7Qd5oOKTzNHcBEZg3uJpvZ2tF5 92/eMz9Wb/JnM6p52CpbcisCSTc6I7oq6VBfN42X9FyDG4f/KCvfeS/E5i9DNc/o8fVK TkDPB/0BJrQFT5WzyTQBmBNm2Pa3zZQvOctEu4TsT6DRJAciKY/2F23694Qhucd2aKWQ Qw6Iy7UOCBzcehiU8sid3Hjs6XBlszj1KZUBHS48o80qb7R/86aomkO/SmOVIpOQ9/xt BkOIsIsoz61tMkgBYcRPHXGQ/f4DGj1EW75BpaAKxhHvrGYAVeLlSjyy0s3mkIkisbYo XTng== 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=jUy0v7ze6kjKCg6ajUkFuqHZZU/KG5s567NAqkti4hk=; b=PsdRFCnxYyV/BG1kpOj1+y3MoLRExEWIbmuV6O2ZzOuwLoKIxl0W4X5fVjOeCT1/yn coN12c7IGgXaUf3VxSKMFiwTMd6j8k3mhBWe/+n32YQuxr17DFmpxODt56CkUkh1a5Ll vkzxtTECbp1/jAnCdGHcgy6fXMRCvyLUUyN8DTJTBO2+Xb6NyrGkZrn7zCZP34GO4cCY hqk1E6kKMTK2UlBr6ve78Gi+kD2u6Aa5hKWFBGLPlXyxUSyP/WAmu2oBd9/TgxTsU0en g2Eib2AHLEDMbb+Mawi9qCD1QsqjC84b5O6JVWgezVRMNGoezLnkjqFs/vDN+VJ8POUi Qtvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C0cexfiR; 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 e25si3286511edq.436.2020.05.09.10.38.31; Sat, 09 May 2020 10:38:53 -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=C0cexfiR; 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 S1728433AbgEIRhH (ORCPT + 99 others); Sat, 9 May 2020 13:37:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728276AbgEIRhD (ORCPT ); Sat, 9 May 2020 13:37:03 -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 741E224956; Sat, 9 May 2020 17:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589045822; bh=J0pKosmlOXViYcNqnVdxednHNeYhIEcCdRkEsNZQjqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C0cexfiRsejeUwl95S2ahp/rK97zzutNg5YoFdZ7WkBHdmPo3MJt539zsjuEzpTLx 6H8vpInmTT8unQYV9TPWsonDNch8VpWhbtaOV2DVCz0tio/W1p/lObIzUJwFUtptOB um3FHXMr5BgbPwqThUVh2RYM0y1bXNNTagev+Z58= 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 02/18] selftests/x86/fsgsbase: Test GS selector on ptracer-induced GS base write Date: Sat, 9 May 2020 13:36:39 -0400 Message-Id: <20200509173655.13977-3-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" 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 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 | 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