git: 1d990fe59832 - stable/13 - linker_set: Disable ASAN only in userspace

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 01 Nov 2021 14:33:07 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d990fe598320a80222467fb725a0cedfc19dbf4

commit 1d990fe598320a80222467fb725a0cedfc19dbf4
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-05-07 18:24:37 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-11-01 14:05:39 +0000

    linker_set: Disable ASAN only in userspace
    
    KASAN does not insert redzones around global variables and so is not
    susceptible to the problem that led to us disabling ASAN for linker set
    elements in the first place (see commit fe3d8086fb6f).
    
    Reviewed by:    andrew, kib
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D30126
    
    (cherry picked from commit 2d499d505262c9c965fc5f4fd36afdd2bb7cad3d)
---
 sys/sys/linker_set.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/sys/linker_set.h b/sys/sys/linker_set.h
index f957858ada04..7c12ae215018 100644
--- a/sys/sys/linker_set.h
+++ b/sys/sys/linker_set.h
@@ -59,12 +59,23 @@
  * Private macros, not to be used outside this header file.
  */
 #ifdef __GNUCLIKE___SECTION
+
+/*
+ * The userspace address sanitizer inserts redzones around global variables,
+ * violating the assumption that linker set elements are packed.
+ */
+#ifdef _KERNEL
+#define	__NOASAN
+#else
+#define	__NOASAN	__nosanitizeaddress
+#endif
+
 #define __MAKE_SET_QV(set, sym, qv)			\
 	__WEAK(__CONCAT(__start_set_,set));		\
 	__WEAK(__CONCAT(__stop_set_,set));		\
 	static void const * qv				\
+	__NOASAN					\
 	__set_##set##_sym_##sym __section("set_" #set)	\
-	__nosanitizeaddress				\
 	__used = &(sym)
 #define __MAKE_SET(set, sym)	__MAKE_SET_QV(set, sym, __MAKE_SET_CONST)
 #else /* !__GNUCLIKE___SECTION */