[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210831144114.154-13-alexandr.lobakin@intel.com>
Date: Tue, 31 Aug 2021 16:41:04 +0200
From: Alexander Lobakin <alexandr.lobakin@...el.com>
To: linux-hardening@...r.kernel.org
Cc: "Kristen C Accardi" <kristen.c.accardi@...el.com>,
Kristen Carlson Accardi <kristen@...ux.intel.com>,
Kees Cook <keescook@...omium.org>,
Masahiro Yamada <masahiroy@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>, Jessica Yu <jeyu@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Marios Pomonis <pomonis@...gle.com>,
Sami Tolvanen <samitolvanen@...gle.com>,
Tony Luck <tony.luck@...el.com>,
Ard Biesheuvel <ardb@...nel.org>,
Jesse Brandeburg <jesse.brandeburg@...el.com>,
Lukasz Czapnik <lukasz.czapnik@...el.com>,
"Marta A Plantykow" <marta.a.plantykow@...el.com>,
Michal Kubiak <michal.kubiak@...el.com>,
Michal Swiatkowski <michal.swiatkowski@...el.com>,
Alexander Lobakin <alexandr.lobakin@...el.com>,
linux-kbuild@...r.kernel.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org, clang-built-linux@...glegroups.com
Subject: [PATCH v6 kspp-next 12/22] linkage: add macros for putting ASM functions into own sections
With ClangLTO or -ffunction-sections (DCE, FG-KASLR), compiler
places C functions into separate sections by default.
However, this doesn't happen with ASM functions which are still
being placed into .text.
Introduce a pack of macros which generate a new unique section
for the describing function named in the same fashion
(.text.<func_name>).
This will be needed to make input .text section empty to harden
the kernel even more.
Signed-off-by: Alexander Lobakin <alexandr.lobakin@...el.com>
---
include/linux/linkage.h | 76 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index dbf8506decca..ef8641a7dc1b 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -355,4 +355,80 @@
#endif /* __ASSEMBLY__ */
+/*
+ * Allow ASM symbols to have their own unique sections if they are being
+ * generated by the compiler for C functions (DCE, FG-KASLR, LTO).
+ */
+#if (defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) && !defined(MODULE)) || \
+ (defined(CONFIG_FG_KASLR) && !defined(MODULE)) || \
+ (defined(CONFIG_MODULE_FG_KASLR) && defined(MODULE)) || \
+ (defined(CONFIG_LTO_CLANG))
+
+#define ASM_PUSH_SECTION(name) \
+ ".pushsection .text." #name
+
+#define SYM_TEXT_SECTION(name) \
+ .pushsection .text.##name
+
+#else /* just .text */
+
+#define ASM_PUSH_SECTION(name) \
+ ".pushsection .text"
+
+#define SYM_TEXT_SECTION(name) \
+ .pushsection .text
+
+#endif /* just .text */
+
+#ifdef __ASSEMBLY__
+
+#define SYM_TEXT_END_SECTION \
+ .popsection
+
+#define SYM_FUNC_START_LOCAL_ALIAS_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_FUNC_START_LOCAL_ALIAS(name)
+
+#define SYM_FUNC_START_LOCAL_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_FUNC_START_LOCAL(name)
+
+#define SYM_FUNC_START_NOALIGN_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_FUNC_START_NOALIGN(name)
+
+#define SYM_FUNC_START_WEAK_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_FUNC_START_WEAK(name)
+
+#define SYM_FUNC_START_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_FUNC_START(name)
+
+#define SYM_CODE_START_LOCAL_NOALIGN_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_CODE_START_LOCAL_NOALIGN(name)
+
+#define SYM_CODE_START_NOALIGN_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_CODE_START_NOALIGN(name)
+
+#define SYM_CODE_START_SECTION(name) \
+ SYM_TEXT_SECTION(name) ASM_NL \
+ SYM_CODE_START(name)
+
+#define SYM_FUNC_END_ALIAS_SECTION(name) \
+ SYM_FUNC_END_ALIAS(name) ASM_NL \
+ SYM_TEXT_END_SECTION
+
+#define SYM_FUNC_END_SECTION(name) \
+ SYM_FUNC_END(name) ASM_NL \
+ SYM_TEXT_END_SECTION
+
+#define SYM_CODE_END_SECTION(name) \
+ SYM_CODE_END(name) ASM_NL \
+ SYM_TEXT_END_SECTION
+
+#endif /* __ASSEMBLY__ */
+
#endif /* _LINUX_LINKAGE_H */
--
2.31.1
Powered by blists - more mailing lists