Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3822685pxb; Mon, 30 Aug 2021 11:26:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKjMAbQb5QlpcLS4MwJlASg2SHUzdVJkXnFprdH6xQYMHD7ZpDMDJWZxn6zeHEGeU/HFKp X-Received: by 2002:a17:907:2137:: with SMTP id qo23mr24142400ejb.508.1630347961073; Mon, 30 Aug 2021 11:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630347961; cv=none; d=google.com; s=arc-20160816; b=UJ0Swn5wjj2l2IeQ28i97GRgFGWVOXmAFdVjOvWD/RM9XypczxKdK+rmA17C6hjvli SOPx/XTGD9V/2yFQ8nozWWrRyWOq3oDJl8CwxE31/znW2qnCHol+HtO7F7/Y9Rx3k+gZ qz/J9mv+Zi5knlK9XV3ZWM143w+I3yeCKam81ey6aUDCqr+d2bDQfW4yoIy/oEBXSw/y BaGBpobNFSH/sncxICSV0I3RDhDsbNVEJ+80/JeaA9J2AGjwUBzQ8/JHf1wPckCbVxob uveNjVx+dZug7OoSbMR6GCH3MIOVkv0ynbBVch0vBwHj2MHwJLnPs1tQijfwCdM8huvm QoZA== 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; bh=SiiREc7TIXwCQ9HPvqyjQIl2ykZ/N/a1lepLZDyyO6Y=; b=IPgnKkYmnyQR592VP98eSr7MLT0F5p8+rSZ9P+zUUkalBMxklNjPHQJdYrKPwj/Jzi S0kMnLHCVuULv1z3S1mHpUXonzrkfjswzQPZeYTsoHqpnwBQaOhEfTsAGGc5v59F1uQU UpbeCKLfDJYHikXxdT14U/a7CGwyTCWwav8rAmNFUz9hhSYmcl3Gx8+PEZ1iG4i9F4Ao oeS3juslO2A6S1KkhnpNH6jL5sYZugdO0kY/qSGoxn/7d9zSyx6UcRBm6Kx3/er4wrCj END9B9fmOlKxcmquPqSabMgQpIz+JWaBUdbwu0t3mGyZN9jgtdW5cZfgjvNnXzgwZkB8 cbpg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox26si810630ejb.200.2021.08.30.11.25.36; Mon, 30 Aug 2021 11:26:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238858AbhH3SYg (ORCPT + 99 others); Mon, 30 Aug 2021 14:24:36 -0400 Received: from mga06.intel.com ([134.134.136.31]:24492 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238583AbhH3SYH (ORCPT ); Mon, 30 Aug 2021 14:24:07 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10092"; a="279340866" X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="279340866" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 11:23:11 -0700 X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="540650965" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 11:23:10 -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" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu , Jarkko Sakkinen Subject: [PATCH v30 08/10] x86/vdso: Introduce ENDBR macro Date: Mon, 30 Aug 2021 11:22:19 -0700 Message-Id: <20210830182221.3535-9-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210830182221.3535-1-yu-cheng.yu@intel.com> References: <20210830182221.3535-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ENDBR is a special new instruction for the Indirect Branch Tracking (IBT) component of CET. IBT prevents attacks by ensuring that (most) indirect branches and 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. Introduce ENDBR64/ENDBR32 macros. Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Jarkko Sakkinen Cc: Peter Zijlstra --- arch/x86/include/asm/vdso.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h index 98aa103eb4ab..97358246e4c7 100644 --- a/arch/x86/include/asm/vdso.h +++ b/arch/x86/include/asm/vdso.h @@ -52,6 +52,24 @@ extern int map_vdso_once(const struct vdso_image *image, unsigned long addr); extern bool fixup_vdso_exception(struct pt_regs *regs, int trapnr, unsigned long error_code, unsigned long fault_addr); -#endif /* __ASSEMBLER__ */ +#else /* __ASSEMBLER__ */ + +/* + * 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. + */ +#ifdef CONFIG_X86_IBT +#define ENDBR64 endbr64 +#define ENDBR32 endbr32 +#else +#define ENDBR64 +#define ENDBR32 +#endif +#endif /* __ASSEMBLER__ */ #endif /* _ASM_X86_VDSO_H */ -- 2.21.0