git: 4c23a98ba3af - main - asan: Use memset_early() to fill shadow memory

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 10 Feb 2026 15:10:56 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=4c23a98ba3af3a00004fd7ef54e6330b4d665d55

commit 4c23a98ba3af3a00004fd7ef54e6330b4d665d55
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-02-10 13:53:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-02-10 15:10:39 +0000

    asan: Use memset_early() to fill shadow memory
    
    __builtin_memset() calls are replaced with calls to memset(), but that
    can't be used before ifunc relocations are processed if the
    implementation is selected at boot time.  Meanwhile, the sanitizer may
    emit calls to __asan_set_shadow_*() as soon as locore jumps into C code,
    before ifuncs are selected.
    
    Just unconditionally use memset_early() to work around this.
    
    Reported by:    andrew
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D55079
---
 sys/kern/subr_asan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/subr_asan.c b/sys/kern/subr_asan.c
index fee6c1a844e2..867d232198b9 100644
--- a/sys/kern/subr_asan.c
+++ b/sys/kern/subr_asan.c
@@ -241,7 +241,7 @@ kasan_shadow_Nbyte_fill(const void *addr, size_t size, uint8_t code)
 	shad = (void *)kasan_md_addr_to_shad((uintptr_t)addr);
 	size = size >> KASAN_SHADOW_SCALE_SHIFT;
 
-	__builtin_memset(shad, code, size);
+	memset_early(shad, code, size);
 }
 
 /*
@@ -1168,7 +1168,7 @@ __asan_handle_no_return(void)
 	void __asan_set_shadow_##byte(void *, size_t);			\
 	void __asan_set_shadow_##byte(void *addr, size_t size)		\
 	{								\
-		__builtin_memset((void *)addr, 0x##byte, size);		\
+		memset_early((void *)addr, 0x##byte, size);		\
 	}
 
 ASAN_SET_SHADOW(00);