From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B7D8C433DF for ; Thu, 21 May 2020 21:17:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7911207F9 for ; Thu, 21 May 2020 21:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730187AbgEUVRi (ORCPT ); Thu, 21 May 2020 17:17:38 -0400 Received: from mga02.intel.com ([134.134.136.20]:63538 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgEUVRi (ORCPT ); Thu, 21 May 2020 17:17:38 -0400 IronPort-SDR: uds8W+vMqX510KuLiMysfPrhV1xuFnbuQz3t8aBcTbn7HASsz5murp+07KaqShQyi1tBKQw38r KKm5mUyfOrGw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 14:17:37 -0700 IronPort-SDR: m6oSK0QqnCy8iuARIOKXpyNhnlkfm9AYnpNWX/bVcxPdVBY1OOEMK9syEBvp+wyfHPU07sLfOU H5RCbW6fk+1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,419,1583222400"; d="scan'208";a="440623118" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005.jf.intel.com with ESMTP; 21 May 2020 14:17:36 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang Cc: Yu-cheng Yu Subject: [RFC PATCH 0/5] Update selftests/x86 for CET Date: Thu, 21 May 2020 14:17:15 -0700 Message-Id: <20200521211720.20236-1-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-api-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org When CET is enabled for selftests/x86, two tests need updates. - The test 'sigreturn_64' does a sigreturn() from a 64-bit context into a 32-bit context. The task's 64-bit shadow stack pointer certainly triggers a fault. Fix it by allocating and switching to a new shadow stack in the 32-bit address range. The arch_ptrcl(ARCH_X86_CET_ALLOC_SHSTK) is updated for taking a bit from the input parameter to indicate the desire of MAP_32BIT. I am proposing this change to minimize API changes, but open to any alternatives. - The test 'sysret_rip' fails because the assembly code needs ENDBR opcodes. Fix it by adding just that. My latest CET submission (v10) does not include the IBT patches. My purpose of posting this now is to show the changes needed in x86 tests. Since ENDBR is nop when IBT is not enabled, this patch can be applied now or split out and merged with the IBT patches. - The makefile changes add "-fcf-protection -mshstk" to the gcc command, when those are available. - Introduce cet_quick_test that checks the system's CET capabilities. This series is based on my CET series: https://lore.kernel.org/lkml/20200429220732.31602-2-yu-cheng.yu@intel.com/ Yu-cheng Yu (5): x86/cet/shstk: Modify ARCH_X86_CET_ALLOC_SHSTK for 32-bit address range selftest/x86: Enable CET for selftests/x86 selftest/x86: Fix sigreturn_64 test. selftest/x86: Fix sysret_rip with ENDBR selftest/x86: Add CET quick test arch/x86/include/asm/cet.h | 2 +- arch/x86/include/uapi/asm/prctl.h | 2 + arch/x86/kernel/cet.c | 19 ++- arch/x86/kernel/cet_prctl.c | 6 +- tools/testing/selftests/x86/Makefile | 7 +- tools/testing/selftests/x86/cet_quick_test.c | 128 +++++++++++++++++++ tools/testing/selftests/x86/sigreturn.c | 28 ++++ tools/testing/selftests/x86/sysret_rip.c | 5 +- 8 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/x86/cet_quick_test.c -- 2.21.0