Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1577530ybk; Sun, 10 May 2020 22:01:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5TZrrkGSjcLwhV7dAgUlp6btB+eSKlucNllk/rrGoJT5kyyzKDcIEsu3iV/RuatXqx1fP X-Received: by 2002:aa7:de0e:: with SMTP id h14mr993660edv.82.1589173264267; Sun, 10 May 2020 22:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173264; cv=none; d=google.com; s=arc-20160816; b=r2MPXKGVLpj5+SPPim2z9weC7kJQwBTe+imu3uG2QIQ70J+zIveQ66UKYglSpiIFVg TMvzBrJfVzr0x4jle60BPdq27CvBqbowcJwO+H6FcgQqz0ZMYiqEI3uEGiNr6Jieb94f iUOEt4YV67Koba/hS1zsN8cSJ17EKN5SNAMZI7bJUIMsNcoLfiKGWMJPN/fPkP81NoGi sT2DYOcFdPSM+R5DMKY9yL2FsEXiKJfy/jHOzc9PZCJ0yiB0JDR82tNVMhzuLBMTHLSt E5g7PFAwr82MU+sOrQeKfqdcWJv+gWFYetcSaSe2fcbLQfVq4D8D1JwRR2MKVF+hisAR FRmQ== 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=eIbU/UWbo461EyjN3A68n4Po5CBXXsj2XZyt5KXCMZBExAmvzmuFZyfk3YErF5lKFY xLtzulN5uTbaaKZlQNvj23Bf4za3woV/4Hv0ws5ywDyQk3HVovRLC14ZjUGmJuLXBj/n FzFjT7iJ9pLpjYT+Ni0UFmwAxYjxRG+qrRsUX4ytFM1tzRD8d5nFH3RA6GCLPyXuIiiM RuWBCF5TwGiZa8l8jUdmpOuh+nz3I/Rf15DqI0FF7oDcuCOOfgyFkMUUAxWeFUmVTorU oMKFCE6aQEW0jipASqfjURYyDgk5G1MhrwGKMe6TlKRmNiEUyA0sDGHijjYdNXDlc046 PGWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VS4oU9H3; 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 oq22si1236961ejb.312.2020.05.10.22.00.33; Sun, 10 May 2020 22:01:04 -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=VS4oU9H3; 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 S1728260AbgEKExb (ORCPT + 99 others); Mon, 11 May 2020 00:53:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728030AbgEKExa (ORCPT ); Mon, 11 May 2020 00:53:30 -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 8EDE82192A; Mon, 11 May 2020 04:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172809; bh=J0pKosmlOXViYcNqnVdxednHNeYhIEcCdRkEsNZQjqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VS4oU9H3Q/NcmH+MJrrzZVuf9wcvNtgaNbt2m489V9HyMA4Wnlc4CtvlnjelA66AZ FaPc9DmGA7U+jxjWEHClTLn8dy0NnsX0DmicIG28yDYyyHwHlI1eItBz2n9tSc93tS Q88BtnhlC7qisp62WtsHbX6bw+IctGMeQutHzY9Q= 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 02/18] selftests/x86/fsgsbase: Test GS selector on ptracer-induced GS base write Date: Mon, 11 May 2020 00:52:55 -0400 Message-Id: <20200511045311.4785-3-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" 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