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=ham 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 4E5E9C433DB for ; Tue, 16 Mar 2021 17:12:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE77165123 for ; Tue, 16 Mar 2021 17:12:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE77165123 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0C1116B0036; Tue, 16 Mar 2021 13:12:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070D36B006C; Tue, 16 Mar 2021 13:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2D2A6B006E; Tue, 16 Mar 2021 13:12:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id C2B4C6B0036 for ; Tue, 16 Mar 2021 13:12:52 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 72AFB181AF5E6 for ; Tue, 16 Mar 2021 17:12:52 +0000 (UTC) X-FDA: 77926382184.22.FAD2CCA Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf07.hostedemail.com (Postfix) with ESMTP id 159EFA0049D9 for ; Tue, 16 Mar 2021 17:12:49 +0000 (UTC) IronPort-SDR: i+56e+s5Xlu63R+ty8jzGvQr5f4A8oHLSkVzBM+XKRDwscwzDJwOEwSdS9BDWh+l4NiJmp4tUa I1Y3A+oT32mA== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="176432170" X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208";a="176432170" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.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 X-Stat-Signature: n54559c6zzrydakaohbipb47oo9nznhn X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 159EFA0049D9 Received-SPF: none (intel.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=mga02.intel.com; client-ip=134.134.136.20 X-HE-DKIM-Result: none/none X-HE-Tag: 1615914769-791102 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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