From 58a3c49678f478a2e0ba185de45bdb43162e8598 Mon Sep 17 00:00:00 2001 From: Vauff Date: Fri, 18 Oct 2024 22:08:27 -0400 Subject: [PATCH] New method for running AddressSanitizer Old method broke after some CS2 update, because Valve started passing RTLD_DEEPBIND to dlopen themselves. So we have to override all dlopen calls to remove the flag. Credit to Poggu for coming up with dlhook --- configure.py | 5 +++-- devtools/dlhook/libasan.so.dlhook.so | Bin 0 -> 16272 bytes devtools/dlhook/src/compile.sh | 1 + devtools/dlhook/src/dlhook.c | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 devtools/dlhook/libasan.so.dlhook.so create mode 100644 devtools/dlhook/src/compile.sh create mode 100644 devtools/dlhook/src/dlhook.c diff --git a/configure.py b/configure.py index aee9750c..b9c7013a 100644 --- a/configure.py +++ b/configure.py @@ -39,8 +39,9 @@ parser.options.add_argument('--targets', type=str, dest='targets', default=None, help="Override the target architecture (use commas to separate multiple targets).") # AddressSanitizer Instructions: -# Recompile Metamod with RTLD_DEEPBIND removed (may break some std functionality) -# Run server with LD_PRELOAD=/usr/lib/clang/11/lib/linux/libclang_rt.asan-x86_64.so (for SteamRT3) +# Copy devtools/dlhook/libasan.so.dlhook.so to the server +# Run server with LD_PRELOAD="/path/to/libasan.so.dlhook.so /usr/lib/clang/11/lib/linux/libclang_rt.asan-x86_64.so" (for SteamRT3) +# Note this may break some std functionality parser.options.add_argument('--asan', action='store_const', const='1', dest='asan', help='Build for AddressSanitizer') parser.Configure() diff --git a/devtools/dlhook/libasan.so.dlhook.so b/devtools/dlhook/libasan.so.dlhook.so new file mode 100644 index 0000000000000000000000000000000000000000..538607c9fb4e13985a3b91e1a9fc68a929dc0122 GIT binary patch literal 16272 zcmeHOU2Ggz6~61W6DN)BZAn_kfo4(#DW&OTeCOxhJ@?M!&d$A`PmYbYMIs6%svc7;&Ba_MA&S_bR0tAkP~AbF z_p0}4+x9h8Q|)YrO97R{grJ5IbPd?`Pr{#NFZt)VUz;%o|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_p>g z_j$63(D=S)u(iLmivL40X;aPf>c_-KT8zstG~Yb#ztv4O&$nfX6CB5zns1&Do9Twm-`1_i}D>YSiDo%BJ+MH5r z$1!ZDU{CRZjEb`DbjhB{mnKtrJMEOp6+2Zuuck_c*?h*yq|L$j!~0ts@i~p0ohp}8 zH9J#u$~84zP8BkCx>_jI$i*YsWa;=!)A?+v^l9qUbhS8T_8)j8P9CGDhmI%h&g4^U zD7D$VqfDI;ld9%SiA1hcGE>TQGUrLu`8Ug@bjnF7Gn19^%%&+CBsYdTu&xK{)KsdF zqhJ)8BU3MRoXJW>nKZi!G-Fy#*LTbDdXLvkSZCq?cc2jni2D_2+70LP$2tJG8-{|i zjB2n$RQo5bsn9;wkwEyvFWCNv$e-7c@W;9WxJWuKygZ~!ym7z9`tJ;Jyq1GM)*nEu zQ^`aZj^QnzAc5D6@W(m@hnX;|Tdh z@yGZpLo|XsX5JF$j(Uld%)uY)OWN7& z6b!~|r^dN`F>hGI|A7YMR@jz{7cuu-jr(~P?MveMcLz=>+Q*;>Z%Bfa< Xr|m5Pk)Ehp`|Ae;(sczK0;2j4tEjFg literal 0 HcmV?d00001 diff --git a/devtools/dlhook/src/compile.sh b/devtools/dlhook/src/compile.sh new file mode 100644 index 00000000..0a08e5b8 --- /dev/null +++ b/devtools/dlhook/src/compile.sh @@ -0,0 +1 @@ +gcc -fPIC -rdynamic -shared dlhook.c -o libasan.so.dlhook.so \ No newline at end of file diff --git a/devtools/dlhook/src/dlhook.c b/devtools/dlhook/src/dlhook.c new file mode 100644 index 00000000..304b2519 --- /dev/null +++ b/devtools/dlhook/src/dlhook.c @@ -0,0 +1,15 @@ +#define _GNU_SOURCE +#include +#include + +void *dlopen(const char *filename, int flags) +{ + printf("CALLED DLOPEN!!\n"); + typedef void *(*dlopen_t)(const char *filename, int flags); + static dlopen_t func; + + if(!func) + func = (dlopen_t)dlsym(RTLD_NEXT, "dlopen"); + + return(func(filename, flags & ~RTLD_DEEPBIND)); +} \ No newline at end of file