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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 183ABC4332E for ; Tue, 16 Mar 2021 17:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F08B36511D for ; Tue, 16 Mar 2021 17:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238575AbhCPRNB (ORCPT ); Tue, 16 Mar 2021 13:13:01 -0400 Received: from mga01.intel.com ([192.55.52.88]:50270 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239171AbhCPRMm (ORCPT ); Tue, 16 Mar 2021 13:12:42 -0400 IronPort-SDR: kupFXEQzqOy4Ngh47OGo92WpruiIVhmacxnCEOG1MjyDormoq4u0xhDWADEvSJZtVmuLTBiWND lEzyeKzwkFIQ== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="209242689" X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="209242689" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 10:12:41 -0700 IronPort-SDR: WAufUYiv2hINDLV1Fsm7MR1NscNe9fmWhCNAMYlonQgBJzkCN1Jk6hMv0wjROGIZvRym4QvWLT XQwO7GxNWjGg== X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="412295708" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.212.191.248]) ([10.212.191.248]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 10:12:40 -0700 Subject: Re: [PATCH v23 6/9] x86/entry: Introduce ENDBR macro To: Dave Hansen , 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 , Pengfei Xu , Haitao Huang Cc: Jarkko Sakkinen References: <20210316151320.6123-1-yu-cheng.yu@intel.com> <20210316151320.6123-7-yu-cheng.yu@intel.com> From: "Yu, Yu-cheng" Message-ID: <15966857-9be7-3029-7e93-e40596b4649a@intel.com> Date: Tue, 16 Mar 2021 10:12:39 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/16/2021 8:49 AM, Dave Hansen wrote: > On 3/16/21 8:13 AM, Yu-cheng Yu wrote: >> --- a/arch/x86/entry/calling.h >> +++ b/arch/x86/entry/calling.h >> @@ -392,3 +392,21 @@ For 32-bit we have the following conventions - kernel is built with >> .endm >> >> #endif /* CONFIG_SMP */ >> +/* >> + * ENDBR is an instruction for the Indirect Branch Tracking (IBT) component >> + * of CET. IBT prevents attacks by ensuring that (most) indirect branches >> + * function calls may only land at ENDBR instructions. Branches that don't >> + * follow the rules will result in control flow (#CF) exceptions. >> + * ENDBR is a noop when IBT is unsupported or disabled. Most ENDBR >> + * instructions are inserted automatically by the compiler, but branch >> + * targets written in assembly must have ENDBR added manually. >> + */ >> +.macro ENDBR >> +#ifdef CONFIG_X86_CET >> +#ifdef __i386__ >> + endbr32 >> +#else >> + endbr64 >> +#endif >> +#endif >> +.endm > > Is "#ifdef __i386__" the right thing to use here? I guess ENDBR only > ends up getting used in the VDSO, but there's a lot of > non-userspace-exposed stuff in calling.h. It seems a bit weird to have > the normally userspace-only __i386__ in there. > > I don't see any existing direct use of __i386__ in arch/x86/entry/vdso. > Good point. My thought was, __i386__ comes from the compiler having the -m32 command-line option, and it is not dependent on anything else. Alternatively, there is another compiler-defined macro _CET_ENDBR that can be used. We can put the following in calling.h: #ifdef __CET__ #include #else #define _CET_ENDBR #endif and then use _CET_ENDBR in other files. How is that? In the future, in case we have kernel-mode IBT, ENDBR macros are also needed for other assembly files. Thanks, Yu-cheng