Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5453013pxu; Tue, 22 Dec 2020 18:27:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzs6Qae30s5dVopxfEVRyJrBOQJLhRem4Wn2h1Uw348P2wU29uXgflrQZvQDsKd60m/06hK X-Received: by 2002:a17:906:1752:: with SMTP id d18mr22367028eje.529.1608690463489; Tue, 22 Dec 2020 18:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608690463; cv=none; d=google.com; s=arc-20160816; b=eCQCRjiZOAJ9wVqrtJMQaSkQ+PWLZv0I9HHn+K/zqqF7f/k9KVbfpMLWnJ9D3A0IaG rrl8lKSp08iYHbRFV7JMHqXvq9SvDfavVpdGQqCiGe8+KS/jWBWn2JebhA53JmLJ6zCR bYRNlIRL8jy+lTAmgWvBVO4TP+LR2FwBwkM5skNJkay9gsZb5XOkGyVmltt+f5+Imfwc aIV7NkVz0LKtqhcAwe8ViiICMGtYpco4SDO97MId9hQqfwZrbWvxwDhoy9CTGSmMBMmG iXNJ5Or1lJDO90k69Bxn5Kb+bfelDwuX/7Pln/+9S0uygNSM/qECW3ktDWb6hXlwUDzS LY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KXf9QZt6pjcgPggT2+aWxVkClN6kRlLElvmKFzob4LQ=; b=UnpwBmFMbQY9ATDDzYCmEOrgRA+6pkh0aoK8FravRFBwY0AuZVgRyDrFM5YleVNZVO l/qz/9NrKYfcV7V5S6dST61dBHm1w+6o0qBjMw7ef83WNF/m8Da6JHRlI6fybIxFtxru Ld4Ii68gIGi33kZ9AZUCxnmOGhri0Ygqr1JPzEj65gRauvDgp1rlImmjjJALsALZNO4V VrXad1rGS7Hk3HTgE1ReQOvhJsJQknLMVPjVx2jI/L+UVt7o+qV2g9fymEeCVcMIRs6F U79J4XwQcr4xNPXbAmJXckxQFWWDPHxT/hnIzVyVf5vKLxK4utmAJ7S5TEwMlFqM9hop hJnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cuw0XGTe; 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 o16si12140728ejx.217.2020.12.22.18.27.21; Tue, 22 Dec 2020 18:27:43 -0800 (PST) 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=k20201202 header.b=Cuw0XGTe; 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 S1730049AbgLWCYH (ORCPT + 99 others); Tue, 22 Dec 2020 21:24:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:52738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730087AbgLWCX4 (ORCPT ); Tue, 22 Dec 2020 21:23:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0167F22285; Wed, 23 Dec 2020 02:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608690220; bh=ZyApZxQZVk6sKMiHL/zzmD4bkGQiWvE7rBwr+GXas2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cuw0XGTecvubsokO9T7vXKAaO1qt0x3vnhrwDcPQdegsPuy0/j7LntzYB9q22/fTH ocDLKPLydXBjpp82q/vtuialyN2eJh7Gf+uKKkOfXmMAwOCFUQEe9+K+LNbtmbUKJn HsQS3qneSDmVwrn8fp4d9+j+WRoinztpzjlIsEZl3LRf+crES4JM//3mG6/VCo0pfJ H09QptVJTQtTjZbhOeuHmC5PMDum7fsmro65Z+MS/+g62W2LEm8nmjnKXlYp7+D2hU Ut0KK4fEeQnvdW4q7dFy3K3azSQFCHpQiRJJy248MSD+J632WbUlhW99qEALuErkQc 3Eaxc41p2Zsgw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andy Lutomirski , Borislav Petkov , Sasha Levin , linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 38/66] selftests/x86/fsgsbase: Fix GS == 1, 2, and 3 tests Date: Tue, 22 Dec 2020 21:22:24 -0500 Message-Id: <20201223022253.2793452-38-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201223022253.2793452-1-sashal@kernel.org> References: <20201223022253.2793452-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski [ Upstream commit 716572b0003ef67a4889bd7d85baf5099c5a0248 ] Setting GS to 1, 2, or 3 causes a nonsensical part of the IRET microcode to change GS back to zero on a return from kernel mode to user mode. The result is that these tests fail randomly depending on when interrupts happen. Detect when this happens and let the test pass. Signed-off-by: Andy Lutomirski Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/7567fd44a1d60a9424f25b19a998f12149993b0d.1604346596.git.luto@kernel.org Signed-off-by: Sasha Levin --- tools/testing/selftests/x86/fsgsbase.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index f249e042b3b51..026cd644360f6 100644 --- a/tools/testing/selftests/x86/fsgsbase.c +++ b/tools/testing/selftests/x86/fsgsbase.c @@ -318,8 +318,8 @@ static void set_gs_and_switch_to(unsigned long local, local = read_base(GS); /* - * Signal delivery seems to mess up weird selectors. Put it - * back. + * Signal delivery is quite likely to change a selector + * of 1, 2, or 3 back to 0 due to IRET being defective. */ asm volatile ("mov %0, %%gs" : : "rm" (force_sel)); } else { @@ -337,6 +337,14 @@ static void set_gs_and_switch_to(unsigned long local, if (base == local && sel_pre_sched == sel_post_sched) { printf("[OK]\tGS/BASE remained 0x%hx/0x%lx\n", sel_pre_sched, local); + } else if (base == local && sel_pre_sched >= 1 && sel_pre_sched <= 3 && + sel_post_sched == 0) { + /* + * IRET is misdesigned and will squash selectors 1, 2, or 3 + * to zero. Don't fail the test just because this happened. + */ + printf("[OK]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx because IRET is defective\n", + sel_pre_sched, local, sel_post_sched, base); } else { nerrs++; printf("[FAIL]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx\n", -- 2.27.0