Skip to content

Commit

Permalink
lang/gcc13: Fix Address sanitizer
Browse files Browse the repository at this point in the history
Software compiled with -fsanitize=address fails to run with the error
message "ASan runtime does not come first in initial library list; you
should either link runtime to your application or manually preload it
with LD_PRELOAD".

This commit fixes the issue by ignoring the [vdso] loaded shared library
instead of linux-vdso.so.

To successfully run the software compiled with -fsanitize=address it is
still necessary to disable ASLR.

PR:		267751
Reported by:	yuri

Co-authored-by:	Andreas Tobler <andreast@gcc.gnu.org>
  • Loading branch information
lsalvadore committed Jan 13, 2024
1 parent 99c1ed3 commit 11e18f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lang/gcc13/Makefile
@@ -1,6 +1,6 @@
PORTNAME= gcc
PORTVERSION= 13.2.0
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= lang
MASTER_SITES= GCC
PKGNAMESUFFIX= ${SUFFIX}
Expand Down
23 changes: 23 additions & 0 deletions lang/gcc13/files/patch-libsanitizer_asan_asan__linux.cpp
@@ -0,0 +1,23 @@
Since the vDSO shared librares on Linux and FreeBSD are called
differently, the initialization order check fails on FreeBSD.
This patch fixes it by ignoring [vdso] instead of linux-vdso.so.

GCC gets the original file from the LLVM Project, so this patch should
probably be upstreamed directly to the LLVM Project rather than to GCC.


--- libsanitizer/asan/asan_linux.cpp.orig 2022-11-23 11:22:41 UTC
+++ libsanitizer/asan/asan_linux.cpp
@@ -148,6 +148,12 @@ static int FindFirstDSOCallback(struct dl_phdr_info *i
return 0;
# endif

+# if SANITIZER_FREEBSD
+ // Ignore vDSO
+ if (internal_strncmp(info->dlpi_name, "[vdso]", sizeof("[vdso]") - 1) == 0)
+ return 0;
+# endif
+
*name = info->dlpi_name;
return 1;
}
13 changes: 13 additions & 0 deletions lang/gcc13/files/patch-libsanitizer_asan_asan__thread.cpp
@@ -0,0 +1,13 @@
--- libsanitizer/asan/asan_thread.cpp.orig 2024-01-12 13:45:52 UTC
+++ libsanitizer/asan/asan_thread.cpp
@@ -323,7 +323,9 @@ void AsanThread::ClearShadowForThreadStackAndTLS() {
if (tls_begin_ != tls_end_) {
uptr tls_begin_aligned = RoundDownTo(tls_begin_, ASAN_SHADOW_GRANULARITY);
uptr tls_end_aligned = RoundUpTo(tls_end_, ASAN_SHADOW_GRANULARITY);
- FastPoisonShadow(tls_begin_aligned, tls_end_aligned - tls_begin_aligned, 0);
+ FastPoisonShadowPartialRightRedzone(tls_begin_aligned,
+ tls_end_ - tls_begin_aligned,
+ tls_end_aligned - tls_end_, 0);
}
}

0 comments on commit 11e18f5

Please sign in to comment.