diff --git a/ape/BUILD.mk b/ape/BUILD.mk index 7a565cbb8..3bbf00e60 100644 --- a/ape/BUILD.mk +++ b/ape/BUILD.mk @@ -162,7 +162,6 @@ o/$(MODE)/ape/ape-no-modify-self.o: \ libc/dce.h \ libc/elf/def.h \ libc/thread/tls.h \ - libc/intrin/asancodes.h \ libc/macho.internal.h \ libc/macros.internal.h \ libc/nexgen32e/uart.internal.h \ @@ -189,7 +188,6 @@ o/$(MODE)/ape/ape-copy-self.o: \ libc/dce.h \ libc/elf/def.h \ libc/thread/tls.h \ - libc/intrin/asancodes.h \ libc/macho.internal.h \ libc/macros.internal.h \ libc/nexgen32e/uart.internal.h \ diff --git a/build/config.mk b/build/config.mk index 2ba79a156..5167a824d 100644 --- a/build/config.mk +++ b/build/config.mk @@ -127,32 +127,10 @@ TARGET_ARCH ?= -msse3 PYFLAGS += -O1 endif -# Asan Mode -# -# Safer binaries good for backend production serving. -# -# - `make MODE=asan` -# - Memory safety -# - Production worthy -# - Backtraces -# - Debuggability -# - Larger binaries -# -ifeq ($(MODE), asan) -ENABLE_FTRACE = 1 -CONFIG_OFLAGS ?= -g -ggdb -CONFIG_CPPFLAGS += -D__SANITIZE_ADDRESS__ -CONFIG_CCFLAGS += $(BACKTRACES) -O2 -DSYSDEBUG -CONFIG_COPTS += -fsanitize=address -TARGET_ARCH ?= -msse3 -QUOTA ?= -C64 -L300 -endif - # Debug Mode # # - `make MODE=dbg` # - Backtraces -# - Enables asan # - Enables ubsan # - Stack canaries # - No optimization @@ -161,9 +139,9 @@ endif ifeq ($(MODE), dbg) ENABLE_FTRACE = 1 CONFIG_OFLAGS ?= -g -ggdb -CONFIG_CPPFLAGS += -DMODE_DBG -D__SANITIZE_ADDRESS__ -D__SANITIZE_UNDEFINED__ +CONFIG_CPPFLAGS += -DMODE_DBG -D__SANITIZE_UNDEFINED__ CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O0 -fno-inline -CONFIG_COPTS += -fsanitize=address -fsanitize=undefined +CONFIG_COPTS += -fsanitize=undefined TARGET_ARCH ?= -msse3 OVERRIDE_CCFLAGS += -fno-pie QUOTA ?= -C64 -L300 diff --git a/build/definitions.mk b/build/definitions.mk index 2683ffe33..000d0a187 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -64,9 +64,6 @@ BACKTRACES = \ -fno-optimize-sibling-calls \ -mno-omit-leaf-frame-pointer -SANITIZER = \ - -fsanitize=address - NO_MAGIC = \ -ffreestanding \ -fno-stack-protector \ diff --git a/examples/asantest.c b/examples/asantest.c deleted file mode 100644 index 19aaa6a90..000000000 --- a/examples/asantest.c +++ /dev/null @@ -1,16 +0,0 @@ -#include - -__static_yoink("__die"); -__static_yoink("GetSymbolByAddr"); -__static_yoink("malloc_inspect_all"); - -char *lol(int n) { - return malloc(n); -} - -char *(*pLol)(int) = lol; - -int main(int argc, char *argv[]) { - char *s = pLol(4); - s[4] = 1; -} diff --git a/libc/calls/asan.internal.h b/libc/calls/asan.internal.h deleted file mode 100644 index 31b504e14..000000000 --- a/libc/calls/asan.internal.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_ -#include "libc/calls/struct/timespec.h" -#include "libc/calls/struct/timeval.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/asmflag.h" -COSMOPOLITAN_C_START_ - -forceinline bool __asan_is_valid_timespec(const struct timespec *ts) { -#ifdef __x86_64__ - bool zf; - asm(ZFLAG_ASM("cmpw\t$0,0x7fff8000(%1)") - : ZFLAG_CONSTRAINT(zf) - : "r"((intptr_t)ts >> 3) - : "memory"); - return zf; -#else - return __asan_is_valid(ts, sizeof(*ts)); -#endif -} - -forceinline bool __asan_is_valid_timeval(const struct timeval *tv) { - return __asan_is_valid_timespec((const struct timespec *)tv); -} - -COSMOPOLITAN_C_END_ -#endif /* COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_ */ diff --git a/libc/calls/chdir.c b/libc/calls/chdir.c index 5482f148b..b37eaf655 100644 --- a/libc/calls/chdir.c +++ b/libc/calls/chdir.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/log/log.h" @@ -59,7 +58,7 @@ int chdir(const char *path) { if (_weaken(GetProgramExecutableName)) { _weaken(GetProgramExecutableName)(); } - if (!path || (IsAsan() && !__asan_is_valid_str(path))) { + if (!path) { rc = efault(); } else if (_weaken(__zipos_parseuri) && _weaken(__zipos_parseuri)(path, &zipname) != -1) { diff --git a/libc/calls/chroot.c b/libc/calls/chroot.c index 107f02521..c5256fd1a 100644 --- a/libc/calls/chroot.c +++ b/libc/calls/chroot.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -49,7 +48,7 @@ */ int chroot(const char *path) { int rc; - if (!path || (IsAsan() && !__asan_is_valid_str(path))) { + if (!path) { rc = efault(); } else { rc = sys_chroot(path); diff --git a/libc/calls/clock_getres.c b/libc/calls/clock_getres.c index 845875461..e400e0569 100644 --- a/libc/calls/clock_getres.c +++ b/libc/calls/clock_getres.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/asan.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/intrin/describeflags.internal.h" @@ -63,7 +62,7 @@ static int sys_clock_getres_xnu(int clock, struct timespec *ts) { */ int clock_getres(int clock, struct timespec *ts) { int rc; - if (!ts || (IsAsan() && !__asan_is_valid_timespec(ts))) { + if (!ts) { rc = efault(); } else if (clock == 127) { rc = einval(); // 127 is used by consts.sh to mean unsupported diff --git a/libc/calls/clock_settime.c b/libc/calls/clock_settime.c index d3b82d0d2..e738d35df 100644 --- a/libc/calls/clock_settime.c +++ b/libc/calls/clock_settime.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/asan.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" @@ -35,7 +34,7 @@ int clock_settime(int clockid, const struct timespec *ts) { struct timeval tv; if (clockid == 127) { rc = einval(); // 127 is used by consts.sh to mean unsupported - } else if (!ts || (IsAsan() && !__asan_is_valid_timespec(ts))) { + } else if (!ts) { rc = efault(); } else if (IsXnu()) { if (clockid == CLOCK_REALTIME) { diff --git a/libc/calls/copy_file_range.c b/libc/calls/copy_file_range.c index 4558ea6f5..d35fcbc9a 100644 --- a/libc/calls/copy_file_range.c +++ b/libc/calls/copy_file_range.c @@ -27,7 +27,6 @@ #include "libc/cosmo.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/sig.h" @@ -109,11 +108,6 @@ ssize_t copy_file_range(int infd, int64_t *opt_in_out_inoffset, int outfd, if (!g_copy_file_range.ok) { rc = enosys(); - } else if (IsAsan() && ((opt_in_out_inoffset && - !__asan_is_valid(opt_in_out_inoffset, 8)) || - (opt_in_out_outoffset && - !__asan_is_valid(opt_in_out_outoffset, 8)))) { - rc = efault(); } else if (__isfdkind(outfd, kFdZip)) { rc = ebadf(); } else if (__isfdkind(infd, kFdZip)) { diff --git a/libc/calls/faccessat.c b/libc/calls/faccessat.c index c5f3066e0..7493e5e90 100644 --- a/libc/calls/faccessat.c +++ b/libc/calls/faccessat.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -52,10 +51,8 @@ int faccessat(int dirfd, const char *path, int amode, int flags) { int e, rc; struct ZiposUri zipname; - if (IsAsan() && !__asan_is_valid_str(path)) { - rc = efault(); - } else if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) || - !(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) { + if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) || + !(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) { rc = einval(); } else if (__isfdkind(dirfd, kFdZip)) { rc = enotsup(); diff --git a/libc/calls/fchmodat.c b/libc/calls/fchmodat.c index 6c5dd007c..e5bbc9bdf 100644 --- a/libc/calls/fchmodat.c +++ b/libc/calls/fchmodat.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -52,10 +51,7 @@ int sys_fchmodat2(int, const char *, unsigned, int); */ int fchmodat(int dirfd, const char *path, uint32_t mode, int flags) { int rc; - if (IsAsan() && !__asan_is_valid_str(path)) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - (rc = __zipos_notat(dirfd, path)) == -1) { + if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { rc = erofs(); } else if (!IsWindows()) { if (IsLinux() && flags) { diff --git a/libc/calls/fchownat.c b/libc/calls/fchownat.c index 8d9adbb35..132cacac5 100644 --- a/libc/calls/fchownat.c +++ b/libc/calls/fchownat.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -43,10 +42,7 @@ int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid, int flags) { int rc; - if (IsAsan() && !__asan_is_valid_str(path)) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - (rc = __zipos_notat(dirfd, path)) == -1) { + if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { rc = erofs(); } else { rc = sys_fchownat(dirfd, path, uid, gid, flags); diff --git a/libc/calls/fcntl-sysv.c b/libc/calls/fcntl-sysv.c index 6f220d1ba..dbd2eba21 100644 --- a/libc/calls/fcntl-sysv.c +++ b/libc/calls/fcntl-sysv.c @@ -21,7 +21,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/sysv/consts/f.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" @@ -32,9 +31,7 @@ int sys_fcntl(int fd, int cmd, uintptr_t arg, int impl(int, int, ...)) { if ((islock = cmd == F_GETLK || // cmd == F_SETLK || // cmd == F_SETLKW)) { - if ((!IsAsan() && !arg) || - (IsAsan() && - !__asan_is_valid((struct flock *)arg, sizeof(struct flock)))) { + if (!arg) { return efault(); } cosmo2flock(arg); diff --git a/libc/calls/fileexists.c b/libc/calls/fileexists.c index 40d4f02ea..03d3a9b80 100644 --- a/libc/calls/fileexists.c +++ b/libc/calls/fileexists.c @@ -23,7 +23,6 @@ #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/nt/files.h" @@ -51,11 +50,8 @@ bool32 fileexists(const char *path) { struct ZiposUri zipname; uint16_t path16[PATH_MAX]; e = errno; - if (IsAsan() && !__asan_is_valid_str(path)) { - efault(); - res = false; - } else if (_weaken(__zipos_open) && - _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = true; } else { diff --git a/libc/calls/fstat.c b/libc/calls/fstat.c index 5c24cb190..bec74978d 100644 --- a/libc/calls/fstat.c +++ b/libc/calls/fstat.c @@ -20,7 +20,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/stat.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -42,9 +41,7 @@ */ int fstat(int fd, struct stat *st) { int rc; - if (IsAsan() && !__asan_is_valid(st, sizeof(*st))) { - rc = efault(); - } else if (__isfdkind(fd, kFdZip)) { + if (__isfdkind(fd, kFdZip)) { rc = _weaken(__zipos_fstat)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st); } else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) { diff --git a/libc/calls/fstatat.c b/libc/calls/fstatat.c index ebb291cef..9e4247067 100644 --- a/libc/calls/fstatat.c +++ b/libc/calls/fstatat.c @@ -23,7 +23,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -76,10 +75,7 @@ int fstatat(int dirfd, const char *path, struct stat *st, int flags) { // execve() depends on this int rc; struct ZiposUri zipname; - if (IsAsan() && (!__asan_is_valid_str(path) || // - !__asan_is_valid(st, sizeof(*st)))) { - rc = efault(); - } else if (flags & ~AT_SYMLINK_NOFOLLOW) { + if (flags & ~AT_SYMLINK_NOFOLLOW) { return einval(); } else if (__isfdkind(dirfd, kFdZip)) { STRACE("zipos dirfd not supported yet"); diff --git a/libc/calls/futimes.c b/libc/calls/futimes.c index 374b18086..50f814c14 100644 --- a/libc/calls/futimes.c +++ b/libc/calls/futimes.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/asan.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" diff --git a/libc/calls/getgroups.c b/libc/calls/getgroups.c index 1d4e5840e..72d49a49a 100644 --- a/libc/calls/getgroups.c +++ b/libc/calls/getgroups.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/groups.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/stdckdint.h" @@ -34,11 +33,7 @@ */ int getgroups(int size, uint32_t list[]) { int rc; - size_t n; - if (IsAsan() && - (ckd_mul(&n, size, sizeof(list[0])) || !__asan_is_valid(list, n))) { - rc = efault(); - } else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { + if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { rc = sys_getgroups(size, list); } else { rc = enosys(); diff --git a/libc/calls/getrandom.c b/libc/calls/getrandom.c index 1e5abd48a..b15abf069 100644 --- a/libc/calls/getrandom.c +++ b/libc/calls/getrandom.c @@ -29,7 +29,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/asmflag.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -182,7 +181,7 @@ ssize_t __getrandom(void *p, size_t n, unsigned f) { */ ssize_t getrandom(void *p, size_t n, unsigned f) { ssize_t rc; - if ((!p && n) || (IsAsan() && !__asan_is_valid(p, n))) { + if ((!p && n)) { rc = efault(); } else if (f & ~(GRND_RANDOM | GRND_NONBLOCK)) { rc = einval(); diff --git a/libc/calls/getrlimit.c b/libc/calls/getrlimit.c index ebd78d2db..f02ac5226 100644 --- a/libc/calls/getrlimit.c +++ b/libc/calls/getrlimit.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/rlimit.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" @@ -41,7 +40,7 @@ int getrlimit(int resource, struct rlimit *rlim) { int rc; if (resource == 127) { rc = einval(); - } else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { + } else if (!rlim) { rc = efault(); } else if (IsXnuSilicon()) { rc = _sysret(__syslib->__getrlimit(resource, rlim)); diff --git a/libc/calls/isdirectory.c b/libc/calls/isdirectory.c index 76a00e024..c5847f7b9 100644 --- a/libc/calls/isdirectory.c +++ b/libc/calls/isdirectory.c @@ -23,7 +23,6 @@ #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/nt/files.h" @@ -51,11 +50,8 @@ bool32 isdirectory(const char *path) { union metastat st; struct ZiposUri zipname; e = errno; - if (IsAsan() && !__asan_is_valid_str(path)) { - efault(); - res = false; - } else if (_weaken(__zipos_open) && - _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = S_ISDIR(st.cosmo.st_mode); } else { diff --git a/libc/calls/isregularfile.c b/libc/calls/isregularfile.c index 87595883b..5dd12bd97 100644 --- a/libc/calls/isregularfile.c +++ b/libc/calls/isregularfile.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/zipos.internal.h" @@ -48,11 +47,8 @@ bool32 isregularfile(const char *path) { union metastat st; struct ZiposUri zipname; e = errno; - if (IsAsan() && !__asan_is_valid_str(path)) { - efault(); - res = false; - } else if (_weaken(__zipos_open) && - _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { res = !!S_ISREG(st.cosmo.st_mode); } else { diff --git a/libc/calls/issymlink.c b/libc/calls/issymlink.c index 633d353e9..f030b20b6 100644 --- a/libc/calls/issymlink.c +++ b/libc/calls/issymlink.c @@ -23,7 +23,6 @@ #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/nt/files.h" @@ -51,11 +50,8 @@ bool32 issymlink(const char *path) { union metastat st; struct ZiposUri zipname; e = errno; - if (IsAsan() && !__asan_is_valid_str(path)) { - efault(); - res = false; - } else if (_weaken(__zipos_open) && - _weaken(__zipos_parseuri)(path, &zipname) != -1) { + if (_weaken(__zipos_open) && + _weaken(__zipos_parseuri)(path, &zipname) != -1) { res = false; } else if (IsMetal()) { res = false; diff --git a/libc/calls/linkat.c b/libc/calls/linkat.c index 1b87e3093..2b3d466d3 100644 --- a/libc/calls/linkat.c +++ b/libc/calls/linkat.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -40,12 +39,9 @@ int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags) { int rc; - if (IsAsan() && - (!__asan_is_valid_str(oldpath) || !__asan_is_valid_str(newpath))) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || - (rc = __zipos_notat(newdirfd, newpath)) == -1)) { + if (_weaken(__zipos_notat) && + ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || + (rc = __zipos_notat(newdirfd, newpath)) == -1)) { STRACE("zipos fchownat not supported yet"); } else if (!IsWindows()) { rc = sys_linkat(olddirfd, oldpath, newdirfd, newpath, flags); diff --git a/libc/calls/madvise.c b/libc/calls/madvise.c index bb05aa0c7..27ea1c7cf 100644 --- a/libc/calls/madvise.c +++ b/libc/calls/madvise.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -38,9 +37,7 @@ */ int madvise(void *addr, size_t length, int advice) { int rc; - if (IsAsan() && !__asan_is_valid(addr, length)) { - rc = enomem(); - } else if (!IsWindows()) { + if (!IsWindows()) { rc = sys_madvise(addr, length, advice); } else { rc = sys_madvise_nt(addr, length, advice); diff --git a/libc/calls/mkdirat.c b/libc/calls/mkdirat.c index d23facbf7..3dd07d8b3 100644 --- a/libc/calls/mkdirat.c +++ b/libc/calls/mkdirat.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -53,10 +52,7 @@ */ int mkdirat(int dirfd, const char *path, unsigned mode) { int rc; - if (IsAsan() && !__asan_is_valid_str(path)) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - (rc = __zipos_notat(dirfd, path)) == -1) { + if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos mkdirat not supported yet"); } else if (!IsWindows()) { rc = sys_mkdirat(dirfd, path, mode); diff --git a/libc/calls/mknod.c b/libc/calls/mknod.c index 75e7090ed..33ee93d32 100644 --- a/libc/calls/mknod.c +++ b/libc/calls/mknod.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/s.h" @@ -42,8 +41,6 @@ */ int mknod(const char *path, uint32_t mode, uint64_t dev) { int e, rc; - if (IsAsan() && !__asan_is_valid_str(path)) - return efault(); if (mode & S_IFREG) return creat(path, mode & ~S_IFREG); if (mode & S_IFDIR) diff --git a/libc/calls/mkntpath.c b/libc/calls/mkntpath.c index 4b9f58641..32477d412 100644 --- a/libc/calls/mkntpath.c +++ b/libc/calls/mkntpath.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" @@ -96,7 +95,7 @@ textwindows int __mkntpath2(const char *path, // 4. Need ≥13 for mkdir() i.e. 1+8+3+1, e.g. "\\ffffffff.xxx\0" // which is an "8.3 filename" from the DOS days - if (!path || (IsAsan() && !__asan_is_valid_str(path))) { + if (!path) { return efault(); } diff --git a/libc/calls/openat.c b/libc/calls/openat.c index f7d15c473..94e4452bc 100644 --- a/libc/calls/openat.c +++ b/libc/calls/openat.c @@ -26,7 +26,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -180,7 +179,7 @@ int openat(int dirfd, const char *path, int flags, ...) { va_end(va); BEGIN_CANCELATION_POINT; - if (!path || (IsAsan() && !__asan_is_valid_str(path))) { + if (!path) { rc = efault(); } else if ((flags & O_UNLINK) && (flags & (O_CREAT | O_EXCL)) != (O_CREAT | O_EXCL)) { diff --git a/libc/calls/openpty.c b/libc/calls/openpty.c index fd9c26cf4..fb0682240 100644 --- a/libc/calls/openpty.c +++ b/libc/calls/openpty.c @@ -27,7 +27,6 @@ #include "libc/calls/termios.h" #include "libc/calls/termios.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/log/rop.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/at.h" @@ -94,13 +93,6 @@ int openpty(int *mfd, int *sfd, char *name, // if (IsWindows() || IsMetal()) { return enosys(); } - if (IsAsan() && (!__asan_is_valid(mfd, sizeof(int)) || - !__asan_is_valid(sfd, sizeof(int)) || - (name && !__asan_is_valid(name, 16)) || - (tio && !__asan_is_valid(tio, sizeof(*tio))) || - (wsz && !__asan_is_valid(wsz, sizeof(*wsz))))) { - return efault(); - } BLOCK_CANCELATION; rc = openpty_impl(mfd, sfd, name, tio, wsz); ALLOW_CANCELATION; diff --git a/libc/calls/pipe.c b/libc/calls/pipe.c index eb370ff10..2f668c31d 100644 --- a/libc/calls/pipe.c +++ b/libc/calls/pipe.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -36,7 +35,7 @@ */ int pipe(int pipefd[hasatleast 2]) { int rc; - if (!pipefd || (IsAsan() && !__asan_is_valid(pipefd, sizeof(int) * 2))) { + if (!pipefd) { // needed for windows which is polyfilled // needed for xnu and netbsd which don't take an argument rc = efault(); diff --git a/libc/calls/pipe2.c b/libc/calls/pipe2.c index 4f49ec446..36593d76c 100644 --- a/libc/calls/pipe2.c +++ b/libc/calls/pipe2.c @@ -19,7 +19,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/errfuns.h" @@ -44,8 +43,7 @@ int pipe2(int pipefd[hasatleast 2], int flags) { int rc; if (flags & ~(O_CLOEXEC | O_NONBLOCK | (O_DIRECT != -1u ? O_DIRECT : 0))) { return einval(); - } else if (!pipefd || - (IsAsan() && !__asan_is_valid(pipefd, sizeof(int) * 2))) { + } else if (!pipefd) { rc = efault(); } else if (!IsWindows()) { rc = sys_pipe2(pipefd, flags); diff --git a/libc/calls/poll.c b/libc/calls/poll.c index c07fb534c..0108475bb 100644 --- a/libc/calls/poll.c +++ b/libc/calls/poll.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/cp.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/struct/pollfd.h" #include "libc/sock/struct/pollfd.internal.h" @@ -65,13 +64,9 @@ */ int poll(struct pollfd *fds, size_t nfds, int timeout_ms) { int rc; - size_t n; BEGIN_CANCELATION_POINT; - if (IsAsan() && - (ckd_mul(&n, nfds, sizeof(struct pollfd)) || !__asan_is_valid(fds, n))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { if (!IsMetal()) { rc = sys_poll(fds, nfds, timeout_ms); } else { diff --git a/libc/calls/ppoll.c b/libc/calls/ppoll.c index 14d210f13..8c2d6d38f 100644 --- a/libc/calls/ppoll.c +++ b/libc/calls/ppoll.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/struct/pollfd.h" #include "libc/sock/struct/pollfd.internal.h" @@ -60,18 +59,12 @@ */ int ppoll(struct pollfd *fds, size_t nfds, const struct timespec *timeout, const sigset_t *sigmask) { - size_t n; int e, rc; sigset_t oldmask; struct timespec ts, *tsp; BEGIN_CANCELATION_POINT; - if (IsAsan() && - (ckd_mul(&n, nfds, sizeof(struct pollfd)) || !__asan_is_valid(fds, n) || - (timeout && !__asan_is_valid(timeout, sizeof(timeout))) || - (sigmask && !__asan_is_valid(sigmask, sizeof(sigmask))))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { e = errno; if (timeout) { ts = *timeout; diff --git a/libc/calls/pread.c b/libc/calls/pread.c index 00de0e652..4aa7b0c53 100644 --- a/libc/calls/pread.c +++ b/libc/calls/pread.c @@ -24,7 +24,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" @@ -67,8 +66,6 @@ ssize_t pread(int fd, void *buf, size_t size, int64_t offset) { rc = einval(); } else if (fd < 0) { rc = ebadf(); - } else if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); } else if (__isfdkind(fd, kFdZip)) { rc = _weaken(__zipos_read)( (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, diff --git a/libc/calls/preadv.c b/libc/calls/preadv.c index cad6a4ac2..586141b80 100644 --- a/libc/calls/preadv.c +++ b/libc/calls/preadv.c @@ -24,7 +24,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/likely.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -52,8 +51,6 @@ static ssize_t Preadv(int fd, struct iovec *iov, int iovlen, int64_t off) { return ebadf(); if (iovlen < 0) return einval(); - if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) - return efault(); // XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX // this is inconsistent with Linux which ignores huge requests diff --git a/libc/calls/pselect.c b/libc/calls/pselect.c index 6a34b8a2b..391d94f53 100644 --- a/libc/calls/pselect.c +++ b/libc/calls/pselect.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" @@ -77,13 +76,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, BEGIN_CANCELATION_POINT; if (nfds < 0) { rc = einval(); - } else if (IsAsan() && - ((readfds && !__asan_is_valid(readfds, FD_SIZE(nfds))) || - (writefds && !__asan_is_valid(writefds, FD_SIZE(nfds))) || - (exceptfds && !__asan_is_valid(exceptfds, FD_SIZE(nfds))) || - (timeout && !__asan_is_valid(timeout, sizeof(*timeout))) || - (sigmask && !__asan_is_valid(sigmask, sizeof(*sigmask))))) { - rc = efault(); } else { if (readfds) { old_readfds = *readfds; diff --git a/libc/calls/pwrite.c b/libc/calls/pwrite.c index 8bf05ac53..f22f52f52 100644 --- a/libc/calls/pwrite.c +++ b/libc/calls/pwrite.c @@ -25,7 +25,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/stdio/sysparam.h" @@ -62,8 +61,6 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) { rc = einval(); } else if (fd == -1) { rc = ebadf(); - } else if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); } else if (__isfdkind(fd, kFdZip)) { rc = ebadf(); } else if (!IsWindows()) { diff --git a/libc/calls/pwritev.c b/libc/calls/pwritev.c index b53d5de64..651b320aa 100644 --- a/libc/calls/pwritev.c +++ b/libc/calls/pwritev.c @@ -24,7 +24,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/likely.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -52,8 +51,6 @@ static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen, return ebadf(); if (iovlen < 0) return einval(); - if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) - return efault(); if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) return ebadf(); diff --git a/libc/calls/read.c b/libc/calls/read.c index 389a3eead..af9461971 100644 --- a/libc/calls/read.c +++ b/libc/calls/read.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/zipos.internal.h" @@ -74,7 +73,7 @@ ssize_t read(int fd, void *buf, size_t size) { if (fd < 0) { rc = ebadf(); - } else if ((!buf && size) || (IsAsan() && !__asan_is_valid(buf, size))) { + } else if ((!buf && size)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = _weaken(__zipos_read)( diff --git a/libc/calls/readlinkat.c b/libc/calls/readlinkat.c index 0593307d6..0312fae73 100644 --- a/libc/calls/readlinkat.c +++ b/libc/calls/readlinkat.c @@ -19,12 +19,12 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/runtime.h" #include "libc/runtime/zipos.internal.h" +#include "libc/stdio/sysparam.h" #include "libc/sysv/errfuns.h" /** @@ -52,8 +52,7 @@ */ ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) { ssize_t bytes; - if ((bufsiz && !buf) || (IsAsan() && (!__asan_is_valid_str(path) || - !__asan_is_valid(buf, bufsiz)))) { + if ((bufsiz && !buf)) { bytes = efault(); } else if (_weaken(__zipos_notat) && (bytes = __zipos_notat(dirfd, path)) == -1) { diff --git a/libc/calls/readv.c b/libc/calls/readv.c index 994242d74..e885ca6de 100644 --- a/libc/calls/readv.c +++ b/libc/calls/readv.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/likely.h" #include "libc/intrin/strace.internal.h" @@ -49,8 +48,6 @@ static ssize_t readv_impl(int fd, const struct iovec *iov, int iovlen) { return ebadf(); if (iovlen < 0) return einval(); - if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) - return efault(); // XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX // this is inconsistent with Linux which ignores huge requests diff --git a/libc/calls/renameat.c b/libc/calls/renameat.c index 02106a4e8..4c329abe6 100644 --- a/libc/calls/renameat.c +++ b/libc/calls/renameat.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -46,12 +45,9 @@ int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { int rc; - if (IsAsan() && - (!__asan_is_valid_str(oldpath) || !__asan_is_valid_str(newpath))) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || - (rc = __zipos_notat(newdirfd, newpath)) == -1)) { + if (_weaken(__zipos_notat) && + ((rc = __zipos_notat(olddirfd, oldpath)) == -1 || + (rc = __zipos_notat(newdirfd, newpath)) == -1)) { STRACE("zipos renameat not supported yet"); } else if (!IsWindows()) { rc = sys_renameat(olddirfd, oldpath, newdirfd, newpath); diff --git a/libc/calls/sched_getparam.c b/libc/calls/sched_getparam.c index e9e0e6bc0..0b5a9705f 100644 --- a/libc/calls/sched_getparam.c +++ b/libc/calls/sched_getparam.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -33,7 +32,7 @@ int sched_getparam(int pid, struct sched_param *param) { int rc; struct sched_param p; - if (!param || (IsAsan() && !__asan_is_valid(param, sizeof(*param)))) { + if (!param) { rc = efault(); } else if (IsNetbsd()) { if (!(rc = sys_sched_getscheduler_netbsd(pid, &p))) { diff --git a/libc/calls/sched_setparam.c b/libc/calls/sched_setparam.c index ca1b0848a..4fae3cbbd 100644 --- a/libc/calls/sched_setparam.c +++ b/libc/calls/sched_setparam.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -34,7 +33,7 @@ int sched_setparam(int pid, const struct sched_param *param) { int rc, policy; struct sched_param p; - if (!param || (IsAsan() && !__asan_is_valid(param, sizeof(*param)))) { + if (!param) { rc = efault(); } else if (IsNetbsd()) { if ((rc = policy = sys_sched_getscheduler_netbsd(pid, &p)) != -1) { diff --git a/libc/calls/select.c b/libc/calls/select.c index 1358aba43..d517eb4ea 100644 --- a/libc/calls/select.c +++ b/libc/calls/select.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" @@ -63,12 +62,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, BEGIN_CANCELATION_POINT; if (nfds < 0) { rc = einval(); - } else if (IsAsan() && - ((readfds && !__asan_is_valid(readfds, FD_SIZE(nfds))) || - (writefds && !__asan_is_valid(writefds, FD_SIZE(nfds))) || - (exceptfds && !__asan_is_valid(exceptfds, FD_SIZE(nfds))) || - (timeout && !__asan_is_valid(timeout, sizeof(*timeout))))) { - rc = efault(); } else { if (readfds) { old_readfds = *readfds; diff --git a/libc/calls/setgroups.c b/libc/calls/setgroups.c index d3e3f956b..0c12a106b 100644 --- a/libc/calls/setgroups.c +++ b/libc/calls/setgroups.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/groups.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/stdckdint.h" @@ -40,11 +39,7 @@ */ int setgroups(size_t size, const uint32_t list[]) { int rc; - size_t n; - if (IsAsan() && - (ckd_mul(&n, size, sizeof(list[0])) || !__asan_is_valid(list, n))) { - rc = efault(); - } else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { + if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { rc = sys_setgroups(size, list); } else { rc = enosys(); diff --git a/libc/calls/setrlimit.c b/libc/calls/setrlimit.c index 58cf2dcd9..96112a096 100644 --- a/libc/calls/setrlimit.c +++ b/libc/calls/setrlimit.c @@ -21,7 +21,6 @@ #include "libc/calls/struct/rlimit.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" @@ -80,7 +79,7 @@ int setrlimit(int resource, const struct rlimit *rlim) { int rc; if (resource == 127) { rc = einval(); - } else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { + } else if (!rlim) { rc = efault(); } else if (IsXnuSilicon()) { rc = _sysret(__syslib->__setrlimit(resource, rlim)); diff --git a/libc/calls/settimeofday.c b/libc/calls/settimeofday.c index 116c1b38e..f0774746d 100644 --- a/libc/calls/settimeofday.c +++ b/libc/calls/settimeofday.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/asan.internal.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.internal.h" #include "libc/dce.h" @@ -29,7 +28,7 @@ */ int settimeofday(const struct timeval *tv, const struct timezone *tz) { int rc; - if (!tv || (IsAsan() && !__asan_is_valid_timeval(tv))) { + if (!tv) { rc = efault(); } else { rc = sys_settimeofday(tv, 0); diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index df751f353..8def7b1dd 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -30,7 +30,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/ucontext.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/dll.h" #include "libc/intrin/strace.internal.h" @@ -167,10 +166,6 @@ static int __sigaction(int sig, const struct sigaction *act, return einval(); if (sig == SIGKILL || sig == SIGSTOP) return einval(); - if (IsAsan() && ((act && !__asan_is_valid(act, sizeof(*act))) || - (oldact && !__asan_is_valid(oldact, sizeof(*oldact))))) { - return efault(); - } if (!act) { rva = (int32_t)(intptr_t)SIG_DFL; } else if ((intptr_t)act->sa_handler < kSigactionMinRva) { diff --git a/libc/calls/sigaltstack.c b/libc/calls/sigaltstack.c index b6da79d0d..7cfb961e4 100644 --- a/libc/calls/sigaltstack.c +++ b/libc/calls/sigaltstack.c @@ -21,9 +21,9 @@ #include "libc/calls/struct/sigaltstack.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" +#include "libc/macros.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/syslib.internal.h" #include "libc/sysv/consts/ss.h" @@ -129,11 +129,8 @@ static int sigaltstack_bsd(const struct sigaltstack *neu, */ int sigaltstack(const struct sigaltstack *neu, struct sigaltstack *old) { int rc; - if (IsAsan() && ((old && !__asan_is_valid(old, sizeof(*old))) || - (neu && !__asan_is_valid(neu, sizeof(*neu))))) { - rc = efault(); - } else if (neu && ((neu->ss_size >> 32) || // - (neu->ss_flags & ~(SS_ONSTACK | SS_DISABLE)))) { + if (neu && ((neu->ss_size >> 32) || // + (neu->ss_flags & ~(SS_ONSTACK | SS_DISABLE)))) { rc = einval(); } else if (neu && neu->ss_size < __get_minsigstksz()) { rc = enomem(); diff --git a/libc/calls/sigpending.c b/libc/calls/sigpending.c index c3daca63b..648a6d223 100644 --- a/libc/calls/sigpending.c +++ b/libc/calls/sigpending.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" @@ -38,7 +37,7 @@ */ int sigpending(sigset_t *pending) { int rc; - if (!pending || (IsAsan() && !__asan_is_valid(pending, sizeof(*pending)))) { + if (!pending) { rc = efault(); } else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { // 128 signals on NetBSD and FreeBSD, 64 on Linux, 32 on OpenBSD and XNU diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index 26a0a9d87..8c4c5d69e 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/synchronization.h" @@ -48,9 +47,7 @@ int sigsuspend(const sigset_t *ignore) { int rc; BEGIN_CANCELATION_POINT; - if (IsAsan() && ignore && !__asan_is_valid(ignore, sizeof(*ignore))) { - rc = efault(); - } else if (IsXnu() || IsOpenbsd()) { + if (IsXnu() || IsOpenbsd()) { // openbsd and xnu use a 32 signal register convention rc = sys_sigsuspend(ignore ? (void *)(intptr_t)(uint32_t)*ignore : 0, 8); } else { diff --git a/libc/calls/sigtimedwait.c b/libc/calls/sigtimedwait.c index be339d65e..d68958113 100644 --- a/libc/calls/sigtimedwait.c +++ b/libc/calls/sigtimedwait.c @@ -17,14 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/sigtimedwait.h" -#include "libc/calls/asan.internal.h" #include "libc/calls/cp.internal.h" #include "libc/calls/sigtimedwait.internal.h" #include "libc/calls/struct/siginfo.internal.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" @@ -52,11 +50,7 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, union siginfo_meta si = {0}; BEGIN_CANCELATION_POINT; - if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) || - (info && !__asan_is_valid(info, sizeof(*info))) || - (timeout && !__asan_is_valid_timespec(timeout)))) { - rc = efault(); - } else if (IsLinux() || IsFreebsd() || IsNetbsd()) { + if (IsLinux() || IsFreebsd() || IsNetbsd()) { if (timeout) { // 1. Linux needs its size parameter // 2. NetBSD modifies timeout argument diff --git a/libc/calls/splice.c b/libc/calls/splice.c index 5d15bfc44..ce936f6ff 100644 --- a/libc/calls/splice.c +++ b/libc/calls/splice.c @@ -23,7 +23,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/mem/alloca.h" @@ -82,11 +81,6 @@ ssize_t splice(int infd, int64_t *opt_in_out_inoffset, int outfd, cosmo_once(&g_splice.once, splice_init); if (!g_splice.ok) { rc = enosys(); - } else if (IsAsan() && ((opt_in_out_inoffset && - !__asan_is_valid(opt_in_out_inoffset, 8)) || - (opt_in_out_outoffset && - !__asan_is_valid(opt_in_out_outoffset, 8)))) { - rc = efault(); } else if (__isfdkind(infd, kFdZip) || __isfdkind(outfd, kFdZip)) { rc = enotsup(); } else { diff --git a/libc/calls/symlinkat.c b/libc/calls/symlinkat.c index 88de3f450..3af90f91d 100644 --- a/libc/calls/symlinkat.c +++ b/libc/calls/symlinkat.c @@ -20,7 +20,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/at.h" @@ -41,10 +40,6 @@ */ int symlinkat(const char *target, int newdirfd, const char *linkpath) { int rc; - if (IsAsan() && - (!__asan_is_valid_str(target) || !__asan_is_valid_str(linkpath))) { - rc = efault(); - } if (!IsWindows()) { rc = sys_symlinkat(target, newdirfd, linkpath); } else { diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index dd18a7fee..5f5fc832f 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -22,7 +22,6 @@ #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/str/str.h" @@ -94,9 +93,7 @@ static int sys_sysinfo_bsd(struct sysinfo *info) { int sysinfo(struct sysinfo *info) { int rc; struct sysinfo x = {0}; - if (IsAsan() && info && !__asan_is_valid(info, sizeof(*info))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { if (IsLinux()) { rc = sys_sysinfo(&x); } else { diff --git a/libc/calls/tcgetattr.c b/libc/calls/tcgetattr.c index bac5f8a8c..e22e0c780 100644 --- a/libc/calls/tcgetattr.c +++ b/libc/calls/tcgetattr.c @@ -24,7 +24,6 @@ #include "libc/calls/termios.internal.h" #include "libc/calls/ttydefaults.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/str/str.h" #include "libc/sysv/errfuns.h" @@ -91,7 +90,7 @@ int tcgetattr(int fd, struct termios *tio) { int rc; if (fd < 0) { rc = einval(); - } else if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { + } else if (!tio) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotty(); diff --git a/libc/calls/tcgetwinsize.c b/libc/calls/tcgetwinsize.c index 4bbb4be8b..6ed585a47 100644 --- a/libc/calls/tcgetwinsize.c +++ b/libc/calls/tcgetwinsize.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" @@ -32,9 +31,7 @@ */ int tcgetwinsize(int fd, struct winsize *ws) { int rc; - if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { - rc = efault(); - } else if (fd >= 0) { + if (fd >= 0) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotty(); } else if (IsWindows()) { diff --git a/libc/calls/tcsetattr.c b/libc/calls/tcsetattr.c index 33f36f7d0..db59486db 100644 --- a/libc/calls/tcsetattr.c +++ b/libc/calls/tcsetattr.c @@ -24,7 +24,6 @@ #include "libc/calls/termios.internal.h" #include "libc/dce.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/mem/alloca.h" @@ -62,10 +61,6 @@ static int tcsetattr_impl(int fd, int opt, const struct termios *tio) { } } - if (IsAsan() && !__asan_is_valid(tio, sizeof(*tio))) { - return efault(); - } - if (IsMetal()) { return 0; } diff --git a/libc/calls/tcsetwinsize.c b/libc/calls/tcsetwinsize.c index ed1f1ecc3..a8503ca68 100644 --- a/libc/calls/tcsetwinsize.c +++ b/libc/calls/tcsetwinsize.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/termios.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/errfuns.h" @@ -34,9 +33,7 @@ int tcsetwinsize_nt(int, const struct winsize *); */ int tcsetwinsize(int fd, const struct winsize *ws) { int rc; - if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { - rc = efault(); - } else if (fd >= 0) { + if (fd >= 0) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotty(); } else if (!IsWindows()) { diff --git a/libc/calls/time.c b/libc/calls/time.c index 644fa669e..d592bc256 100644 --- a/libc/calls/time.c +++ b/libc/calls/time.c @@ -19,7 +19,6 @@ #include "libc/time.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/sysv/errfuns.h" /** @@ -32,10 +31,7 @@ int64_t time(int64_t *opt_out_ret) { int64_t secs; struct timeval tv; - if (IsAsan() && opt_out_ret && - !__asan_is_valid(opt_out_ret, sizeof(*opt_out_ret))) { - secs = efault(); - } else if (gettimeofday(&tv, 0) != -1) { + if (gettimeofday(&tv, 0) != -1) { secs = tv.tv_sec; if (opt_out_ret) { *opt_out_ret = secs; diff --git a/libc/calls/tinyprint.c b/libc/calls/tinyprint.c index c1cac3a52..55aec26ef 100644 --- a/libc/calls/tinyprint.c +++ b/libc/calls/tinyprint.c @@ -19,7 +19,6 @@ #include "libc/calls/blockcancel.internal.h" #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/runtime/runtime.h" #define ASAN_ERROR "error: tinyprint() passed invalid memory, or missing NULL\n" @@ -59,10 +58,6 @@ ssize_t tinyprint(int fd, const char *s, ...) { BLOCK_CANCELATION; va_start(va, s); for (toto = n = 0; s; s = va_arg(va, const char *)) { - if (IsAsan() && !__asan_is_valid_str(s)) { - write(2, ASAN_ERROR, sizeof(ASAN_ERROR) - 1); - abort(); - } while ((c = *s++)) { buf[n++] = c; if (n == sizeof(buf)) { diff --git a/libc/calls/truncate.c b/libc/calls/truncate.c index 5588a5816..956fd81fc 100644 --- a/libc/calls/truncate.c +++ b/libc/calls/truncate.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/zipos.internal.h" @@ -69,7 +68,7 @@ int truncate(const char *path, int64_t length) { if (IsMetal()) { rc = enosys(); - } else if (!path || (IsAsan() && !__asan_is_valid_str(path))) { + } else if (!path) { rc = efault(); } else if (_weaken(__zipos_parseuri) && _weaken(__zipos_parseuri)(path, &zipname) != -1) { diff --git a/libc/calls/uname.c b/libc/calls/uname.c index 754142794..e61181f20 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -25,7 +25,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/log/log.h" #include "libc/macros.internal.h" @@ -136,7 +135,7 @@ static const char *Str(int rc, const char *s) { */ int uname(struct utsname *uts) { int rc; - if (!uts || (IsAsan() && !__asan_is_valid(uts, sizeof(*uts)))) { + if (!uts) { rc = efault(); } else if (IsLinux()) { struct utsname_linux linux; diff --git a/libc/calls/unlinkat.c b/libc/calls/unlinkat.c index 939c77091..75ecfdcb9 100644 --- a/libc/calls/unlinkat.c +++ b/libc/calls/unlinkat.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -44,10 +43,7 @@ int unlinkat(int dirfd, const char *path, int flags) { int rc; - if (IsAsan() && !__asan_is_valid_str(path)) { - rc = efault(); - } else if (_weaken(__zipos_notat) && - (rc = __zipos_notat(dirfd, path)) == -1) { + if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) { STRACE("zipos unlinkat not supported yet"); } else if (!IsWindows()) { rc = sys_unlinkat(dirfd, path, flags); diff --git a/libc/calls/utimens.c b/libc/calls/utimens.c index 17c489e5c..333b49432 100644 --- a/libc/calls/utimens.c +++ b/libc/calls/utimens.c @@ -17,14 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" -#include "libc/calls/asan.internal.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" @@ -38,10 +36,6 @@ int __utimens(int fd, const char *path, const struct timespec ts[2], struct ZiposUri zipname; if (IsMetal()) { rc = enosys(); - } else if (IsAsan() && ((fd == AT_FDCWD && !__asan_is_valid_str(path)) || - (ts && (!__asan_is_valid_timespec(ts + 0) || - !__asan_is_valid_timespec(ts + 1))))) { - rc = efault(); // bad memory } else if ((flags & ~AT_SYMLINK_NOFOLLOW)) { rc = einval(); // unsupported flag } else if (__isfdkind(fd, kFdZip) || diff --git a/libc/calls/write.c b/libc/calls/write.c index 9ed622ebe..258386df3 100644 --- a/libc/calls/write.c +++ b/libc/calls/write.c @@ -22,7 +22,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/zipos.internal.h" @@ -76,8 +75,6 @@ ssize_t write(int fd, const void *buf, size_t size) { if (fd < 0) { rc = ebadf(); - } else if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = ebadf(); // posix specifies this when not open()'d for writing } else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) { diff --git a/libc/calls/writev.c b/libc/calls/writev.c index b21105315..42d141461 100644 --- a/libc/calls/writev.c +++ b/libc/calls/writev.c @@ -22,7 +22,6 @@ #include "libc/calls/struct/iovec.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/likely.h" #include "libc/intrin/strace.internal.h" @@ -47,8 +46,6 @@ static ssize_t writev_impl(int fd, const struct iovec *iov, int iovlen) { return ebadf(); if (iovlen < 0) return einval(); - if (IsAsan() && !__asan_is_valid_iov(iov, iovlen)) - return efault(); if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) return ebadf(); // posix specifies this when not open()'d for writing diff --git a/libc/dce.h b/libc/dce.h index f67cb0028..53b9098af 100644 --- a/libc/dce.h +++ b/libc/dce.h @@ -55,12 +55,6 @@ #define IsOptimized() 0 #endif -#ifdef __SANITIZE_ADDRESS__ -#define IsAsan() 1 -#else -#define IsAsan() 0 -#endif - #ifdef __aarch64__ #define IsAarch64() 1 #define IsXnuSilicon() IsXnu() diff --git a/libc/dlopen/BUILD.mk b/libc/dlopen/BUILD.mk index 2c254ca8d..4db5aa081 100644 --- a/libc/dlopen/BUILD.mk +++ b/libc/dlopen/BUILD.mk @@ -54,8 +54,6 @@ $(LIBC_DLOPEN_A_OBJS): private \ o/$(MODE)/libc/dlopen/foreign_tramp.o: libc/dlopen/foreign_tramp.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< -$(LIBC_DLOPEN_A_OBJS): private COPTS += -fno-sanitize=address - LIBC_DLOPEN_LIBS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x))) LIBC_DLOPEN_SRCS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_SRCS)) LIBC_DLOPEN_HDRS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_HDRS)) diff --git a/libc/fmt/BUILD.mk b/libc/fmt/BUILD.mk index 2ff357eb9..4114c6ba7 100644 --- a/libc/fmt/BUILD.mk +++ b/libc/fmt/BUILD.mk @@ -55,8 +55,7 @@ $(LIBC_FMT_A).pkg: \ $(LIBC_FMT_A_OBJS): private \ CFLAGS += \ - -fno-jump-tables \ - -fno-sanitize=address + -fno-jump-tables o/$(MODE)/libc/fmt/formatint64.o \ o/$(MODE)/libc/fmt/formatint64thousands.o \ diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 1a25488b3..491aff579 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -176,8 +176,7 @@ typedef struct { #define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0))) #ifndef privileged -#define privileged \ - _Section(".privileged") dontinline dontinstrument dontubsan dontasan +#define privileged _Section(".privileged") dontinline dontinstrument dontubsan #endif #ifndef wontreturn @@ -522,13 +521,6 @@ typedef struct { #define nocallersavedregisters #endif -#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \ - __has_attribute(__no_sanitize_address__)) -#define dontasan __attribute__((__no_sanitize_address__)) -#else -#define dontasan -#endif - #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \ __has_attribute(__no_sanitize_undefined__)) #define dontubsan __attribute__((__no_sanitize_undefined__)) diff --git a/libc/intrin/BUILD.mk b/libc/intrin/BUILD.mk index 1189d5994..f9742c42b 100644 --- a/libc/intrin/BUILD.mk +++ b/libc/intrin/BUILD.mk @@ -62,12 +62,6 @@ o/$(MODE)/libc/intrin/kprintf.o: private \ -Wframe-larger-than=128 \ -Walloca-larger-than=128 -o/$(MODE)/libc/intrin/asan.o: private \ - CFLAGS += \ - -O2 \ - -finline \ - -finline-functions - o//libc/intrin/memmove.o: private \ CFLAGS += \ -fno-toplevel-reorder diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c deleted file mode 100644 index ef3b73c46..000000000 --- a/libc/intrin/asan.c +++ /dev/null @@ -1,1126 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "ape/sections.internal.h" -#include "libc/calls/state.internal.h" -#include "libc/calls/struct/rlimit.h" -#include "libc/calls/struct/rlimit.internal.h" -#include "libc/calls/syscall-sysv.internal.h" -#include "libc/dce.h" -#include "libc/errno.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/atomic.h" -#include "libc/intrin/cmpxchg.h" -#include "libc/intrin/describebacktrace.internal.h" -#include "libc/intrin/directmap.internal.h" -#include "libc/intrin/kprintf.h" -#include "libc/intrin/leaky.internal.h" -#include "libc/intrin/likely.h" -#include "libc/intrin/maps.h" -#include "libc/intrin/strace.internal.h" -#include "libc/intrin/weaken.h" -#include "libc/log/libfatal.internal.h" -#include "libc/log/log.h" -#include "libc/macros.internal.h" -#include "libc/mem/mem.h" -#include "libc/nexgen32e/gc.internal.h" -#include "libc/nexgen32e/stackframe.h" -#include "libc/runtime/memtrack.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/runtime/stack.h" -#include "libc/runtime/symbols.internal.h" -#include "libc/serialize.h" -#include "libc/stdckdint.h" -#include "libc/str/str.h" -#include "libc/str/tab.internal.h" -#include "libc/sysv/consts/auxv.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/prot.h" -#include "libc/sysv/consts/rlim.h" -#include "libc/sysv/consts/rlimit.h" -#include "libc/sysv/errfuns.h" -#include "libc/thread/tls.h" -#include "third_party/dlmalloc/dlmalloc.h" -#ifdef __x86_64__ -#ifdef __SANITIZE_ADDRESS__ - -__static_yoink("_init_asan"); - -/** - * @fileoverview Cosmopolitan Address Sanitizer Runtime. - * - * Someone brilliant at Google figured out a way to improve upon memory - * protection. Rather than invent another Java or Rust they changed GCC - * so it can emit fast code, that checks the validity of each memory op - * with byte granularity, by probing shadow memory. - * - * - AddressSanitizer dedicates one-eighth of the virtual address space - * to its shadow memory and uses a direct mapping with a scale and - * offset to translate an application address to its corresponding - * shadow address. Given the application memory address Addr, the - * address of the shadow byte is computed as (Addr>>3)+Offset." - * - * - We use the following encoding for each shadow byte: 0 means that - * all 8 bytes of the corresponding application memory region are - * addressable; k (1 ≤ k ≤ 7) means that the first k bytes are - * addressible; any negative value indicates that the entire 8-byte - * word is unaddressable. We use different negative values to - * distinguish between different kinds of unaddressable memory (heap - * redzones, stack redzones, global redzones, freed memory). - * - * Here's what the generated code looks like for 64-bit reads: - * - * movq %addr,%tmp - * shrq $3,%tmp - * cmpb $0,0x7fff8000(%tmp) - * jnz abort - * movq (%addr),%dst - */ - -#define RBP __builtin_frame_address(0) - -#define ASAN_LOG(...) (void)0 // kprintf(__VA_ARGS__) - -struct AsanSourceLocation { - char *filename; - int line; - int column; -}; - -struct AsanAccessInfo { - char *addr; - const uintptr_t first_bad_addr; - size_t size; - bool iswrite; - unsigned long ip; -}; - -struct AsanGlobal { - char *addr; - size_t size; - size_t size_with_redzone; - const void *name; - const void *module_name; - unsigned long has_cxx_init; - struct AsanSourceLocation *location; - char *odr_indicator; -}; - -int __asan_option_detect_stack_use_after_return = 0; - -void __asan_version_mismatch_check_v8(void) { -} - -static bool __asan_once(void) { - int want = false; - static atomic_int once; - return atomic_compare_exchange_strong_explicit( - &once, &want, true, memory_order_relaxed, memory_order_relaxed); -} - -static int __asan_bsf(uint64_t x) { - _Static_assert(sizeof(long long) == sizeof(uint64_t), ""); - return __builtin_ctzll(x); -} - -static char *__asan_utf8cpy(char *p, unsigned c) { - uint64_t z; - z = tpenc(c); - do - *p++ = z; - while ((z >>= 8)); - return p; -} - -static char *__asan_stpcpy(char *d, const char *s) { - size_t i; - for (i = 0;; ++i) { - if (!(d[i] = s[i])) { - return d + i; - } - } -} - -dontinstrument void __asan_memset(void *p, char c, size_t n) { - char *b; - size_t i; - uint64_t x; - b = p; - x = 0x0101010101010101ul * (c & 255); - switch (n) { - case 0: - break; - case 1: - __builtin_memcpy(b, &x, 1); - break; - case 2: - __builtin_memcpy(b, &x, 2); - break; - case 3: - __builtin_memcpy(b, &x, 2); - __builtin_memcpy(b + 1, &x, 2); - break; - case 4: - __builtin_memcpy(b, &x, 4); - break; - case 5: - case 6: - case 7: - __builtin_memcpy(b, &x, 4); - __builtin_memcpy(b + n - 4, &x, 4); - break; - case 8: - __builtin_memcpy(b, &x, 8); - break; - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - __builtin_memcpy(b, &x, 8); - __builtin_memcpy(b + n - 8, &x, 8); - break; - default: - i = 0; - do { - __builtin_memcpy(b + i, &x, 8); - asm volatile("" ::: "memory"); - __builtin_memcpy(b + i + 8, &x, 8); - } while ((i += 16) + 16 <= n); - for (; i < n; ++i) - b[i] = x; - break; - } -} - -static void *__asan_mempcpy(void *dst, const void *src, size_t n) { - size_t i; - char *d; - const char *s; - uint64_t a, b; - d = dst; - s = src; - switch (n) { - case 0: - return d; - case 1: - *d = *s; - return d + 1; - case 2: - __builtin_memcpy(&a, s, 2); - __builtin_memcpy(d, &a, 2); - return d + 2; - case 3: - __builtin_memcpy(&a, s, 2); - __builtin_memcpy(&b, s + 1, 2); - __builtin_memcpy(d, &a, 2); - __builtin_memcpy(d + 1, &b, 2); - return d + 3; - case 4: - __builtin_memcpy(&a, s, 4); - __builtin_memcpy(d, &a, 4); - return d + 4; - case 5: - case 6: - case 7: - __builtin_memcpy(&a, s, 4); - __builtin_memcpy(&b, s + n - 4, 4); - __builtin_memcpy(d, &a, 4); - __builtin_memcpy(d + n - 4, &b, 4); - return d + n; - case 8: - __builtin_memcpy(&a, s, 8); - __builtin_memcpy(d, &a, 8); - return d + 8; - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - __builtin_memcpy(&a, s, 8); - __builtin_memcpy(&b, s + n - 8, 8); - __builtin_memcpy(d, &a, 8); - __builtin_memcpy(d + n - 8, &b, 8); - return d + n; - default: - i = 0; - do { - __builtin_memcpy(&a, s + i, 8); - asm volatile("" ::: "memory"); - __builtin_memcpy(d + i, &a, 8); - } while ((i += 8) + 8 <= n); - for (; i < n; ++i) - d[i] = s[i]; - return d + i; - } -} - -void *__asan_memcpy(void *dst, const void *src, size_t n) { - __asan_mempcpy(dst, src, n); - return dst; -} - -static char *__asan_hexcpy(char *p, uint64_t x, uint8_t k) { - while (k) - *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; - return p; -} - -static void __asan_exit(void) { - kprintf("your asan runtime needs\n" - "\t__static_yoink(\"__die\");\n" - "in order to show you backtraces\n"); - _Exit(99); -} - -__wur __asan_die_f *__asan_die(void) { - if (_weaken(__die)) { - return _weaken(__die); - } else { - return __asan_exit; - } -} - -static wontreturn void __asan_require_failed(const char *func) { - kprintf("error: asan needs %s\n", func); - __asan_die()(); - __asan_unreachable(); -} - -static bool __asan_overlaps_shadow_space(const void *p, size_t n) { - intptr_t BegA, EndA, BegB, EndB; - if (n) { - BegA = (intptr_t)p; - EndA = BegA + n; - BegB = 0x7fff0000; - EndB = 0x100080000000; - return MAX(BegA, BegB) < MIN(EndA, EndB); - } else { - return 0; - } -} - -void __asan_unpoison(void *p, long n) { - signed char k, *s; - k = (intptr_t)p & 7; - s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000); - if (UNLIKELY(k)) { - if (k + n < 8) { - if (n > 0) - *s = MAX(*s, k + n); - return; - } - n -= MIN(8 - k, n); - *s++ = 0; - } - __asan_memset(s, 0, n >> 3); - if ((k = n & 7)) { - s += n >> 3; - if (*s < 0) - *s = k; - if (*s > 0) - *s = MAX(*s, k); - } -} - -dontinstrument void __asan_poison(void *p, long n, signed char t) { - signed char k, *s; - s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000); - if ((k = (intptr_t)p & 7)) { - if ((!*s && n >= 8 - k) || *s > k) - *s = k; - n -= MIN(8 - k, n); - s += 1; - } - __asan_memset(s, t, n >> 3); - if ((k = n & 7)) { - s += n >> 3; - if (*s < 0 || (*s > 0 && *s <= k)) - *s = t; - } -} - -static void __asan_poison_safe(char *p, long n, signed char t) { - int granularity = __granularity(); - int chunk = granularity << 3; - while (n > 0) { - char *block = (char *)((uintptr_t)p & -chunk); - signed char *shadow = (signed char *)(((uintptr_t)block >> 3) + 0x7fff8000); - if (__asan_is_mapped(shadow)) { - char *start = MAX(p, block); - size_t bytes = MIN(n, chunk); - __asan_poison(start, bytes, t); - } - p += chunk; - n -= chunk; - } -} - -privileged static bool __asan_is_mapped_unlocked(const char *addr) { - struct Dll *e, *e2; - for (e = dll_first(__maps.used); e; e = e2) { - e2 = dll_next(__maps.used, e); - struct Map *map = MAP_CONTAINER(e); - if (map->addr <= addr && addr < map->addr + map->size) { - dll_remove(&__maps.used, e); - dll_make_first(&__maps.used, e); - return true; - } - } - return false; -} - -privileged bool __asan_is_mapped(const void *addr) { - bool32 res; - __maps_lock(); - res = __asan_is_mapped_unlocked(addr); - __maps_unlock(); - return res; -} - -static void __asan_ensure_shadow_is_mapped(void *addr, size_t size) { - int m = 0x7fff8000; - int g = __granularity(); - size_t n = (size + 7) & -8; - char *p = (char *)((((uintptr_t)addr >> 3) + m) & -g); - char *pe = (char *)(((((uintptr_t)(addr + n) >> 3) + m) + g - 1) & -g); - for (char *pm = p; p < pe; p = pm) { - pm += g; - if (!__asan_is_mapped(p)) { - while (pm < pe && !__asan_is_mapped(pm)) - pm += g; - if (__mmap(p, pm - p, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) != MAP_FAILED) - __asan_memset(p, kAsanUnmapped, pm - p); - } - } -} - -void __asan_shadow(void *addr, size_t size) { - if (!__asan_overlaps_shadow_space(addr, size)) { - __asan_ensure_shadow_is_mapped(addr, size); - __asan_unpoison(addr, size); - } -} - -void __asan_unshadow(void *addr, size_t size) { - if (!__asan_overlaps_shadow_space(addr, size)) { - __asan_poison_safe(addr, size, kAsanUnmapped); - } -} - -static bool __asan_is_image(const unsigned char *p) { - return __executable_start <= p && p < _end; -} - -static bool __asan_exists(const void *x) { - return !kisdangerous(x); -} - -static struct AsanFault __asan_fault(const signed char *s, signed char dflt) { - struct AsanFault r; - if (s[0] < 0) { - r.kind = s[0]; - } else if (((uintptr_t)(s + 1) & 4095) && s[1] < 0) { - r.kind = s[1]; - } else { - r.kind = dflt; - } - r.shadow = s; - return r; -} - -static struct AsanFault __asan_checka(const signed char *s, long ndiv8) { - uint64_t w; - int g = __granularity(); - const signed char *o = s; - const signed char *e = s + ndiv8; - for (; ((intptr_t)s & 7) && s < e; ++s) { - if (*s) - return __asan_fault(s - 1, kAsanHeapOverrun); - } - for (; s + 8 <= e; s += 8) { - if (UNLIKELY(!((intptr_t)s & (g - 1))) && kisdangerous(s)) { - return (struct AsanFault){kAsanUnmapped, s}; - } - if ((w = READ64LE(s))) { - s += __asan_bsf(w) >> 3; - return __asan_fault(s, kAsanHeapOverrun); - } - } - for (; s < e; ++s) { - if (*s) - return __asan_fault(s > o ? s - 1 : s, kAsanHeapOverrun); - } - return (struct AsanFault){0}; -} - -/** - * Checks validity of memory range. - * - * This is normally abstracted by the compiler. In some cases, it may be - * desirable to perform an ASAN memory safety check explicitly, e.g. for - * system call wrappers that need to vet memory passed to the kernel, or - * string library routines that use the `dontasan` keyword due to compiler - * generated ASAN being too costly. This function is fast especially for - * large memory ranges since this takes a few picoseconds for each byte. - * - * @param p is starting virtual address - * @param n is number of bytes to check - * @return kind is 0 on success or <0 if invalid - * @return shadow points to first poisoned shadow byte - */ -struct AsanFault __asan_check(const void *p, long n) { - struct AsanFault f; - signed char c, k, *s; - if (n > 0) { - k = (intptr_t)p & 7; - s = SHADOW(p); - if (__asan_overlaps_shadow_space(p, n)) { - return (struct AsanFault){kAsanProtected, s}; - } else if (kisdangerous(s)) { - return (struct AsanFault){kAsanUnmapped, s}; - } - if (UNLIKELY(k)) { - if (!(c = *s)) { - n -= MIN(8 - k, n); - s += 1; - } else if (c > 0 && n < 8 && c >= k + n) { - return (struct AsanFault){0}; - } else { - return __asan_fault(s, kAsanHeapOverrun); - } - } - k = n & 7; - n >>= 3; - if ((f = __asan_checka(s, n)).kind) { - return f; - } else if (!k || !(c = s[n]) || k <= c) { - return (struct AsanFault){0}; - } else { - return __asan_fault(s, kAsanHeapOverrun); - } - } else if (!n) { - return (struct AsanFault){0}; - } else { - return (struct AsanFault){kAsanNullPage, 0}; - } -} - -/** - * Checks validity of nul-terminated string. - * - * This is similar to `__asan_check(p, 1)` except it checks the validity - * of the entire string including its trailing nul byte, and goes faster - * than calling strlen() beforehand. - * - * @param p is starting virtual address - * @param n is number of bytes to check - * @return kind is 0 on success or <0 if invalid - * @return shadow points to first poisoned shadow byte - */ -struct AsanFault __asan_check_str(const char *p) { - uint64_t w; - signed char c, k, *s; - int g = __granularity(); - s = SHADOW(p); - if (__asan_overlaps_shadow_space(p, 1)) { - return (struct AsanFault){kAsanProtected, s}; - } - if (kisdangerous(s)) { - return (struct AsanFault){kAsanUnmapped, s}; - } - if ((k = (intptr_t)p & 7)) { - do { - if ((c = *s) && c < k + 1) { - return __asan_fault(s, kAsanHeapOverrun); - } - if (!*p++) { - return (struct AsanFault){0}; - } - } while ((k = (intptr_t)p & 7)); - ++s; - } - for (;; ++s, p += 8) { - if (UNLIKELY(!((intptr_t)s & (g - 1))) && kisdangerous(s)) { - return (struct AsanFault){kAsanUnmapped, s}; - } - if ((c = *s) < 0) { - return (struct AsanFault){c, s}; - } - w = *(const uint64_t *)p; - if (!(w = ~w & (w - 0x0101010101010101) & 0x8080808080808080)) { - if (c > 0) { - return __asan_fault(s, kAsanHeapOverrun); - } - } else { - k = (unsigned)__builtin_ctzll(w) >> 3; - if (!c || c > k) { - return (struct AsanFault){0}; - } else { - return __asan_fault(s, kAsanHeapOverrun); - } - } - } -} - -/** - * Checks memory validity of memory region. - */ -bool __asan_is_valid(const void *p, long n) { - struct AsanFault f; - f = __asan_check(p, n); - return !f.kind; -} - -/** - * Checks memory validity of nul-terminated string. - */ -bool __asan_is_valid_str(const char *p) { - struct AsanFault f; - f = __asan_check_str(p); - return !f.kind; -} - -/** - * Checks memory validity of null-terminated nul-terminated string list. - */ -bool __asan_is_valid_strlist(char *const *p) { - for (;; ++p) { - if (!__asan_is_valid(p, sizeof(char *))) - return false; - if (!*p) - return true; - if (!__asan_is_valid_str(*p)) - return false; - } -} - -/** - * Checks memory validity of `iov` array and each buffer it describes. - */ -bool __asan_is_valid_iov(const struct iovec *iov, int iovlen) { - int i; - size_t size; - if (iovlen >= 0 && !ckd_mul(&size, iovlen, sizeof(struct iovec)) && - __asan_is_valid(iov, size)) { - for (i = 0; i < iovlen; ++i) { - if (!__asan_is_valid(iov[i].iov_base, iov[i].iov_len)) { - return false; - } - } - return true; - } else { - return false; - } -} - -static wint_t __asan_symbolize_access_poison(signed char kind) { - switch (kind) { - case kAsanNullPage: - return L'∅'; - case kAsanProtected: - return L'P'; - case kAsanHeapFree: - return L'F'; - case kAsanHeapRelocated: - return L'R'; - case kAsanAllocaOverrun: - return L'𝑂'; - case kAsanHeapUnderrun: - return L'U'; - case kAsanHeapOverrun: - return L'O'; - case kAsanStackUnscoped: - return L's'; - case kAsanStackOverflow: - return L'!'; - case kAsanGlobalOrder: - return L'I'; - case kAsanStackFree: - return L'r'; - case kAsanStackPartial: - return L'p'; - case kAsanStackOverrun: - return L'o'; - case kAsanStackMiddle: - return L'm'; - case kAsanStackUnderrun: - return L'u'; - case kAsanAllocaUnderrun: - return L'𝑈'; - case kAsanUnmapped: - return L'M'; - case kAsanGlobalRedzone: - return L'G'; - case kAsanGlobalGone: - return L'𝐺'; - case kAsanGlobalUnderrun: - return L'μ'; - case kAsanGlobalOverrun: - return L'Ω'; - case kAsanMmapSizeOverrun: - return L'Z'; - default: - return L'?'; - } -} - -static const char *__asan_describe_access_poison(signed char kind) { - switch (kind) { - case kAsanNullPage: - return "null pointer dereference"; - case kAsanProtected: - return "protected"; - case kAsanHeapFree: - return "heap use after free"; - case kAsanHeapRelocated: - return "heap use after relocate"; - case kAsanAllocaOverrun: - return "alloca overflow"; - case kAsanHeapUnderrun: - return "heap underrun"; - case kAsanHeapOverrun: - return "heap overrun"; - case kAsanStackUnscoped: - return "stack use after scope"; - case kAsanStackOverflow: - return "stack overflow"; - case kAsanGlobalOrder: - return "global init order"; - case kAsanStackFree: - return "stack use after return"; - case kAsanStackPartial: - return "stack partial"; - case kAsanStackOverrun: - return "stack overrun"; - case kAsanStackMiddle: - return "stack middle"; - case kAsanStackUnderrun: - return "stack underflow"; - case kAsanAllocaUnderrun: - return "alloca underflow"; - case kAsanUnmapped: - return "unmapped"; - case kAsanGlobalRedzone: - return "global redzone"; - case kAsanGlobalGone: - return "global gone"; - case kAsanGlobalUnderrun: - return "global underrun"; - case kAsanGlobalOverrun: - return "global overrun"; - default: - return "poisoned"; - } -} - -static char *__asan_format_interval(char *p, intptr_t a, intptr_t b) { - p = __asan_hexcpy(p, a, 48), *p++ = '-'; - p = __asan_hexcpy(p, b, 48); - return p; -} - -static char *__asan_format_section(char *p, const void *p1, const void *p2, - const char *name, const void *addr) { - intptr_t a, b; - if ((a = (intptr_t)p1) < (b = (intptr_t)p2)) { - p = __asan_format_interval(p, a, b), *p++ = ' '; - p = __asan_stpcpy(p, name); - if (a <= (intptr_t)addr && (intptr_t)addr <= b) { - p = __asan_stpcpy(p, " ←address"); - } - *p++ = '\n'; - } - return p; -} - -void __asan_report_memory_origin_image(intptr_t a, int z) { - unsigned l, m, r, n, k; - struct SymbolTable *st; - kprintf("\nthe memory belongs to image symbols\n"); - if (_weaken(GetSymbolTable)) { - if ((st = _weaken(GetSymbolTable)())) { - l = 0; - r = n = st->count; - k = a - st->addr_base; - while (l < r) { - m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2) - if (st->symbols[m].y < k) { - l = m + 1; - } else { - r = m; - } - } - for (; l < n; ++l) { - if ((st->symbols[l].x <= k && k <= st->symbols[l].y) || - (st->symbols[l].x <= k + z && k + z <= st->symbols[l].y) || - (k < st->symbols[l].x && st->symbols[l].y < k + z)) { - kprintf("\t%s [%#x,%#x] size %'d\n", st->name_base + st->names[l], - st->addr_base + st->symbols[l].x, - st->addr_base + st->symbols[l].y, - st->symbols[l].y - st->symbols[l].x + 1); - } else { - break; - } - } - } else { - kprintf("\tunknown please supply .dbg symbols or set COMDBG\n"); - } - } else { - kprintf("\tunknown please __static_yoink(\"GetSymbolTable\");\n"); - } -} - -void __asan_report_memory_origin(const unsigned char *addr, int size, - signed char kind) { - switch (kind) { - case kAsanStackOverrun: - case kAsanGlobalOverrun: - case kAsanAllocaOverrun: - case kAsanHeapOverrun: - addr -= 1; - size += 1; - break; - case kAsanHeapUnderrun: - case kAsanStackUnderrun: - case kAsanAllocaUnderrun: - case kAsanGlobalUnderrun: - size += 1; - break; - case kAsanGlobalRedzone: - addr -= 1; - size += 2; - break; - default: - break; - } - if (__executable_start <= addr && addr < _end) { - __asan_report_memory_origin_image((intptr_t)addr, size); - /* } else if (IsAutoFrame((intptr_t)addr >> 16)) { */ - /* if (_weaken(__asan_report_memory_origin_heap)) */ - /* _weaken(__asan_report_memory_origin_heap)(addr, size); */ - } -} - -static __wur __asan_die_f *__asan_report(const void *addr, int size, - const char *message, - signed char kind) { -#pragma GCC push_options -#pragma GCC diagnostic ignored "-Wframe-larger-than=" - char buf[8192]; - CheckLargeStackAllocation(buf, sizeof(buf)); -#pragma GCC pop_options - int i; - wint_t c; - signed char t; - uint64_t z; - char *base, *q, *p = buf; - ftrace_enabled(-1); - kprintf("\n\e[J\e[1;31masan error\e[0m: %s %d-byte %s at %p shadow %p\n", - __asan_describe_access_poison(kind), size, message, addr, - SHADOW(addr)); - if (0 < size && size < 80) { - base = (char *)addr - ((80 >> 1) - (size >> 1)); - for (i = 0; i < 80; ++i) { - if ((char *)addr <= base + i && base + i < (char *)addr + size) { - if (__asan_is_valid(base + i, 1)) { - *p++ = '*'; - } else { - *p++ = 'x'; - } - } else { - *p++ = ' '; - } - } - *p++ = '\n'; - for (c = i = 0; i < 80; ++i) { - if (!(t = __asan_check(base + i, 1).kind)) { - if (c != 32) { - *p++ = '\e', *p++ = '[', *p++ = '3', *p++ = '2', *p++ = 'm'; - c = 32; - } - *p++ = '.'; - } else { - if (c != 31) { - *p++ = '\e', *p++ = '[', *p++ = '3', *p++ = '1', *p++ = 'm'; - c = 31; - } - p = __asan_utf8cpy(p, __asan_symbolize_access_poison(t)); - } - } - *p++ = '\e', *p++ = '[', *p++ = '3', *p++ = '9', *p++ = 'm'; - *p++ = '\n'; - for (i = 0; (intptr_t)(base + i) & 7; ++i) - *p++ = ' '; - for (; i + 8 <= 80; i += 8) { - q = p + 8; - *p++ = '|'; - z = ((intptr_t)(base + i) >> 3) + 0x7fff8000; - if (!kisdangerous((void *)z)) { - p = __intcpy(p, *(signed char *)z); - } else { - *p++ = '!'; - } - while (p < q) { - *p++ = ' '; - } - } - for (; i < 80; ++i) - *p++ = ' '; - *p++ = '\n'; - for (i = 0; i < 80; ++i) { - p = __asan_utf8cpy(p, __asan_exists(base + i) - ? kCp437[((unsigned char *)base)[i]] - : L'⋅'); - } - *p++ = '\n'; - } - p = __asan_format_section(p, __executable_start, _etext, ".text", addr); - p = __asan_format_section(p, _etext, _edata, ".data", addr); - p = __asan_format_section(p, _end, _edata, ".bss", addr); - __maps_lock(); - struct Dll *e, *e2; - for (e = dll_first(__maps.used); e; e = e2) { - e2 = dll_next(__maps.used, e); - struct Map *map = MAP_CONTAINER(e); - p = __asan_format_interval(p, (uintptr_t)map->addr, - (uintptr_t)map->addr + map->size); - if (!__asan_overlaps_shadow_space(map->addr, map->size)) - p = __asan_stpcpy(p, " ←address"); - else - p = __asan_stpcpy(p, " ←shadow"); - *p++ = '\n'; - } - __maps_unlock(); - *p = 0; - kprintf("%s", buf); - __asan_report_memory_origin(addr, size, kind); - kprintf("\nthe crash was caused by %s\n", program_invocation_name); - ftrace_enabled(+1); - return __asan_die(); -} - -static wontreturn void __asan_verify_failed(const void *p, size_t n, - struct AsanFault f) { - const char *q; - q = UNSHADOW(f.shadow); - if ((uintptr_t)q != ((uintptr_t)p & -8) && (uintptr_t)q - (uintptr_t)p < n) { - n -= (uintptr_t)q - (uintptr_t)p; - p = q; - } - __asan_report(p, n, "verify", f.kind)(); - __asan_unreachable(); -} - -void __asan_verify(const void *p, size_t n) { - struct AsanFault f; - if (!(f = __asan_check(p, n)).kind) - return; - __asan_verify_failed(p, n, f); -} - -void __asan_verify_str(const char *p) { - struct AsanFault f; - if (!(f = __asan_check_str(p)).kind) - return; - __asan_verify_failed(UNSHADOW(f.shadow), 8, f); -} - -static __wur __asan_die_f *__asan_report_memory_fault(void *addr, int size, - const char *message) { - return __asan_report(addr, size, message, - __asan_fault(SHADOW(addr), -128).kind); -} - -void __asan_rawtrace(struct AsanTrace *bt, const struct StackFrame *bp) { - size_t i; - for (i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) { - if (kisdangerous(bp)) - break; - bt->p[i] = bp->addr; - } - for (; i < ARRAYLEN(bt->p); ++i) { - bt->p[i] = 0; - } -} - -static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) { - int f1, f2; - size_t i, gi; - intptr_t addr; - struct Garbages *garbage; - garbage = __tls_enabled ? __get_tls()->tib_garbages : 0; - gi = garbage ? garbage->i : 0; - for (f1 = -1, i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) { - if (f1 != (f2 = ((intptr_t)bp >> 16))) { - if (kisdangerous(bp)) - break; - f1 = f2; - } - if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) { - addr = bp->addr; -#ifdef __x86_64__ - if (addr == (uintptr_t)_weaken(__gc) && (uintptr_t)_weaken(__gc)) { - do - --gi; - while ((addr = garbage->p[gi].ret) == (uintptr_t)_weaken(__gc)); - } -#endif - bt->p[i] = addr; - } else { - break; - } - } - for (; i < ARRAYLEN(bt->p); ++i) { - bt->p[i] = 0; - } -} - -void __asan_register_globals(struct AsanGlobal g[], int n) { - int i; - __asan_poison(g, sizeof(*g) * n, kAsanProtected); - for (i = 0; i < n; ++i) { - __asan_poison(g[i].addr + g[i].size, g[i].size_with_redzone - g[i].size, - kAsanGlobalRedzone); - if (g[i].location) { - __asan_poison(g[i].location, sizeof(*g[i].location), kAsanProtected); - } - } -} - -void __asan_unregister_globals(struct AsanGlobal g[], int n) { - int i; - for (i = 0; i < n; ++i) { - __asan_poison(g[i].addr, g[i].size, kAsanGlobalGone); - } -} - -void __asan_evil(uint8_t *addr, int size, const char *s) { - struct AsanTrace tr; - __asan_rawtrace(&tr, RBP); - kprintf("WARNING: ASAN bad %d byte %s at %lx bt %x %x %x\n", size, s, addr, - tr.p[0], tr.p[1], tr.p[2], tr.p[3]); -} - -void __asan_report_load(uint8_t *addr, int size) { - __asan_evil(addr, size, "load"); - if (!__vforked && __asan_once()) { - __asan_report_memory_fault(addr, size, "load")(); - } - __asan_unreachable(); -} - -void __asan_report_store(uint8_t *addr, int size) { - __asan_evil(addr, size, "store"); - if (!__vforked && __asan_once()) { - __asan_report_memory_fault(addr, size, "store")(); - } - __asan_unreachable(); -} - -void __asan_handle_no_return(void) { - // this check is stupid and has far-reaching toilsome ramifications -} - -void __asan_poison_stack_memory(char *addr, size_t size) { - ASAN_LOG("__asan_poison_stack_memory(%p, %zu)\n", addr, size); - __asan_poison(addr, size, kAsanStackFree); -} - -void __asan_unpoison_stack_memory(char *addr, size_t size) { - ASAN_LOG("__asan_unpoison_stack_memory(%p, %zu)\n", addr, size); - __asan_unpoison(addr, size); -} - -void __asan_alloca_poison(char *addr, uintptr_t size) { - ASAN_LOG("__asan_alloca_poison(%p, %zu)\n", addr, size); - size_t rounded_up_size = ROUNDUP(size, 8); - size_t padding_size = ROUNDUP(size, 32) - rounded_up_size; - size_t rounded_down_size = ROUNDDOWN(size, 8); - char *left_redzone = addr - 32; - void *right_redzone = addr + rounded_up_size; - __asan_unpoison(addr + rounded_down_size, size - rounded_down_size); - __asan_poison(left_redzone, 32, kAsanAllocaUnderrun); - __asan_poison(right_redzone, padding_size + 32, kAsanAllocaOverrun); -} - -void __asan_allocas_unpoison(uintptr_t x, uintptr_t y) { - ASAN_LOG("__asan_allocas_unpoison(%p, %p)\n", x, y); - if (!x || x > y) - return; - __asan_unpoison((char *)x, y - x); -} - -void *__asan_addr_is_in_fake_stack(void *fakestack, void *addr, void **beg, - void **end) { - ASAN_LOG("__asan_addr_is_in_fake_stack(%p)\n", addr); - return 0; -} - -void *__asan_get_current_fake_stack(void) { - ASAN_LOG("__asan_get_current_fake_stack()\n"); - return 0; -} - -void __sanitizer_annotate_contiguous_container(char *beg, char *end, - char *old_mid, char *new_mid) { - ASAN_LOG("__sanitizer_annotate_contiguous_container()\n"); - // the c++ stl uses this - // TODO(jart): make me faster - __asan_unpoison(beg, new_mid - beg); - __asan_poison(new_mid, end - new_mid, kAsanHeapOverrun); -} - -void __asan_before_dynamic_init(const char *module_name) { - ASAN_LOG("__asan_before_dynamic_init()\n"); -} - -void __asan_after_dynamic_init(void) { - ASAN_LOG("__asan_after_dynamic_init()\n"); -} - -void __asan_init(void) { - static bool once; - if (once) - return; - once = true; - - __asan_shadow(0, 4096); - __asan_shadow(__maps.stack.addr, __maps.stack.size); - __asan_shadow(__executable_start, _end - __executable_start); - __asan_poison((void *)__veil("r", 0L), getauxval(AT_PAGESZ), kAsanNullPage); - STRACE(" _ ____ _ _ _ "); - STRACE(" / \\ / ___| / \\ | \\ | |"); - STRACE(" / _ \\ \\___ \\ / _ \\ | \\| |"); - STRACE(" / ___ \\ ___) / ___ \\| |\\ |"); - STRACE("/_/ \\_\\____/_/ \\_\\_| \\_|"); - STRACE("cosmopolitan memory safety module initialized"); -} - -__weak_reference(__asan_poison, __asan_poison_memory_region); -__weak_reference(__asan_unpoison, __asan_unpoison_memory_region); - -#endif /* __SANITIZE_ADDRESS__ */ -#endif /* __x86_64__ */ diff --git a/libc/intrin/asan.internal.h b/libc/intrin/asan.internal.h deleted file mode 100644 index ffe0f2d27..000000000 --- a/libc/intrin/asan.internal.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ -#define COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ -#include "libc/calls/struct/iovec.h" -#include "libc/intrin/asancodes.h" -#include "libc/macros.internal.h" -#include "libc/nexgen32e/stackframe.h" -COSMOPOLITAN_C_START_ - -#ifdef MODE_DBG -// MODE=dbg -// O(32mb) of morgue memory -// Θ(64) bytes of malloc overhead -#define ASAN_MORGUE_ITEMS 512 -#define ASAN_MORGUE_THRESHOLD 65536 -#define ASAN_TRACE_ITEMS 16 -#else -// MODE=asan -// O(32mb) of morgue memory -// Θ(32) bytes of malloc overhead -#define ASAN_MORGUE_ITEMS 512 -#define ASAN_MORGUE_THRESHOLD 65536 -#define ASAN_TRACE_ITEMS 4 -#endif - -#define SHADOW(x) ((signed char *)(((intptr_t)(x) >> kAsanScale) + kAsanMagic)) -#define UNSHADOW(x) ((void *)(MAX(0, (intptr_t)(x) - kAsanMagic) << kAsanScale)) - -#define __asan_unreachable() \ - do { \ - kprintf("%s:%d: __asan_unreachable()\n", __FILE__, __LINE__); \ - __builtin_trap(); \ - } while (0) - -typedef void __asan_die_f(void); - -struct AsanFault { - signed char kind; - const signed char *shadow; -}; - -struct AsanTrace { - uint32_t p[ASAN_TRACE_ITEMS]; // assumes linkage into 32-bit space -}; - -void __asan_unpoison(void *, long); -void __asan_poison(void *, long, signed char); -void __asan_verify(const void *, size_t); -void __asan_verify_str(const char *); -void __asan_shadow(void *, size_t); -void __asan_unshadow(void *, size_t); -bool __asan_is_valid(const void *, long) nosideeffect; -bool __asan_is_valid_str(const char *) nosideeffect; -bool __asan_is_valid_strlist(char *const *) nosideeffect; -bool __asan_is_valid_iov(const struct iovec *, int) nosideeffect; -struct AsanFault __asan_check(const void *, long) nosideeffect; -struct AsanFault __asan_check_str(const char *) nosideeffect; - -int __asan_is_leaky(void *); -int __asan_print_trace(void *); -bool __asan_is_mapped(const void *); -__asan_die_f *__asan_die(void) __wur; -void __asan_memset(void *, char, size_t); -size_t __asan_get_heap_size(const void *); -void *__asan_memcpy(void *, const void *, size_t); -void __asan_rawtrace(struct AsanTrace *, const struct StackFrame *); -void __asan_report_memory_origin(const unsigned char *, int, signed char); -void __asan_report_memory_origin_image(intptr_t, int); -void __asan_report_memory_origin_heap(const unsigned char *, int); - -COSMOPOLITAN_C_END_ -#endif /* COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ */ diff --git a/libc/intrin/asancodes.h b/libc/intrin/asancodes.h deleted file mode 100644 index f5de56027..000000000 --- a/libc/intrin/asancodes.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_ -#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_ - -#define kAsanScale 3 -#define kAsanMagic 0x7fff8000 -#define kAsanNullPage -1 /* ∅ 0xff */ -#define kAsanProtected -2 /* P 0xfe */ -#define kAsanHeapFree -3 /* F 0xfd */ -#define kAsanHeapRelocated -4 /* R 0xfc */ -#define kAsanAllocaOverrun -5 /* 𝑂 0xfb */ -#define kAsanHeapUnderrun -6 /* U 0xfa */ -#define kAsanHeapOverrun -7 /* O 0xf9 */ -#define kAsanStackUnscoped -8 /* s 0xf8 */ -#define kAsanStackOverflow -9 /* ! 0xf7 */ -#define kAsanGlobalOrder -10 /* I 0xf6 */ -#define kAsanStackFree -11 /* r 0xf5 */ -#define kAsanStackPartial -12 /* p 0xf4 */ -#define kAsanStackOverrun -13 /* o 0xf3 */ -#define kAsanStackMiddle -14 /* m 0xf2 */ -#define kAsanStackUnderrun -15 /* u 0xf1 */ -#define kAsanAllocaUnderrun -16 /* 𝑈 0xf0 */ -#define kAsanUnmapped -17 /* M 0xef */ -#define kAsanGlobalRedzone -18 /* G 0xee */ -#define kAsanGlobalGone -19 /* 𝐺 0xed */ -#define kAsanGlobalUnderrun -20 /* μ 0xec */ -#define kAsanGlobalOverrun -21 /* Ω 0xeb */ -#define kAsanMmapSizeOverrun -22 /* Z 0xea */ - -#endif /* COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_ */ diff --git a/libc/intrin/asaninit.S b/libc/intrin/asaninit.S deleted file mode 100644 index 0b906ce84..000000000 --- a/libc/intrin/asaninit.S +++ /dev/null @@ -1,31 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - - .init.start 303,_init_asan -#ifdef __x86_64__ -#ifdef __SANITIZE_ADDRESS__ - push %rdi - push %rsi - call __asan_init - pop %rsi - pop %rdi -#endif /* __SANITIZE_ADDRESS__ */ -#endif /* __x86_64__ */ - .init.end 303,_init_asan diff --git a/libc/intrin/describefdset.c b/libc/intrin/describefdset.c index 338121b2e..1ef26444d 100644 --- a/libc/intrin/describefdset.c +++ b/libc/intrin/describefdset.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/bsr.h" #include "libc/intrin/kprintf.h" #include "libc/sock/select.h" @@ -32,8 +31,7 @@ const char *(DescribeFdSet)(char buf[N], ssize_t rc, int nfds, fd_set *fds) { if (!fds) return "NULL"; - if ((!IsAsan() && kisdangerous(fds)) || - (IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) { + if (kisdangerous(fds)) { ksnprintf(buf, N, "%p", fds); return buf; } diff --git a/libc/intrin/describeflock.c b/libc/intrin/describeflock.c index 83aea89bf..c2399e583 100644 --- a/libc/intrin/describeflock.c +++ b/libc/intrin/describeflock.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/flock.h" #include "libc/calls/struct/flock.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/sysv/consts/f.h" @@ -33,8 +32,7 @@ const char *(DescribeFlock)(char buf[N], int cmd, const struct flock *l) { if (!l) return "NULL"; - if ((!IsAsan() && kisdangerous(l)) || - (IsAsan() && !__asan_is_valid(l, sizeof(*l)))) { + if (kisdangerous(l)) { ksnprintf(buf, N, "%p", l); return buf; } diff --git a/libc/intrin/describegidlist.c b/libc/intrin/describegidlist.c index e6487986a..d35e9db87 100644 --- a/libc/intrin/describegidlist.c +++ b/libc/intrin/describegidlist.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/groups.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/popcnt.h" #include "libc/macros.internal.h" @@ -34,8 +33,7 @@ const char *(DescribeGidList)(char buf[N], int rc, int size, return "{}"; if (!list) return "NULL"; - if ((!IsAsan() && kisdangerous(list)) || - (IsAsan() && !__asan_is_valid(list, size * sizeof(list[0])))) { + if (kisdangerous(list)) { ksnprintf(buf, N, "%p", list); return buf; } diff --git a/libc/intrin/describeiovec.c b/libc/intrin/describeiovec.c index c687f0d2f..2f1e97350 100644 --- a/libc/intrin/describeiovec.c +++ b/libc/intrin/describeiovec.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/limits.h" #include "libc/macros.internal.h" @@ -39,8 +38,7 @@ const char *(DescribeIovec)(char buf[N], ssize_t rc, const struct iovec *iov, return "n/a"; if (rc == -2) rc = SSIZE_MAX; - if ((!IsAsan() && kisdangerous(iov)) || - (IsAsan() && !__asan_is_valid(iov, sizeof(*iov) * iovlen))) { + if (kisdangerous(iov)) { ksnprintf(buf, N, "%p", iov); return buf; } diff --git a/libc/intrin/describeiovnt.c b/libc/intrin/describeiovnt.c index 8e3827bf2..1f94bc5d2 100644 --- a/libc/intrin/describeiovnt.c +++ b/libc/intrin/describeiovnt.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" @@ -25,8 +24,7 @@ void DescribeIovNt(const struct NtIovec *iov, uint32_t iovlen, ssize_t rem) { int i; - if ((!IsAsan() && kisdangerous(iov)) || - (IsAsan() && !__asan_is_valid(iov, iovlen * sizeof(struct NtIovec)))) { + if (kisdangerous(iov)) { kprintf("%p", iov); return; } diff --git a/libc/intrin/describeitimerval.c b/libc/intrin/describeitimerval.c index 4088b4cf4..9ea8ff455 100644 --- a/libc/intrin/describeitimerval.c +++ b/libc/intrin/describeitimerval.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" @@ -32,8 +31,7 @@ const char *(DescribeItimerval)(char buf[N], int rc, return "NULL"; if (rc == -1) return "n/a"; - if ((!IsAsan() && kisdangerous(it)) || - (IsAsan() && !__asan_is_valid(it, sizeof(*it)))) { + if (kisdangerous(it)) { ksnprintf(buf, N, "%p", it); } else { ksnprintf(buf, N, "{%s, %s}", DescribeTimeval(0, &it->it_interval), diff --git a/libc/intrin/describepollfds.c b/libc/intrin/describepollfds.c index 92be225c7..941fa09e2 100644 --- a/libc/intrin/describepollfds.c +++ b/libc/intrin/describepollfds.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/limits.h" @@ -36,8 +35,7 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds, if (!fds) return "NULL"; - if ((!IsAsan() && kisdangerous(fds)) || - (IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) { + if (kisdangerous(fds)) { ksnprintf(buf, N, "%p", fds); return buf; } diff --git a/libc/intrin/describerlimit.c b/libc/intrin/describerlimit.c index ebc85feec..79d9a7d46 100644 --- a/libc/intrin/describerlimit.c +++ b/libc/intrin/describerlimit.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/rlimit.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/strace.internal.h" @@ -27,8 +26,7 @@ const char *DescribeRlimit(char buf[64], int rc, const struct rlimit *rlim) { return "n/a"; if (!rlim) return "NULL"; - if ((!IsAsan() && kisdangerous(rlim)) || - (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { + if (kisdangerous(rlim)) { ksnprintf(buf, 64, "%p", rlim); } else { ksnprintf(buf, 64, "{%'ld, %'ld}", rlim->rlim_cur, rlim->rlim_max); diff --git a/libc/intrin/describesigaction.c b/libc/intrin/describesigaction.c index 4138457b4..968ce057c 100644 --- a/libc/intrin/describesigaction.c +++ b/libc/intrin/describesigaction.c @@ -21,9 +21,9 @@ #include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" +#include "libc/macros.internal.h" #include "libc/mem/alloca.h" #include "libc/sysv/consts/sa.h" @@ -67,8 +67,7 @@ const char *(DescribeSigaction)(char buf[N], int rc, return "n/a"; if (!sa) return "NULL"; - if ((!IsAsan() && kisdangerous(sa)) || - (IsAsan() && !__asan_is_valid(sa, sizeof(*sa)))) { + if (kisdangerous(sa)) { ksnprintf(buf, N, "%p", sa); return buf; } diff --git a/libc/intrin/describesigaltstack.c b/libc/intrin/describesigaltstack.c index 16d7f811e..5121a93e5 100644 --- a/libc/intrin/describesigaltstack.c +++ b/libc/intrin/describesigaltstack.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/sigaltstack.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" @@ -28,8 +27,7 @@ const char *(DescribeSigaltstk)(char buf[128], int rc, return "n/a"; if (!ss) return "NULL"; - if ((!IsAsan() && kisdangerous(ss)) || - (IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) { + if (kisdangerous(ss)) { ksnprintf(buf, 128, "%p", ss); } else { ksnprintf(buf, 128, "{.ss_sp=%p, .ss_flags=%#lx, .ss_size=%'zu}", ss->ss_sp, diff --git a/libc/intrin/describesiginfo.c b/libc/intrin/describesiginfo.c index 9a3b4c1e0..d1bc5508d 100644 --- a/libc/intrin/describesiginfo.c +++ b/libc/intrin/describesiginfo.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/weaken.h" @@ -37,8 +36,7 @@ const char *(DescribeSiginfo)(char buf[N], int rc, const siginfo_t *si) { return "n/a"; if (!si) return "NULL"; - if ((!IsAsan() && kisdangerous(si)) || - (IsAsan() && !__asan_is_valid(si, sizeof(*si)))) { + if (kisdangerous(si)) { ksnprintf(buf, N, "%p", si); return buf; } diff --git a/libc/intrin/describesigset.c b/libc/intrin/describesigset.c index 97822e50c..e05758d49 100644 --- a/libc/intrin/describesigset.c +++ b/libc/intrin/describesigset.c @@ -21,7 +21,6 @@ #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/popcnt.h" #include "libc/str/str.h" @@ -43,8 +42,7 @@ const char *(DescribeSigset)(char buf[N], int rc, const sigset_t *ss) { return "n/a"; if (!ss) return "NULL"; - if ((!IsAsan() && kisdangerous(ss)) || - (IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) { + if (kisdangerous(ss)) { ksnprintf(buf, N, "%p", ss); return buf; } diff --git a/libc/intrin/describestat.c b/libc/intrin/describestat.c index 6c8d9dee4..102e58ef7 100644 --- a/libc/intrin/describestat.c +++ b/libc/intrin/describestat.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #define N 300 @@ -33,8 +32,7 @@ const char *(DescribeStat)(char buf[N], int rc, const struct stat *st) { return "n/a"; if (!st) return "NULL"; - if ((!IsAsan() && kisdangerous(st)) || - (IsAsan() && !__asan_is_valid(st, sizeof(*st)))) { + if (kisdangerous(st)) { ksnprintf(buf, N, "%p", st); return buf; } diff --git a/libc/intrin/describestatfs.c b/libc/intrin/describestatfs.c index 0932b6c76..787062edc 100644 --- a/libc/intrin/describestatfs.c +++ b/libc/intrin/describestatfs.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/statfs.internal.h" #include "libc/dce.h" #include "libc/fmt/conv.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/kprintf.h" #include "libc/sysv/consts/st.h" @@ -37,8 +36,7 @@ const char *(DescribeStatfs)(char buf[N], int rc, const struct statfs *f) { return "n/a"; if (!f) return "NULL"; - if ((!IsAsan() && kisdangerous(f)) || - (IsAsan() && !__asan_is_valid(f, sizeof(*f)))) { + if (kisdangerous(f)) { ksnprintf(buf, N, "%p", f); return buf; } diff --git a/libc/intrin/describestringlist.c b/libc/intrin/describestringlist.c index 8f1594210..b998b1cea 100644 --- a/libc/intrin/describestringlist.c +++ b/libc/intrin/describestringlist.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" @@ -30,10 +29,6 @@ const char *(DescribeStringList)(char buf[N], char *const list[]) { if (!list) return "NULL"; - if (IsAsan() && !__asan_is_valid_strlist(list)) { - ksnprintf(buf, N, "%p", list); - return buf; - } append("{"); i = 0; diff --git a/libc/intrin/describetermios.c b/libc/intrin/describetermios.c index 8c0614f1b..825d3f0c6 100644 --- a/libc/intrin/describetermios.c +++ b/libc/intrin/describetermios.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/termios.internal.h" #include "libc/calls/ttydefaults.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" @@ -37,8 +36,7 @@ const char *(DescribeTermios)(char buf[N], ssize_t rc, if (!tio) return "NULL"; - if ((!IsAsan() && kisdangerous(tio)) || - (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { + if (kisdangerous(tio)) { ksnprintf(buf, N, "%p", tio); return buf; } diff --git a/libc/intrin/describetimespec.c b/libc/intrin/describetimespec.c index d5cc954ff..7b5c56d9c 100644 --- a/libc/intrin/describetimespec.c +++ b/libc/intrin/describetimespec.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/timespec.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/str/str.h" @@ -29,8 +28,7 @@ const char *(DescribeTimespec)(char buf[45], int rc, return "n/a"; if (!ts) return "NULL"; - if ((!IsAsan() && kisdangerous(ts)) || - (IsAsan() && !__asan_is_valid(ts, sizeof(*ts)))) { + if (kisdangerous(ts)) { ksnprintf(buf, 45, "%p", ts); } else { if (!memcmp(ts, ×pec_max, sizeof(*ts))) { diff --git a/libc/intrin/describetimeval.c b/libc/intrin/describetimeval.c index 4e504aaa8..328d95d90 100644 --- a/libc/intrin/describetimeval.c +++ b/libc/intrin/describetimeval.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/timeval.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" @@ -27,8 +26,7 @@ const char *(DescribeTimeval)(char buf[45], int rc, const struct timeval *tv) { return "NULL"; if (rc == -1) return "n/a"; - if ((!IsAsan() && kisdangerous(tv)) || - (IsAsan() && !__asan_is_valid(tv, sizeof(*tv)))) { + if (kisdangerous(tv)) { ksnprintf(buf, 45, "%p", tv); } else { ksnprintf(buf, 45, "{%ld, %ld}", tv->tv_sec, tv->tv_usec); diff --git a/libc/intrin/describewinsize.c b/libc/intrin/describewinsize.c index 61208a7b5..abc91c867 100644 --- a/libc/intrin/describewinsize.c +++ b/libc/intrin/describewinsize.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/limits.h" @@ -35,8 +34,7 @@ const char *(DescribeWinsize)(char buf[N], int rc, const struct winsize *ws) { return "NULL"; if (rc == -1) return "n/a"; - if ((!IsAsan() && kisdangerous(ws)) || - (IsAsan() && !__asan_is_valid(ws, sizeof(*ws)))) { + if (kisdangerous(ws)) { ksnprintf(buf, N, "%p", ws); return buf; } diff --git a/libc/intrin/extend.c b/libc/intrin/extend.c index ae4b822e0..20a557fef 100644 --- a/libc/intrin/extend.c +++ b/libc/intrin/extend.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" @@ -47,14 +46,6 @@ */ void *_extend(void *p, size_t n, void *e, int f, intptr_t h) { char *q; - -#ifdef __SANITIZE_ADDRESS__ - if ((uintptr_t)SHADOW(p) & (G - 1)) - __builtin_trap(); - if ((uintptr_t)p + (G << kAsanScale) > h) - __builtin_trap(); -#endif - for (q = e; q < ((char *)p + n); q += 8) { if (!((uintptr_t)q & (G - 1))) { if (q + G > (char *)h) @@ -64,6 +55,5 @@ void *_extend(void *p, size_t n, void *e, int f, intptr_t h) { return 0; } } - return q; } diff --git a/libc/intrin/leaky.internal.h b/libc/intrin/leaky.internal.h index d413461fd..59a463d42 100644 --- a/libc/intrin/leaky.internal.h +++ b/libc/intrin/leaky.internal.h @@ -3,14 +3,7 @@ #include "libc/dce.h" COSMOPOLITAN_C_START_ -#if IsAsan() -#define IGNORE_LEAKS(FUNC) \ - __static_yoink("_leaky_start"); \ - void *_leaky_##FUNC[] _Section(".piro.relo.sort.leaky.2." #FUNC \ - ",\"aw\",@init_array #") = {FUNC}; -#else #define IGNORE_LEAKS(FUNC) -#endif extern intptr_t _leaky_end[] __attribute__((__weak__)); extern intptr_t _leaky_start[] __attribute__((__weak__)); diff --git a/libc/intrin/memchr.c b/libc/intrin/memchr.c index 676cb04be..6680c5292 100644 --- a/libc/intrin/memchr.c +++ b/libc/intrin/memchr.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" #ifndef __aarch64__ diff --git a/libc/intrin/memmove.c b/libc/intrin/memmove.c index b67842c50..6dd10c594 100644 --- a/libc/intrin/memmove.c +++ b/libc/intrin/memmove.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" #include "libc/str/str.h" @@ -159,7 +158,7 @@ static __vex void *__memmove(void *dst, const void *src, size_t n) { #if defined(__x86_64__) && !defined(__chibicc__) if (n < kHalfCache3 || !kHalfCache3) { if (d > s) { - if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) { + if (n < 900 || !X86_HAVE(ERMS)) { do { n -= 32; v = *(const xmm_t *)(s + n); @@ -176,7 +175,7 @@ static __vex void *__memmove(void *dst, const void *src, size_t n) { return dst; } } else { - if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) { + if (n < 900 || !X86_HAVE(ERMS)) { i = 0; do { v = *(const xmm_t *)(s + i); diff --git a/libc/intrin/mmap.c b/libc/intrin/mmap.c index 88f025dda..95d34515c 100644 --- a/libc/intrin/mmap.c +++ b/libc/intrin/mmap.c @@ -24,7 +24,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/directmap.internal.h" @@ -114,10 +113,7 @@ static bool __overlaps_existing_map(const char *addr, size_t size) { } static int __munmap_chunk(void *addr, size_t size) { - int rc = sys_munmap(addr, size); - if (IsAsan() && !rc) - __asan_unshadow(addr, size); - return rc; + return sys_munmap(addr, size); } static int __munmap(char *addr, size_t size, bool untrack_only) { @@ -410,12 +406,6 @@ void *__mmap(char *addr, size_t size, int prot, int flags, int fd, void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { void *res; res = __mmap(addr, size, prot, flags, fd, off); - if (IsAsan() && res != MAP_FAILED) { - __asan_shadow(res, size); - int granularity = __granularity(); - if (size != PGUP(size)) - __asan_poison(res + size, PGUP(size) - size, kAsanMmapSizeOverrun); - } STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → %p% m", addr, size, DescribeProtFlags(prot), DescribeMapFlags(flags), fd, off, res); return res; diff --git a/libc/intrin/sigprocmask.c b/libc/intrin/sigprocmask.c index 662a01a27..aa77cac8c 100644 --- a/libc/intrin/sigprocmask.c +++ b/libc/intrin/sigprocmask.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/sigset.internal.h" #include "libc/dce.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/str/str.h" @@ -51,12 +50,7 @@ int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) { int rc; sigset_t old = {0}; - if (IsAsan() && - ((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) || - (opt_out_oldset && - !__asan_is_valid(opt_out_oldset, sizeof(*opt_out_oldset))))) { - rc = efault(); - } else if (IsMetal() || IsWindows()) { + if (IsMetal() || IsWindows()) { rc = __sig_mask(how, opt_set, &old); } else { rc = sys_sigprocmask(how, opt_set, opt_out_oldset ? &old : 0); diff --git a/libc/intrin/stpcpy.c b/libc/intrin/stpcpy.c index c7c15e8e2..101355a61 100644 --- a/libc/intrin/stpcpy.c +++ b/libc/intrin/stpcpy.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/str/str.h" #ifndef __aarch64__ diff --git a/libc/irq/BUILD.mk b/libc/irq/BUILD.mk index 83b3e6d97..a3fb241a3 100644 --- a/libc/irq/BUILD.mk +++ b/libc/irq/BUILD.mk @@ -43,8 +43,6 @@ $(LIBC_IRQ_A).pkg: \ $(LIBC_IRQ_A_OBJS) \ $(foreach x,$(LIBC_IRQ_A_DIRECTDEPS),$($(x)_A).pkg) -$(LIBC_IRQ_A_OBJS): private COPTS += -fno-sanitize=address - LIBC_IRQ_LIBS = $(foreach x,$(LIBC_IRQ_ARTIFACTS),$($(x))) LIBC_IRQ_SRCS = $(foreach x,$(LIBC_IRQ_ARTIFACTS),$($(x)_SRCS)) LIBC_IRQ_HDRS = $(foreach x,$(LIBC_IRQ_ARTIFACTS),$($(x)_HDRS)) diff --git a/libc/log/backtrace3.c b/libc/log/backtrace3.c index 6ed1f82f7..37d0c1462 100644 --- a/libc/log/backtrace3.c +++ b/libc/log/backtrace3.c @@ -46,8 +46,9 @@ * @param st is open symbol table for current executable * @return -1 w/ errno if error happened */ -dontinstrument dontasan int PrintBacktraceUsingSymbols( - int fd, const struct StackFrame *bp, struct SymbolTable *st) { +dontinstrument int PrintBacktraceUsingSymbols(int fd, + const struct StackFrame *bp, + struct SymbolTable *st) { size_t gi; intptr_t addr; const char *name; diff --git a/libc/log/leaks.c b/libc/log/leaks.c index 6435b2bae..5978dbf5e 100644 --- a/libc/log/leaks.c +++ b/libc/log/leaks.c @@ -16,117 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/cxxabi.h" -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/cmpxchg.h" -#include "libc/intrin/cxaatexit.internal.h" -#include "libc/intrin/kprintf.h" -#include "libc/intrin/strace.internal.h" -#include "libc/mem/mem.h" -#include "libc/runtime/internal.h" -#include "libc/runtime/memtrack.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/runtime/symbols.internal.h" -#include "libc/testlib/testlib.h" -#include "libc/thread/posixthread.internal.h" -#include "libc/thread/tls.h" - -__static_yoink("GetSymbolByAddr"); - -#define MAXLEAKS 1000 - -static bool once; -static bool hasleaks; - -static dontasan void CheckLeak(void *x, void *y, size_t n, void *a) { - if (n) { - if (IsAsan()) { - if (__asan_get_heap_size(x) && !__asan_is_leaky(x)) { - hasleaks = true; - } - } else { - hasleaks = true; - } - } -} - -static dontasan void OnMemory(void *x, void *y, size_t n, void *a) { - static int i; - if (n) { - if (MAXLEAKS) { - if (i < MAXLEAKS) { - ++i; - kprintf("%p %,lu bytes [dlmalloc]", x, n); - if (__asan_is_leaky(x)) { - kprintf(" [leaky]"); - } - __asan_print_trace(x); - kprintf("\n"); - } else if (i == MAXLEAKS) { - ++i; - kprintf("etc. etc.\n"); - } - } - } -} - -static dontasan bool HasLeaks(void) { - malloc_inspect_all(CheckLeak, 0); - return hasleaks; -} /** * Tests for memory leaks. - * - * This function needs to call __cxa_finalize(). Therefore any runtime - * services that depend on malloc() cannot be used, after calling this - * function. */ -dontasan void CheckForMemoryLeaks(void) { - struct mallinfo mi; - if (!IsAsan()) - return; // we need traces to exclude leaky - if (!GetSymbolTable()) { - kprintf("CheckForMemoryLeaks() needs the symbol table\n"); - return; - } - if (!_cmpxchg(&once, false, true)) { - kprintf("CheckForMemoryLeaks() may only be called once\n"); - exit(0); - } - _pthread_unwind(_pthread_self()); - __cxa_thread_finalize(); - _pthread_unkey(__get_tls()); - _pthread_ungarbage(); - __cxa_finalize(0); - STRACE("checking for memory leaks% m"); - if (!IsAsan()) { - /* TODO(jart): How can we make this work without ASAN? */ - return; - } - malloc_trim(0); - if (HasLeaks()) { - mi = mallinfo(); - kprintf("\n" - "UNFREED MEMORY\n" - "%s\n" - "max allocated space %,*d\n" - "total allocated space %,*d\n" - "total free space %,*d\n" - "releasable space %,*d\n" - "mmaped space %,*d\n" - "non-mmapped space %,*d\n" - "\n", - __argv[0], 16l, mi.usmblks, 16l, mi.uordblks, 16l, mi.fordblks, 16l, - mi.hblkhd, 16l, mi.keepcost, 16l, mi.arena); - if (!IsAsan()) { - kprintf("# NOTE: Use `make -j8 MODE=dbg` for malloc() backtraces\n"); - } - malloc_inspect_all(OnMemory, 0); - kprintf("\n"); - /* __print_maps(); */ - /* PrintGarbage(); */ - _Exit(78); - } +void CheckForMemoryLeaks(void) { + // TODO(jart): give me a new lease on life } diff --git a/libc/log/oncrash_amd64.c b/libc/log/oncrash_amd64.c index a9fb0195d..914e2aa44 100644 --- a/libc/log/oncrash_amd64.c +++ b/libc/log/oncrash_amd64.c @@ -31,7 +31,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/describebacktrace.internal.h" #include "libc/intrin/describeflags.internal.h" diff --git a/libc/macros.internal.h b/libc/macros.internal.h index ae6313384..cf00d0364 100644 --- a/libc/macros.internal.h +++ b/libc/macros.internal.h @@ -488,31 +488,12 @@ .endm .macro .poison name:req kind:req -#ifdef __SANITIZE_ADDRESS__ -2323: .quad 0 - .init.start 304,"_init_\name\()_poison_\@" - push %rdi - push %rsi - ezlea 2323b,di - mov $8,%esi - mov $\kind,%edx - call __asan_poison - pop %rsi - pop %rdi - .init.end 304,"_init_\name\()_poison_\@" -#endif .endm .macro .underrun -#ifdef __SANITIZE_ADDRESS__ - .poison __BASE_FILE__, -20 # kAsanGlobalUnderrun -#endif .endm .macro .overrun -#ifdef __SANITIZE_ADDRESS__ - .poison __BASE_FILE__, -21 # kAsanGlobalOverrun -#endif .endm #else diff --git a/libc/mem/asan.c b/libc/mem/asan.c deleted file mode 100644 index 7229fecfa..000000000 --- a/libc/mem/asan.c +++ /dev/null @@ -1,353 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2024 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/atomic.h" -#include "libc/intrin/kprintf.h" -#include "libc/intrin/leaky.internal.h" -#include "libc/intrin/likely.h" -#include "libc/intrin/weaken.h" -#include "libc/macros.internal.h" -#include "libc/mem/mem.h" -#include "libc/runtime/symbols.internal.h" -#include "libc/stdckdint.h" -#include "libc/sysv/errfuns.h" -#include "libc/thread/thread.h" -#include "third_party/dlmalloc/dlmalloc.h" -#ifdef __SANITIZE_ADDRESS__ - -#define RBP __builtin_frame_address(0) - -struct AsanExtra { - uint64_t size; - struct AsanTrace bt; -}; - -struct ReportOriginHeap { - const unsigned char *a; - int z; -}; - -static struct AsanMorgue { - _Atomic(unsigned) i; - _Atomic(void *) p[ASAN_MORGUE_ITEMS]; -} __asan_morgue; - -static pthread_spinlock_t __asan_lock; - -static int __asan_bsr(uint64_t x) { - _Static_assert(sizeof(long long) == sizeof(uint64_t), ""); - return __builtin_clzll(x) ^ 63; -} - -static uint64_t __asan_roundup2pow(uint64_t x) { - return 2ull << __asan_bsr(x - 1); -} - -static void __asan_write48(uint64_t *value, uint64_t x) { - uint64_t cookie; - cookie = 'J' | 'T' << 8; - cookie ^= x & 0xffff; - *value = (x & 0xffffffffffff) | cookie << 48; -} - -static bool __asan_read48(uint64_t value, uint64_t *x) { - uint64_t cookie; - cookie = value >> 48; - cookie ^= value & 0xffff; - *x = (int64_t)(value << 16) >> 16; - return cookie == ('J' | 'T' << 8); -} - -static void *__asan_morgue_add(void *p) { - return atomic_exchange_explicit( - __asan_morgue.p + (atomic_fetch_add_explicit(&__asan_morgue.i, 1, - memory_order_acq_rel) & - (ARRAYLEN(__asan_morgue.p) - 1)), - p, memory_order_acq_rel); -} - -__attribute__((__destructor__)) static void __asan_morgue_flush(void) { - unsigned i; - for (i = 0; i < ARRAYLEN(__asan_morgue.p); ++i) - if (atomic_load_explicit(__asan_morgue.p + i, memory_order_acquire)) - dlfree(atomic_exchange_explicit(__asan_morgue.p + i, 0, - memory_order_release)); -} - -static size_t __asan_heap_size(size_t n) { - if (n < 0x7fffffff0000) { - n = ROUNDUP(n, _Alignof(struct AsanExtra)); - return __asan_roundup2pow(n + sizeof(struct AsanExtra)); - } else { - return -1; - } -} - -static void *__asan_allocate(size_t a, size_t n, struct AsanTrace *bt, - int underrun, int overrun, int initializer) { - char *p; - size_t c; - struct AsanExtra *e; - if ((p = dlmemalign(a, __asan_heap_size(n)))) { - c = dlmalloc_usable_size(p); - e = (struct AsanExtra *)(p + c - sizeof(*e)); - __asan_unpoison(p, n); - __asan_poison(p - 16, 16, underrun); /* see dlmalloc design */ - __asan_poison(p + n, c - n, overrun); - __asan_memset(p, initializer, n); - __asan_write48(&e->size, n); - __asan_memcpy(&e->bt, bt, sizeof(*bt)); - } - return p; -} - -static void *__asan_allocate_heap(size_t a, size_t n, struct AsanTrace *bt) { - return __asan_allocate(a, n, bt, kAsanHeapUnderrun, kAsanHeapOverrun, 0xf9); -} - -static struct AsanExtra *__asan_get_extra(const void *p, size_t *c) { - long n; - if (kisdangerous(p)) - return 0; - if ((n = dlmalloc_usable_size((void *)p)) < sizeof(struct AsanExtra)) - return 0; - *c = n; - return (struct AsanExtra *)(p + n - sizeof(struct AsanExtra)); -} - -// Returns true if `p` was allocated by an IGNORE_LEAKS(function). -int __asan_is_leaky(void *p) { - int sym; - size_t c, i, n; - intptr_t f, *l; - struct AsanExtra *e; - struct SymbolTable *st; - if (!_weaken(GetSymbolTable)) - notpossible; - if (!(e = __asan_get_extra(p, &c))) - return 0; - if (!__asan_read48(e->size, &n)) - return 0; - if (!__asan_is_mapped((char *)(((intptr_t)p >> 3) + 0x7fff8000))) - return 0; - if (!(st = GetSymbolTable())) - return 0; - for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) { - if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1) - continue; - f = st->addr_base + st->symbols[sym].x; - for (l = _leaky_start; l < _leaky_end; ++l) - if (f == *l) - return 1; - } - return 0; -} - -#define __asan_trace __asan_rawtrace - -int __asan_print_trace(void *p) { - size_t c, i, n; - struct AsanExtra *e; - if (!(e = __asan_get_extra(p, &c))) { - kprintf(" bad pointer"); - return einval(); - } - if (!__asan_read48(e->size, &n)) { - kprintf(" bad cookie"); - return -1; - } - kprintf("\n%p %,lu bytes [asan]", (char *)p, n); - if (!__asan_is_mapped((char *)(((intptr_t)p >> 3) + 0x7fff8000))) - kprintf(" (shadow not mapped?!)"); - for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) - kprintf("\n%*lx %t", 12, e->bt.p[i], e->bt.p[i]); - return 0; -} - -static void __asan_onmemory(void *x, void *y, size_t n, void *a) { - const unsigned char *p = x; - struct ReportOriginHeap *t = a; - if ((p <= t->a && t->a < p + n) || - (p <= t->a + t->z && t->a + t->z < p + n) || - (t->a < p && p + n <= t->a + t->z)) { - kprintf("%p %,lu bytes [dlmalloc]", x, n); - __asan_print_trace(x); - kprintf("\n"); - } -} - -void __asan_report_memory_origin_heap(const unsigned char *a, int z) { - struct ReportOriginHeap t; - kprintf("\nthe memory was allocated by\n"); - t.a = a; - t.z = z; - dlmalloc_inspect_all(__asan_onmemory, &t); -} - -size_t __asan_get_heap_size(const void *p) { - size_t n, c; - struct AsanExtra *e; - if ((e = __asan_get_extra(p, &c)) && __asan_read48(e->size, &n)) - return n; - return 0; -} - -static __wur __asan_die_f *__asan_report_invalid_pointer(const void *addr) { - pthread_spin_lock(&__asan_lock); - kprintf("\n\e[J\e[1;31masan error\e[0m: this corruption at %p shadow %p\n", - addr, SHADOW(addr)); - return __asan_die(); -} - -size_t malloc_usable_size(void *p) { - size_t n, c; - struct AsanExtra *e; - if ((e = __asan_get_extra(p, &c)) && __asan_read48(e->size, &n)) - return n; - __asan_report_invalid_pointer(p)(); - __asan_unreachable(); -} - -static void __asan_deallocate(char *p, long kind) { - size_t c, n; - struct AsanExtra *e; - if ((e = __asan_get_extra(p, &c))) { - if (__asan_read48(e->size, &n)) { - __asan_poison(p, c, kind); - if (c <= ASAN_MORGUE_THRESHOLD) - p = __asan_morgue_add(p); - dlfree(p); - } else { - __asan_report_invalid_pointer(p)(); - __asan_unreachable(); - } - } else { - __asan_report_invalid_pointer(p)(); - __asan_unreachable(); - } -} - -static void *__asan_realloc_nogrow(void *p, size_t n, size_t m, - struct AsanTrace *bt) { - return 0; -} - -static void *__asan_realloc_grow(void *p, size_t n, size_t m, - struct AsanTrace *bt) { - char *q; - if ((q = __asan_allocate_heap(16, n, bt))) { - __asan_memcpy(q, p, m); - __asan_deallocate(p, kAsanHeapRelocated); - } - return q; -} - -static void *__asan_realloc_impl(void *p, size_t n, - void *grow(void *, size_t, size_t, - struct AsanTrace *)) { - size_t c, m; - struct AsanExtra *e; - if ((e = __asan_get_extra(p, &c))) { - if (__asan_read48(e->size, &m)) { - if (n <= m) { // shrink - __asan_poison((char *)p + n, m - n, kAsanHeapOverrun); - __asan_write48(&e->size, n); - return p; - } else if (n <= c - sizeof(struct AsanExtra)) { // small growth - __asan_unpoison((char *)p + m, n - m); - __asan_write48(&e->size, n); - return p; - } else { // exponential growth - return grow(p, n, m, &e->bt); - } - } - } - __asan_report_invalid_pointer(p)(); - __asan_unreachable(); -} - -void free(void *p) { - if (!p) - return; - __asan_deallocate(p, kAsanHeapFree); -} - -void *malloc(size_t size) { - struct AsanTrace bt; - __asan_trace(&bt, RBP); - return __asan_allocate_heap(16, size, &bt); -} - -void *memalign(size_t align, size_t size) { - struct AsanTrace bt; - __asan_trace(&bt, RBP); - return __asan_allocate_heap(align, size, &bt); -} - -void *calloc(size_t n, size_t m) { - struct AsanTrace bt; - __asan_trace(&bt, RBP); - if (ckd_mul(&n, n, m)) - n = -1; - return __asan_allocate(16, n, &bt, kAsanHeapUnderrun, kAsanHeapOverrun, 0x00); -} - -void *realloc(void *p, size_t n) { - struct AsanTrace bt; - if (p) { - return __asan_realloc_impl(p, n, __asan_realloc_grow); - } else { - __asan_trace(&bt, RBP); - void *res = __asan_allocate_heap(16, n, &bt); - return res; - } -} - -void *realloc_in_place(void *p, size_t n) { - return p ? __asan_realloc_impl(p, n, __asan_realloc_nogrow) : 0; -} - -int malloc_trim(size_t pad) { - __asan_morgue_flush(); - return dlmalloc_trim(pad); -} - -void *__asan_stack_malloc(size_t size, int classid) { - struct AsanTrace bt; - __asan_trace(&bt, RBP); - return __asan_allocate(16, size, &bt, kAsanStackUnderrun, kAsanStackOverrun, - 0xf9); -} - -void __asan_stack_free(char *p, size_t size, int classid) { - __asan_deallocate(p, kAsanStackFree); -} - -size_t bulk_free(void *p[], size_t n) { - size_t i; - for (i = 0; i < n; ++i) - if (p[i]) { - __asan_deallocate(p[i], kAsanHeapFree); - p[i] = 0; - } - return 0; -} - -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/asanthunk.c b/libc/mem/asanthunk.c deleted file mode 100644 index 5abecff00..000000000 --- a/libc/mem/asanthunk.c +++ /dev/null @@ -1,178 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#ifdef __x86_64__ -#ifdef __SANITIZE_ADDRESS__ - -void __asan_report_load(void *, int); -void __asan_report_store(void *, int); -void *__asan_stack_malloc(size_t, int); -void __asan_stack_free(char *, size_t, int); - -void __asan_report_load1(void *p) { - __asan_report_load(p, 1); -} -void __asan_report_load2(void *p) { - __asan_report_load(p, 2); -} -void __asan_report_load4(void *p) { - __asan_report_load(p, 4); -} -void __asan_report_load8(void *p) { - __asan_report_load(p, 8); -} -void __asan_report_load16(void *p) { - __asan_report_load(p, 16); -} -void __asan_report_load32(void *p) { - __asan_report_load(p, 32); -} -void __asan_report_load_n(void *p, int n) { - __asan_report_load(p, n); -} - -void __asan_report_store1(void *p) { - __asan_report_store(p, 1); -} -void __asan_report_store2(void *p) { - __asan_report_store(p, 2); -} -void __asan_report_store4(void *p) { - __asan_report_store(p, 4); -} -void __asan_report_store8(void *p) { - __asan_report_store(p, 8); -} -void __asan_report_store16(void *p) { - __asan_report_store(p, 16); -} -void __asan_report_store32(void *p) { - __asan_report_store(p, 32); -} -void __asan_report_store_n(void *p, int n) { - __asan_report_store(p, n); -} - -void *__asan_stack_malloc_0(size_t n) { - return __asan_stack_malloc(n, 0); -} -void *__asan_stack_malloc_1(size_t n) { - return __asan_stack_malloc(n, 1); -} -void *__asan_stack_malloc_2(size_t n) { - return __asan_stack_malloc(n, 2); -} -void *__asan_stack_malloc_3(size_t n) { - return __asan_stack_malloc(n, 3); -} -void *__asan_stack_malloc_4(size_t n) { - return __asan_stack_malloc(n, 4); -} -void *__asan_stack_malloc_5(size_t n) { - return __asan_stack_malloc(n, 5); -} -void *__asan_stack_malloc_6(size_t n) { - return __asan_stack_malloc(n, 6); -} -void *__asan_stack_malloc_7(size_t n) { - return __asan_stack_malloc(n, 7); -} -void *__asan_stack_malloc_8(size_t n) { - return __asan_stack_malloc(n, 8); -} -void *__asan_stack_malloc_9(size_t n) { - return __asan_stack_malloc(n, 9); -} -void *__asan_stack_malloc_10(size_t n) { - return __asan_stack_malloc(n, 10); -} - -void __asan_stack_free_0(char *p, size_t n) { - __asan_stack_free(p, n, 0); -} -void __asan_stack_free_1(char *p, size_t n) { - __asan_stack_free(p, n, 1); -} -void __asan_stack_free_2(char *p, size_t n) { - __asan_stack_free(p, n, 2); -} -void __asan_stack_free_3(char *p, size_t n) { - __asan_stack_free(p, n, 3); -} -void __asan_stack_free_4(char *p, size_t n) { - __asan_stack_free(p, n, 4); -} -void __asan_stack_free_5(char *p, size_t n) { - __asan_stack_free(p, n, 5); -} -void __asan_stack_free_6(char *p, size_t n) { - __asan_stack_free(p, n, 6); -} -void __asan_stack_free_7(char *p, size_t n) { - __asan_stack_free(p, n, 7); -} -void __asan_stack_free_8(char *p, size_t n) { - __asan_stack_free(p, n, 8); -} -void __asan_stack_free_9(char *p, size_t n) { - __asan_stack_free(p, n, 9); -} -void __asan_stack_free_10(char *p, size_t n) { - __asan_stack_free(p, n, 10); -} - -void __asan_load1() { - __builtin_trap(); -} -void __asan_load2() { - __builtin_trap(); -} -void __asan_load4() { - __builtin_trap(); -} -void __asan_load8() { - __builtin_trap(); -} -void __asan_load16() { - __builtin_trap(); -} -void __asan_load32() { - __builtin_trap(); -} - -void __asan_store1() { - __builtin_trap(); -} -void __asan_store2() { - __builtin_trap(); -} -void __asan_store4() { - __builtin_trap(); -} -void __asan_store8() { - __builtin_trap(); -} -void __asan_store16() { - __builtin_trap(); -} -void __asan_store32() { - __builtin_trap(); -} - -#endif /* __SANITIZE_ADDRESS__ */ -#endif /* __x86_64__ */ diff --git a/libc/mem/bulk_free.c b/libc/mem/bulk_free.c index 64c736a50..cecd50e58 100644 --- a/libc/mem/bulk_free.c +++ b/libc/mem/bulk_free.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Frees and clears (sets to NULL) each non-null pointer in given array. @@ -33,4 +32,3 @@ size_t bulk_free(void **p, size_t n) { return dlbulk_free(p, n); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/calloc.c b/libc/mem/calloc.c index f64294fb5..df578353c 100644 --- a/libc/mem/calloc.c +++ b/libc/mem/calloc.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Allocates n * itemsize bytes, initialized to zero. @@ -33,4 +32,3 @@ void *calloc(size_t n, size_t itemsize) { return dlcalloc(n, itemsize); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/free.c b/libc/mem/free.c index c7ba3c233..bb143438f 100644 --- a/libc/mem/free.c +++ b/libc/mem/free.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Free memory returned by malloc() & co. @@ -34,4 +33,3 @@ void free(void *p) { dlfree(p); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/malloc.c b/libc/mem/malloc.c index 68629fb35..c843f2fc8 100644 --- a/libc/mem/malloc.c +++ b/libc/mem/malloc.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Allocates uninitialized memory. @@ -44,4 +43,3 @@ void *malloc(size_t n) { return dlmalloc(n); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/malloc_trim.c b/libc/mem/malloc_trim.c index 3c6f3b474..26f4b5d47 100644 --- a/libc/mem/malloc_trim.c +++ b/libc/mem/malloc_trim.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Releases freed memory back to system. @@ -30,4 +29,3 @@ int malloc_trim(size_t n) { return dlmalloc_trim(n); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/malloc_usable_size.c b/libc/mem/malloc_usable_size.c index 60b1c738d..38d952c4b 100644 --- a/libc/mem/malloc_usable_size.c +++ b/libc/mem/malloc_usable_size.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Returns the number of bytes you can actually use in @@ -42,4 +41,3 @@ size_t malloc_usable_size(void *p) { return dlmalloc_usable_size(p); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/memalign.c b/libc/mem/memalign.c index 114048477..bdf8f9ff7 100644 --- a/libc/mem/memalign.c +++ b/libc/mem/memalign.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Allocates aligned memory. @@ -37,4 +36,3 @@ void *memalign(size_t align, size_t bytes) { return dlmemalign(align, bytes); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/realloc.c b/libc/mem/realloc.c index 589ef2bfe..6d7451a8e 100644 --- a/libc/mem/realloc.c +++ b/libc/mem/realloc.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Allocates / resizes / frees memory, e.g. @@ -62,4 +61,3 @@ void *realloc(void *p, size_t n) { return dlrealloc(p, n); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/realloc_in_place.c b/libc/mem/realloc_in_place.c index 514cfd046..79c581fd1 100644 --- a/libc/mem/realloc_in_place.c +++ b/libc/mem/realloc_in_place.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "third_party/dlmalloc/dlmalloc.h" -#ifndef __SANITIZE_ADDRESS__ /** * Resizes the space allocated for p to size n, only if this can be @@ -39,4 +38,3 @@ void *realloc_in_place(void *p, size_t n) { return dlrealloc_in_place(p, n); } -#endif /* __SANITIZE_ADDRESS__ */ diff --git a/libc/mem/tinymalloc.inc b/libc/mem/tinymalloc.inc index 2719a0ce9..019a4ec3f 100644 --- a/libc/mem/tinymalloc.inc +++ b/libc/mem/tinymalloc.inc @@ -29,8 +29,6 @@ #define TINYMALLOC_MAX_ALIGN 4096 #endif -#if !IsAsan() - alignas(TINYMALLOC_MAX_ALIGN) static struct { char memory[TINYMALLOC_MAX_BYTES]; size_t used, last, free; @@ -167,5 +165,3 @@ OutOfMemory: errno = ENOMEM; return 0; } - -#endif /* IsAsan() */ diff --git a/libc/proc/BUILD.mk b/libc/proc/BUILD.mk index ca56c4b99..5c50271d5 100644 --- a/libc/proc/BUILD.mk +++ b/libc/proc/BUILD.mk @@ -50,7 +50,6 @@ $(LIBC_PROC_A).pkg: \ $(LIBC_PROC_A_OBJS): private \ COPTS += \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/libc/proc/execve.c b/libc/proc/execve.c index 41c3fdc49..2fde8ee9b 100644 --- a/libc/proc/execve.c +++ b/libc/proc/execve.c @@ -22,7 +22,6 @@ #include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/likely.h" #include "libc/intrin/promises.internal.h" @@ -63,10 +62,7 @@ int execve(const char *prog, char *const argv[], char *const envp[]) { int rc; struct ZiposUri uri; - if (!prog || !argv || !envp || - (IsAsan() && (!__asan_is_valid_str(prog) || // - !__asan_is_valid_strlist(argv) || // - !__asan_is_valid_strlist(envp)))) { + if (!prog || !argv || !envp) { rc = efault(); } else { STRACE("execve(%#s, %s, %s)", prog, DescribeStringList(argv), diff --git a/libc/proc/execvpe.c b/libc/proc/execvpe.c index d748e47f8..d749aa2fc 100644 --- a/libc/proc/execvpe.c +++ b/libc/proc/execvpe.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/limits.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" @@ -46,12 +45,6 @@ int execvpe(const char *prog, char *const argv[], char *const *envp) { char *exe, **argv2; char pathbuf[PATH_MAX]; - // validate memory - if (IsAsan() && - (!__asan_is_valid_str(prog) || !__asan_is_valid_strlist(argv))) { - return efault(); - } - if (strchr(prog, '/')) { return execve(prog, argv, envp); } diff --git a/libc/proc/fexecve.c b/libc/proc/fexecve.c index 085d0c98a..9ed672c8d 100644 --- a/libc/proc/fexecve.c +++ b/libc/proc/fexecve.c @@ -27,7 +27,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" @@ -186,9 +185,7 @@ static int fd_to_mem_fd(const int infd, char *path) { */ int fexecve(int fd, char *const argv[], char *const envp[]) { int rc = 0; - if (!argv || !envp || - (IsAsan() && - (!__asan_is_valid_strlist(argv) || !__asan_is_valid_strlist(envp)))) { + if (!argv || !envp) { rc = efault(); } else { STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv), diff --git a/libc/proc/getrusage.c b/libc/proc/getrusage.c index 9003883bb..95d385a50 100644 --- a/libc/proc/getrusage.c +++ b/libc/proc/getrusage.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/rusage.h" #include "libc/calls/struct/rusage.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -34,8 +33,6 @@ int getrusage(int who, struct rusage *usage) { int rc; if (who == 99) { rc = einval(); - } else if (IsAsan() && usage && !__asan_is_valid(usage, sizeof(*usage))) { - rc = efault(); } else if (!IsWindows()) { rc = sys_getrusage(who, usage); } else { diff --git a/libc/proc/posix_spawn.c b/libc/proc/posix_spawn.c index 6cf8439af..4e85e49b4 100644 --- a/libc/proc/posix_spawn.c +++ b/libc/proc/posix_spawn.c @@ -35,7 +35,6 @@ #include "libc/errno.h" #include "libc/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/bsf.h" #include "libc/intrin/describeflags.internal.h" @@ -419,10 +418,7 @@ static textwindows dontinline errno_t posix_spawn_nt( int *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) { int err; - if (!path || !argv || - (IsAsan() && (!__asan_is_valid_str(path) || // - !__asan_is_valid_strlist(argv) || // - (envp && !__asan_is_valid_strlist(envp))))) { + if (!path || !argv) { err = EFAULT; } else { err = posix_spawn_nt_impl(pid, path, file_actions, attrp, argv, envp); diff --git a/libc/proc/wait4.c b/libc/proc/wait4.c index 3ac5bc8ba..7d6056aff 100644 --- a/libc/proc/wait4.c +++ b/libc/proc/wait4.c @@ -20,7 +20,6 @@ #include "libc/calls/cp.internal.h" #include "libc/calls/struct/rusage.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/proc/proc.internal.h" #include "libc/sysv/errfuns.h" @@ -44,13 +43,7 @@ int wait4(int pid, int *opt_out_wstatus, int options, int rc, ws = 0; BEGIN_CANCELATION_POINT; - if (IsAsan() && - ((opt_out_wstatus && - !__asan_is_valid(opt_out_wstatus, sizeof(*opt_out_wstatus))) || - (opt_out_rusage && - !__asan_is_valid(opt_out_rusage, sizeof(*opt_out_rusage))))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { rc = sys_wait4(pid, &ws, options, opt_out_rusage); } else { rc = sys_wait4_nt(pid, &ws, options, opt_out_rusage); diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index cf73154a0..be9b73488 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -27,7 +27,6 @@ #include "libc/calls/wincrash.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/ulock.h" @@ -751,13 +750,6 @@ errno_t clone(void *func, void *stk, size_t stksz, int flags, void *arg, if (!func) { rc = EINVAL; - } else if (IsAsan() && - (((flags & CLONE_SETTLS) && !__asan_is_valid(tls, 64)) || - ((flags & CLONE_PARENT_SETTID) && - !__asan_is_valid(ptid, sizeof(int))) || - ((flags & CLONE_CHILD_SETTID) && - !__asan_is_valid(ctid, sizeof(int))))) { - rc = EFAULT; } else if (IsLinux()) { rc = CloneLinux(func, stk, stksz, flags, arg, tls, ptid, ctid); } else if (!IsTiny() && diff --git a/libc/runtime/cosmo.S b/libc/runtime/cosmo.S index 7d7c66755..fcaa2376e 100644 --- a/libc/runtime/cosmo.S +++ b/libc/runtime/cosmo.S @@ -134,16 +134,6 @@ cosmo: push %rbp pop %rdi .init.end 304,_init_tls -#if IsAsan() - .init.start 305,_init_symbols - push %rdi - push %rsi - call __init_symbols - pop %rsi - pop %rdi - .init.end 305,_init_symbols -#endif - #ifdef FTRACE .init.start 306,_init_ftrace push %rdi diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 45246fade..ccc662568 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -20,8 +20,6 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/asancodes.h" #include "libc/intrin/atomic.h" #include "libc/intrin/dll.h" #include "libc/intrin/getenv.internal.h" @@ -151,22 +149,12 @@ textstartup void __enable_tls(void) { mem = _weaken(_mapanon)(siz); } - if (IsAsan()) { - // poison the space between .tdata and .tbss - __asan_poison(mem + I(_tdata_size), I(_tbss_offset) - I(_tdata_size), - kAsanProtected); - } - struct CosmoTib *tib = (struct CosmoTib *)(mem + siz - sizeof(*tib)); char *tls = mem + siz - sizeof(*tib) - I(_tls_size); // copy in initialized data section if (I(_tdata_size)) { - if (IsAsan()) { - __asan_memcpy(tls, _tdata_start, I(_tdata_size)); - } else { - memcpy(tls, _tdata_start, I(_tdata_size)); - } + memcpy(tls, _tdata_start, I(_tdata_size)); } #elif defined(__aarch64__) diff --git a/libc/runtime/mapstack.c b/libc/runtime/mapstack.c index 368918ea3..6e9a508ae 100644 --- a/libc/runtime/mapstack.c +++ b/libc/runtime/mapstack.c @@ -19,8 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/syscall-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/asancodes.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" @@ -55,10 +53,6 @@ void *NewCosmoStack(void) { -1, 0, 0) != p) { notpossible; } - if (IsAsan()) { - __asan_poison(p + n - 16, 16, kAsanStackOverflow); - __asan_poison(p, getauxval(AT_PAGESZ), kAsanStackOverflow); - } return p; } else { return 0; diff --git a/libc/runtime/symbols.c b/libc/runtime/symbols.c index 23f5dfb1f..05dfdebb5 100644 --- a/libc/runtime/symbols.c +++ b/libc/runtime/symbols.c @@ -23,7 +23,6 @@ #include "libc/runtime/symbols.internal.h" void __init_symbols(void) { - if (__strace > 0 || (IsAsan() && _weaken(__die))) { + if (__strace > 0) GetSymbolTable(); - } } diff --git a/libc/runtime/zipos-open.c b/libc/runtime/zipos-open.c index 25e89d48b..4a181ed51 100644 --- a/libc/runtime/zipos-open.c +++ b/libc/runtime/zipos-open.c @@ -26,7 +26,6 @@ #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/cmpxchg.h" #include "libc/intrin/directmap.internal.h" @@ -94,10 +93,6 @@ void __zipos_drop(struct ZiposHandle *h) { return; } atomic_thread_fence(memory_order_acquire); - if (IsAsan()) { - __asan_poison((char *)h + sizeof(struct ZiposHandle), - h->mapsize - sizeof(struct ZiposHandle), kAsanHeapFree); - } __zipos_lock(); do h->next = h->zipos->freelist; @@ -125,12 +120,6 @@ StartOver: h = __zipos_mmap_space(mapsize); } __zipos_unlock(); - if (IsAsan()) { - __asan_unpoison((char *)h, sizeof(struct ZiposHandle) + size); - __asan_poison((char *)h + sizeof(struct ZiposHandle) + size, - mapsize - (sizeof(struct ZiposHandle) + size), - kAsanHeapOverrun); - } if (h) { atomic_store_explicit(&h->refs, 0, memory_order_relaxed); h->size = size; diff --git a/libc/sock/accept4.c b/libc/sock/accept4.c index e7884baac..5aee5e465 100644 --- a/libc/sock/accept4.c +++ b/libc/sock/accept4.c @@ -19,7 +19,6 @@ #include "libc/calls/cp.internal.h" #include "libc/calls/internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" diff --git a/libc/sock/asanmsghdr.c b/libc/sock/asanmsghdr.c deleted file mode 100644 index f9af26ab2..000000000 --- a/libc/sock/asanmsghdr.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2022 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/sock/struct/msghdr.h" -#if IsAsan() - -bool __asan_is_valid_msghdr(const struct msghdr *msg) { - if (!__asan_is_valid(msg, sizeof(struct msghdr))) - return false; - if (msg->msg_name) { - if (!__asan_is_valid(msg->msg_name, msg->msg_namelen)) - return false; - } - if (msg->msg_control) { - if (!__asan_is_valid(msg->msg_control, msg->msg_controllen)) - return false; - } - return __asan_is_valid_iov(msg->msg_iov, msg->msg_iovlen); -} - -#endif diff --git a/libc/sock/bind.c b/libc/sock/bind.c index 45ff0a967..5ff0ff37b 100644 --- a/libc/sock/bind.c +++ b/libc/sock/bind.c @@ -19,7 +19,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" @@ -48,7 +47,7 @@ */ int bind(int fd, const struct sockaddr *addr, uint32_t addrsize) { int rc; - if (!addr || (IsAsan() && !__asan_is_valid(addr, addrsize))) { + if (!addr) { rc = efault(); } else if (addrsize >= sizeof(struct sockaddr_in)) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { diff --git a/libc/sock/connect.c b/libc/sock/connect.c index 956b35507..9453c62d5 100644 --- a/libc/sock/connect.c +++ b/libc/sock/connect.c @@ -20,7 +20,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" @@ -45,7 +44,7 @@ int connect(int fd, const struct sockaddr *addr, uint32_t addrsize) { int rc; BEGIN_CANCELATION_POINT; - if (addr && !(IsAsan() && !__asan_is_valid(addr, addrsize))) { + if (addr) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { diff --git a/libc/sock/getsockname.c b/libc/sock/getsockname.c index f2ad8ff1d..e04d620ad 100644 --- a/libc/sock/getsockname.c +++ b/libc/sock/getsockname.c @@ -19,7 +19,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/errors.h" #include "libc/nt/thunk/msabi.h" diff --git a/libc/sock/getsockopt.c b/libc/sock/getsockopt.c index 82f8ce6ce..3a7106ddd 100644 --- a/libc/sock/getsockopt.c +++ b/libc/sock/getsockopt.c @@ -19,7 +19,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" @@ -47,10 +46,6 @@ int getsockopt(int fd, int level, int optname, void *out_opt_optval, if (level == -1 || !optname) { rc = enoprotoopt(); // see libc/sysv/consts.sh - } else if (IsAsan() && (out_opt_optval && out_optlen && - (!__asan_is_valid(out_optlen, sizeof(uint32_t)) || - !__asan_is_valid(out_opt_optval, *out_optlen)))) { - rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { diff --git a/libc/sock/kntwsadata.c b/libc/sock/kntwsadata.c index 2e0e2cfc6..a3450d88c 100644 --- a/libc/sock/kntwsadata.c +++ b/libc/sock/kntwsadata.c @@ -42,7 +42,7 @@ static textwindows void WinSockCleanup(void) { NTTRACE("WSACleanup() → %d% lm", rc); } -textwindows dontasan void WinSockInit(void) { +textwindows void WinSockInit(void) { int rc; atexit(WinSockCleanup); NTTRACE("WSAStartup()"); diff --git a/libc/sock/recv.c b/libc/sock/recv.c index 9175f4354..26b9a7436 100644 --- a/libc/sock/recv.c +++ b/libc/sock/recv.c @@ -20,7 +20,6 @@ #include "libc/calls/internal.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sock/internal.h" #include "libc/sock/sock.h" @@ -45,9 +44,7 @@ ssize_t recv(int fd, void *buf, size_t size, int flags) { ssize_t rc; BEGIN_CANCELATION_POINT; - if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { rc = sys_recvfrom(fd, buf, size, flags, 0, 0); diff --git a/libc/sock/recvfrom.c b/libc/sock/recvfrom.c index d3e326f1b..b015cf2af 100644 --- a/libc/sock/recvfrom.c +++ b/libc/sock/recvfrom.c @@ -21,7 +21,6 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/winsock.h" #include "libc/sock/internal.h" @@ -60,9 +59,7 @@ ssize_t recvfrom(int fd, void *buf, size_t size, int flags, uint32_t addrsize = sizeof(addr); BEGIN_CANCELATION_POINT; - if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { rc = sys_recvfrom(fd, buf, size, flags, &addr, &addrsize); diff --git a/libc/sock/recvmsg.c b/libc/sock/recvmsg.c index 85c3fc761..56f6d4762 100644 --- a/libc/sock/recvmsg.c +++ b/libc/sock/recvmsg.c @@ -57,9 +57,7 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags) { union sockaddr_storage_bsd bsd; BEGIN_CANCELATION_POINT; - if (IsAsan() && !__asan_is_valid_msghdr(msg)) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { if (IsBsd() && msg->msg_name) { diff --git a/libc/sock/send.c b/libc/sock/send.c index 799914646..b66ee698c 100644 --- a/libc/sock/send.c +++ b/libc/sock/send.c @@ -21,7 +21,6 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/sock/internal.h" @@ -46,9 +45,7 @@ ssize_t send(int fd, const void *buf, size_t size, int flags) { ssize_t rc; BEGIN_CANCELATION_POINT; - if (IsAsan() && !__asan_is_valid(buf, size)) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { rc = sys_sendto(fd, buf, size, flags, 0, 0); diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index 633c81273..f5b107a1b 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -25,7 +25,6 @@ #include "libc/cosmo.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/enum/wsaid.h" @@ -182,10 +181,7 @@ ssize_t sendfile(int outfd, int infd, int64_t *opt_in_out_inoffset, // less error prone, since Linux may EINVAL if greater than INT64_MAX uptobytes = MIN(uptobytes, 0x7ffff000); - if (IsAsan() && opt_in_out_inoffset && - !__asan_is_valid(opt_in_out_inoffset, 8)) { - rc = efault(); - } else if (IsLinux()) { + if (IsLinux()) { rc = sys_sendfile(outfd, infd, opt_in_out_inoffset, uptobytes); } else if (IsFreebsd() || IsXnu()) { rc = sys_sendfile_bsd(outfd, infd, opt_in_out_inoffset, uptobytes); diff --git a/libc/sock/sendmsg.c b/libc/sock/sendmsg.c index 2eb0c7f5b..1b1e32a1d 100644 --- a/libc/sock/sendmsg.c +++ b/libc/sock/sendmsg.c @@ -23,7 +23,6 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/strace.internal.h" @@ -56,9 +55,7 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) { union sockaddr_storage_bsd bsd; BEGIN_CANCELATION_POINT; - if (IsAsan() && !__asan_is_valid_msghdr(msg)) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { if (IsBsd() && msg->msg_name) { @@ -91,8 +88,7 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) { // TODO(jart): Write a DescribeMsg() function. if (strace_enabled(0) > 0) { kprintf(STRACE_PROLOGUE "sendmsg(%d, ", fd); - if ((!IsAsan() && kisdangerous(msg)) || - (IsAsan() && !__asan_is_valid(msg, sizeof(*msg)))) { + if (kisdangerous(msg)) { kprintf("%p", msg); } else { kprintf("{"); diff --git a/libc/sock/sendto.c b/libc/sock/sendto.c index c5b426981..61638e132 100644 --- a/libc/sock/sendto.c +++ b/libc/sock/sendto.c @@ -22,7 +22,6 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/macros.internal.h" #include "libc/sock/internal.h" @@ -61,10 +60,7 @@ ssize_t sendto(int fd, const void *buf, size_t size, int flags, union sockaddr_storage_bsd bsd; BEGIN_CANCELATION_POINT; - if (IsAsan() && (!__asan_is_valid(buf, size) || - (opt_addr && !__asan_is_valid(opt_addr, addrsize)))) { - rc = efault(); - } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { + if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); } else if (!IsWindows()) { if (!IsBsd() || !opt_addr) { diff --git a/libc/sock/setsockopt.c b/libc/sock/setsockopt.c index 63352a010..c7c204eb9 100644 --- a/libc/sock/setsockopt.c +++ b/libc/sock/setsockopt.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/fd.internal.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/nt/winsock.h" @@ -63,8 +62,7 @@ int setsockopt(int fd, int level, int optname, const void *optval, if (level == -1 || !optname) { rc = enoprotoopt(); // see libc/sysv/consts.sh - } else if ((!optval && optlen) || - (IsAsan() && !__asan_is_valid(optval, optlen))) { + } else if ((!optval && optlen)) { rc = efault(); } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { rc = enotsock(); diff --git a/libc/stdio/getentropy.c b/libc/stdio/getentropy.c index ec2e68570..c9cebf50b 100644 --- a/libc/stdio/getentropy.c +++ b/libc/stdio/getentropy.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/sigset.internal.h" #include "libc/calls/syscall_support-sysv.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/stdio/rand.h" #include "libc/sysv/errfuns.h" @@ -39,7 +38,7 @@ int getentropy(void *p, size_t n) { int rc; if (n > 256) { rc = eio(); - } else if ((!p && n) || (IsAsan() && !__asan_is_valid(p, n))) { + } else if ((!p && n)) { rc = efault(); } else if (IsXnu() || IsOpenbsd()) { if (sys_getentropy(p, n)) diff --git a/libc/stdio/rngset.c b/libc/stdio/rngset.c index ff0c6274d..dc13fc564 100644 --- a/libc/stdio/rngset.c +++ b/libc/stdio/rngset.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" @@ -41,7 +40,7 @@ * * @return original buf */ -dontasan void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) { +void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) { size_t m; uint64_t x, t = 0; unsigned char *p = b; diff --git a/libc/testlib/memoryexists.c b/libc/testlib/memoryexists.c index 5d656f8b1..d18c173ba 100644 --- a/libc/testlib/memoryexists.c +++ b/libc/testlib/memoryexists.c @@ -51,7 +51,7 @@ static void ContinueOnError(int sig, siginfo_t *si, void *vctx) { * on error. It then attempts a volatile read and if it faults, then * this function shall return false. The value at `p` isn't considered. */ -dontasan bool testlib_memoryexists(const void *p) { +bool testlib_memoryexists(const void *p) { volatile char c; const atomic_char *mem = p; struct sigaction old[2]; diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index b343aa374..438663b91 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -89,7 +89,7 @@ static void GetOpts(int argc, char *argv[]) { /** * Generic test program main function. */ -dontasan int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { int fd; struct Dll *e; struct TestAspect *a; @@ -164,7 +164,7 @@ dontasan int main(int argc, char *argv[]) { } // check for memory leaks - if (IsAsan() && !g_testlib_failed) { + if (!g_testlib_failed) { CheckForMemoryLeaks(); } diff --git a/libc/thread/getitimer.c b/libc/thread/getitimer.c index 9bbda100b..4e37b0d40 100644 --- a/libc/thread/getitimer.c +++ b/libc/thread/getitimer.c @@ -20,7 +20,6 @@ #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -33,9 +32,7 @@ */ int getitimer(int which, struct itimerval *curvalue) { int rc; - if (IsAsan() && !__asan_is_valid(curvalue, sizeof(*curvalue))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { rc = sys_getitimer(which, curvalue); } else if (!curvalue) { rc = efault(); diff --git a/libc/thread/mktls.c b/libc/thread/mktls.c index d871603e5..2f7129a5c 100644 --- a/libc/thread/mktls.c +++ b/libc/thread/mktls.c @@ -18,8 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/sections.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/asancodes.h" #include "libc/intrin/atomic.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" @@ -72,22 +70,12 @@ static char *_mktls_below(struct CosmoTib **out_tib) { siz = ROUNDUP(siz, _Alignof(struct CosmoTib)); mem = memalign(_Alignof(struct CosmoTib), siz); - if (IsAsan()) { - // poison the space between .tdata and .tbss - __asan_poison(mem + I(_tdata_size), I(_tbss_offset) - I(_tdata_size), - kAsanProtected); - } - tib = (struct CosmoTib *)(mem + siz - sizeof(*tib)); tls = mem + siz - sizeof(*tib) - I(_tls_size); // copy in initialized data section if (I(_tdata_size)) { - if (IsAsan()) { - __asan_memcpy(tls, _tdata_start, I(_tdata_size)); - } else { - memcpy(tls, _tdata_start, I(_tdata_size)); - } + memcpy(tls, _tdata_start, I(_tdata_size)); } // clear .tbss diff --git a/libc/thread/pthread_attr_setstack.c b/libc/thread/pthread_attr_setstack.c index 1e16d3fd9..f82be129f 100644 --- a/libc/thread/pthread_attr_setstack.c +++ b/libc/thread/pthread_attr_setstack.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/thread/thread.h" /** @@ -72,10 +71,8 @@ errno_t pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, attr->__stacksize = 0; return 0; } - if (stacksize < PTHREAD_STACK_MIN || - (IsAsan() && !__asan_is_valid(stackaddr, stacksize))) { + if (stacksize < PTHREAD_STACK_MIN) return EINVAL; - } attr->__stackaddr = stackaddr; attr->__stacksize = stacksize; return 0; diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index 25dd940cb..15624b7ec 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -24,7 +24,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/bsr.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/dll.h" @@ -258,10 +257,6 @@ static errno_t pthread_create_impl(pthread_t *thread, } } pt->pt_flags |= PT_OWNSTACK; - if (IsAsan() && !IsWindows() && pt->pt_attr.__guardsize) { - __asan_poison(pt->pt_attr.__stackaddr, pt->pt_attr.__guardsize, - kAsanStackOverflow); - } } // set initial status diff --git a/libc/thread/pthread_setname_np.c b/libc/thread/pthread_setname_np.c index 83cf95662..9f2894c05 100644 --- a/libc/thread/pthread_setname_np.c +++ b/libc/thread/pthread_setname_np.c @@ -22,7 +22,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" diff --git a/libc/thread/setitimer.c b/libc/thread/setitimer.c index 544f026cd..88d1c7b16 100644 --- a/libc/thread/setitimer.c +++ b/libc/thread/setitimer.c @@ -19,7 +19,6 @@ #include "libc/calls/struct/itimerval.h" #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -71,11 +70,7 @@ int setitimer(int which, const struct itimerval *newvalue, struct itimerval *oldvalue) { int rc; - if (IsAsan() && - ((newvalue && !__asan_is_valid(newvalue, sizeof(*newvalue))) || - (oldvalue && !__asan_is_valid(oldvalue, sizeof(*oldvalue))))) { - rc = efault(); - } else if (!IsWindows()) { + if (!IsWindows()) { if (newvalue) { rc = sys_setitimer(which, newvalue, oldvalue); } else { diff --git a/libc/tinymath/BUILD.mk b/libc/tinymath/BUILD.mk index cd6e5e8ed..15493f253 100644 --- a/libc/tinymath/BUILD.mk +++ b/libc/tinymath/BUILD.mk @@ -63,8 +63,7 @@ $(LIBC_TINYMATH_A_OBJS): private \ -fno-associative-math \ -fno-finite-math-only \ -fno-cx-limited-range \ - -ffp-int-builtin-inexact \ - -fno-sanitize=address + -ffp-int-builtin-inexact LIBC_TINYMATH_LIBS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x))) LIBC_TINYMATH_HDRS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_HDRS)) diff --git a/libc/vga/BUILD.mk b/libc/vga/BUILD.mk index 93f83b431..55c801065 100644 --- a/libc/vga/BUILD.mk +++ b/libc/vga/BUILD.mk @@ -45,8 +45,6 @@ $(LIBC_VGA_A).pkg: \ $(LIBC_VGA_A_OBJS) \ $(foreach x,$(LIBC_VGA_A_DIRECTDEPS),$($(x)_A).pkg) -$(LIBC_VGA_A_OBJS): private COPTS += -fno-sanitize=address - LIBC_VGA_LIBS = $(foreach x,$(LIBC_VGA_ARTIFACTS),$($(x))) LIBC_VGA_SRCS = $(foreach x,$(LIBC_VGA_ARTIFACTS),$($(x)_SRCS)) LIBC_VGA_HDRS = $(foreach x,$(LIBC_VGA_ARTIFACTS),$($(x)_HDRS)) diff --git a/test/libc/calls/access_test.c b/test/libc/calls/access_test.c index 72bfbb3ea..efa924280 100644 --- a/test/libc/calls/access_test.c +++ b/test/libc/calls/access_test.c @@ -33,12 +33,6 @@ void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath fattr", 0)); } -TEST(access, efault) { - if (IsWindows() || !IsAsan()) - return; // not possible - ASSERT_SYS(EFAULT, -1, access((void *)77, F_OK)); -} - TEST(access, enoent) { ASSERT_SYS(ENOENT, -1, access("", F_OK)); ASSERT_SYS(ENOENT, -1, access("doesnotexist", F_OK)); diff --git a/test/libc/calls/chdir_test.c b/test/libc/calls/chdir_test.c index 93c5f359b..45e8da03c 100644 --- a/test/libc/calls/chdir_test.c +++ b/test/libc/calls/chdir_test.c @@ -29,9 +29,6 @@ void SetUpOnce(void) { TEST(chdir, efault) { ASSERT_SYS(EFAULT, -1, chdir(0)); - if (IsWindows() || !IsAsan()) - return; // not possible - ASSERT_SYS(EFAULT, -1, chdir((void *)77)); } TEST(chdir, enoent) { diff --git a/test/libc/calls/open_test.c b/test/libc/calls/open_test.c index 6125684ba..87545b603 100644 --- a/test/libc/calls/open_test.c +++ b/test/libc/calls/open_test.c @@ -47,9 +47,6 @@ void SetUpOnce(void) { TEST(open, efault) { ASSERT_SYS(EFAULT, -1, open(0, O_RDONLY)); - if (IsWindows() || !IsAsan()) - return; // not possible - ASSERT_SYS(EFAULT, -1, open((void *)77, O_RDONLY)); } TEST(open, enoent) { diff --git a/test/libc/calls/setrlimit_test.c b/test/libc/calls/setrlimit_test.c index dd95408c4..b9f57bcfc 100644 --- a/test/libc/calls/setrlimit_test.c +++ b/test/libc/calls/setrlimit_test.c @@ -131,8 +131,6 @@ TEST(setrlimit, testMemoryLimit) { int i, wstatus; if (IsXnu()) return; - if (IsAsan()) - return; /* b/c we use sys_mmap */ ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM)); @@ -162,8 +160,6 @@ TEST(setrlimit, testMemoryLimit) { TEST(setrlimit, testVirtualMemoryLimit) { char *p; int i, wstatus; - if (IsAsan()) - return; if (IsXnu()) return; /* doesn't work on darwin */ if (IsOpenbsd()) @@ -194,8 +190,6 @@ TEST(setrlimit, testVirtualMemoryLimit) { TEST(setrlimit, testDataMemoryLimit) { char *p; int i, wstatus; - if (IsAsan()) - return; if (IsXnu()) return; /* doesn't work on darwin */ if (IsNetbsd()) diff --git a/test/libc/calls/sigaction_test.c b/test/libc/calls/sigaction_test.c index d9e5cb735..9206016e2 100644 --- a/test/libc/calls/sigaction_test.c +++ b/test/libc/calls/sigaction_test.c @@ -374,7 +374,7 @@ void OnSegfault(int sig) { } } -dontubsan dontasan int Segfault(char *p) { +dontubsan int Segfault(char *p) { return *p; } diff --git a/test/libc/calls/unlinkat_test.c b/test/libc/calls/unlinkat_test.c index 99511f48d..2bcb29534 100644 --- a/test/libc/calls/unlinkat_test.c +++ b/test/libc/calls/unlinkat_test.c @@ -30,9 +30,6 @@ void SetUpOnce(void) { TEST(unlink, efault) { ASSERT_SYS(EFAULT, -1, unlink(0)); - if (IsWindows() || !IsAsan()) - return; // not possible - ASSERT_SYS(EFAULT, -1, unlink((void *)77)); } TEST(unlink, enoent) { diff --git a/test/libc/calls/write_test.c b/test/libc/calls/write_test.c index 77ddfd9a1..bfcfdab6c 100644 --- a/test/libc/calls/write_test.c +++ b/test/libc/calls/write_test.c @@ -66,9 +66,6 @@ TEST(write, readOnlyFd_ebadf) { TEST(write, badMemory_efault) { ASSERT_SYS(EFAULT, -1, write(1, 0, 1)); - if (!IsAsan()) - return; - ASSERT_SYS(EFAULT, -1, write(1, (void *)1, 1)); } TEST(write, brokenPipe_raisesSigpipe) { diff --git a/test/libc/calls/writev_test.c b/test/libc/calls/writev_test.c index 796d9ff59..c6a9a9540 100644 --- a/test/libc/calls/writev_test.c +++ b/test/libc/calls/writev_test.c @@ -96,30 +96,6 @@ TEST(writev, big_fullCompletion) { EXPECT_NE(-1, close(fd)); } -TEST(writev, asanError_efaults) { - if (!IsAsan()) - return; - void *malloc_(size_t) asm("malloc"); - void free_(void *) asm("free"); - void *p; - int fd; - p = malloc_(32); - EXPECT_NE(-1, (fd = open("asan", O_RDWR | O_CREAT | O_TRUNC, 0644))); - EXPECT_EQ(32, write(fd, p, 32)); - EXPECT_NE(-1, lseek(fd, 0, SEEK_SET)); - EXPECT_EQ(32, read(fd, p, 32)); - EXPECT_EQ(-1, write(fd, p, 33)); - EXPECT_EQ(EFAULT, errno); - EXPECT_EQ(-1, write(fd, p, -1)); - EXPECT_EQ(EFAULT, errno); - free_(p); - EXPECT_EQ(-1, write(fd, p, 32)); - EXPECT_EQ(EFAULT, errno); - EXPECT_EQ(-1, read(fd, p, 32)); - EXPECT_EQ(EFAULT, errno); - close(fd); -} - TEST(writev, empty_stillPerformsIoOperation) { int fd; struct iovec iov[] = {{"", 0}, {NULL, 0}}; diff --git a/test/libc/intrin/memset_test.c b/test/libc/intrin/memset_test.c index 056e05b34..4d818845a 100644 --- a/test/libc/intrin/memset_test.c +++ b/test/libc/intrin/memset_test.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" @@ -25,10 +24,8 @@ #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -static dontasan void *golden(void *p, int c, size_t n) { +static void *golden(void *p, int c, size_t n) { size_t i; - if (IsAsan()) - __asan_verify(p, n); for (i = 0; i < n; ++i) ((char *)p)[i] = c; return p; diff --git a/test/libc/intrin/mmap_test.c b/test/libc/intrin/mmap_test.c index 75f5c6cc4..d28f5c80b 100644 --- a/test/libc/intrin/mmap_test.c +++ b/test/libc/intrin/mmap_test.c @@ -22,7 +22,6 @@ #include "libc/calls/ucontext.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" @@ -146,17 +145,6 @@ TEST(mmap, smallerThanPage_mapsRemainder) { EXPECT_FALSE(testlib_memoryexists(map + (pagesz - 1))); } -TEST(mmap, smallerThanPage_remainderIsPoisoned) { - if (!IsAsan()) - return; - char *map; - ASSERT_NE(MAP_FAILED, (map = mmap(0, 1, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))); - EXPECT_TRUE(__asan_is_valid(map, 1)); - EXPECT_FALSE(__asan_is_valid(map + 1, 1)); - EXPECT_SYS(0, 0, munmap(map, 1)); -} - TEST(mmap, testMapFile) { int fd; char *p; diff --git a/test/libc/intrin/munmap_test.c b/test/libc/intrin/munmap_test.c index 02c6c9038..a420ad659 100644 --- a/test/libc/intrin/munmap_test.c +++ b/test/libc/intrin/munmap_test.c @@ -35,10 +35,6 @@ void SetUpOnce(void) { TEST(munmap, doesntExist_doesntCare) { EXPECT_SYS(0, 0, munmap(0, granularity * 8)); - if (IsAsan()) { - // make sure it didn't unmap the null pointer shadow memory - EXPECT_TRUE(testlib_memoryexists((char *)0x7fff8000)); - } } TEST(munmap, invalidParams) { @@ -142,38 +138,6 @@ TEST(munmap, memoryGone) { EXPECT_SYS(0, 0, munmap(p, granularity)); } -TEST(munmap, testTooSmallToUnmapAsan) { - if (!IsAsan()) - return; - char *p; - ASSERT_NE(MAP_FAILED, (p = mmap(0, granularity, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0))); - EXPECT_TRUE(testlib_memoryexists((char *)(((intptr_t)p >> 3) + 0x7fff8000))); - EXPECT_SYS(0, 0, munmap(p, granularity)); - EXPECT_TRUE(testlib_memoryexists((char *)(((intptr_t)p >> 3) + 0x7fff8000))); -} - -TEST(munmap, testLargeEnoughToUnmapAsan) { - if (!IsAsan()) - return; - if (IsWindows()) { - // we're unfortunately never able to unmap asan pages on windows - // because the memtrack array items always have to be 64kb so we - // we're able to store a handle for each - return; - } - char *p; - size_t n; - n = granularity * 8 * 2; - ASSERT_NE(MAP_FAILED, (p = mmap(0, n, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0))); - EXPECT_SYS(0, 0, munmap(p, n)); -#if 0 - EXPECT_FALSE( - testlib_memoryexists((char *)(((intptr_t)(p + n / 2) >> 3) + 0x7fff8000))); -#endif -} - TEST(munmap, tinyFile_roundupUnmapSize) { char *p; ASSERT_SYS(0, 3, open("doge", O_WRONLY | O_CREAT | O_TRUNC, 0644)); diff --git a/test/libc/log/backtrace_test.c b/test/libc/log/backtrace_test.c index 409876f45..ab735e4cf 100644 --- a/test/libc/log/backtrace_test.c +++ b/test/libc/log/backtrace_test.c @@ -21,7 +21,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" -#include "libc/intrin/asan.internal.h" #include "libc/limits.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" @@ -86,10 +85,6 @@ TEST(ShowCrashReports, testMemoryLeakCrash) { ssize_t rc; int ws, pid, fds[2]; char *output, buf[512]; - if (!IsAsan()) { - /* TODO(jart): How can we make this work without ASAN? */ - return; - } ASSERT_NE(-1, pipe2(fds, O_CLOEXEC)); ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -254,53 +249,6 @@ TEST(ShowCrashReports, testDivideByZero) { free(output); } -// clang-format off -// -// test/libc/log/backtrace_test.c:59: ubsan error: 'int' index 10 into 'char [10]' out of bounds -// 0x000000000040a352: __die at libc/log/die.c:40 -// 0x0000000000489bc8: __ubsan_abort at libc/intrin/ubsan.c:196 -// 0x0000000000489e1c: __ubsan_handle_out_of_bounds at libc/intrin/ubsan.c:242 -// 0x0000000000423666: BssOverrunCrash at test/libc/log/backtrace_test.c:59 -// 0x0000000000423e0a: SetUp at test/libc/log/backtrace_test.c:115 -// 0x000000000049350b: testlib_runtestcases at libc/testlib/testrunner.c:98 -// 0x000000000048ab50: testlib_runalltests at libc/testlib/runner.c:37 -// 0x00000000004028d0: main at libc/testlib/testmain.c:94 -// 0x0000000000403977: cosmo at libc/runtime/cosmo.S:69 -// 0x00000000004021ae: _start at libc/crt/crt.S:78 -// -// asan error: global redzone 1-byte store at 0x00000048cf2a shadow 0x0000800899e5 -// x -// ........................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO -// |0 |0 |0 |0 |2 |-6 |-6 |-6 |-6 -//                                ☺☻♥♦♣♠•◘○                                         -// 000000400000-000000460000 .text -// 000000460000-000000468000 .data -// 00007fff0000-00008000ffff -// 000080070000-00008009ffff ←shadow -// 02008fff0000-02009001ffff -// 020090060000-02009007ffff -// 0e007ffb0000-0e008000ffff -// 1000286b0000-1000286cffff -// 100080000000-10008009ffff -// 100080350000-10008036ffff -// 100080380000-10008038ffff -// 6fffffe00000-6fffffffffff -// 0x0000000000407af6: __die at libc/log/die.c:36 -// 0x0000000000444f13: __asan_die at libc/intrin/asan.c:318 -// 0x0000000000445bc8: __asan_report at libc/intrin/asan.c:667 -// 0x0000000000445e41: __asan_report_memory_fault at libc/intrin/asan.c:672 -// 0x0000000000446312: __asan_report_store at libc/intrin/asan.c:1008 -// 0x0000000000444442: __asan_report_store1 at libc/intrin/somanyasan.S:118 -// 0x0000000000416216: BssOverrunCrash at test/libc/log/backtrace_test.c:52 -// 0x000000000041642a: SetUp at test/libc/log/backtrace_test.c:73 -// 0x00000000004513eb: testlib_runtestcases at libc/testlib/testrunner.c:98 -// 0x000000000044bbe0: testlib_runalltests at libc/testlib/runner.c:37 -// 0x00000000004026db: main at libc/testlib/testmain.c:155 -// 0x000000000040323f: cosmo at libc/runtime/cosmo.S:64 -// 0x000000000040219b: _start at libc/crt/crt.S:67 -// -// clang-format on - TEST(ShowCrashReports, testBssOverrunCrash) { if (!IsAsan()) return; size_t got; @@ -348,78 +296,6 @@ TEST(ShowCrashReports, testBssOverrunCrash) { free(output); } -// clang-format off -// asan error: null pointer dereference 1-byte load at 0x000000000000 shadow 0x00007fff8000 -// x -// MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅∅ -// |-17 |-17 |-17 |-17 |-17 |-1 |-1 |-1 |-1 |-1 -// ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -// 000000400000-000000464000 .text -// 000000464000-00000046d000 .data -// 00007fff0000-00008000ffff ←shadow -// 000080070000-00008009ffff -// 02008fff0000-02009001ffff -// 020090060000-02009007ffff -// 0e007fff0000-0e008000ffff -// 10000d3e0000-10000d3fffff -// 100080000000-10008009ffff -// 100080370000-10008038ffff -// 1000803a0000-1000803affff -// 6ffffffe0000-6fffffffffff -// 0x0000000000407c84: __die at libc/log/die.c:37 -// 0x000000000040b1ee: __asan_report_load at libc/intrin/asan.c:1083 -// 0x000000000041639e: NpeCrash at test/libc/log/backtrace_test.c:87 -// 0x0000000000416733: SetUp at test/libc/log/backtrace_test.c:120 -// 0x00000000004541fb: testlib_runtestcases at libc/testlib/testrunner.c:98 -// 0x000000000044d000: testlib_runalltests at libc/testlib/runner.c:37 -// 0x00000000004026db: main at libc/testlib/testmain.c:94 -// 0x000000000040327f: cosmo at libc/runtime/cosmo.S:64 -// 0x000000000040219b: _start at libc/crt/crt.S:67 -// clang-format on -TEST(ShowCrashReports, testNpeCrash) { - if (!IsAsan()) return; - size_t got; - ssize_t rc; - int ws, pid, fds[2]; - char *output, buf[512]; - ASSERT_NE(-1, pipe2(fds, O_CLOEXEC)); - ASSERT_NE(-1, (pid = fork())); - if (!pid) { - dup2(fds[1], 1); - dup2(fds[1], 2); - execv("bin/backtrace", (char *const[]){"bin/backtrace", "7", 0}); - _Exit(127); - } - close(fds[1]); - output = 0; - appends(&output, ""); - for (;;) { - rc = read(fds[0], buf, sizeof(buf)); - if (rc == -1) { - ASSERT_EQ(EINTR, errno); - continue; - } - if ((got = rc)) { - appendd(&output, buf, got); - } else { - break; - } - } - close(fds[0]); - ASSERT_NE(-1, wait(&ws)); - // tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL); - EXPECT_EQ(77 << 8, ws); - /* NULL is stopgap until we can copy symbol tables into binary */ - ASSERT_TRUE(!!strstr(output, "null pointer")); -#ifdef __FNO_OMIT_FRAME_POINTER__ - ASSERT_TRUE(OutputHasSymbol(output, "NpeCrash")); -#endif - if (!strstr(output, "null pointer access")) { // ubsan - ASSERT_TRUE(!!strstr(output, "∅∅∅∅")); // asan - } - free(output); -} - TEST(ShowCrashReports, testDataOverrunCrash) { if (!IsAsan()) return; size_t got; diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index 96f52b289..0fceb4649 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -21,7 +21,6 @@ #include "libc/calls/struct/timespec.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/safemacros.internal.h" @@ -50,46 +49,26 @@ TEST(malloc, zero) { char *p; ASSERT_NE(NULL, (p = malloc(0))); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p, 1)); free(p); } TEST(realloc, bothAreZero_createsMinimalAllocation) { char *p; ASSERT_NE(NULL, (p = realloc(0, 0))); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p, 1)); free(p); } TEST(realloc, ptrIsZero_createsAllocation) { char *p; ASSERT_NE(NULL, (p = realloc(0, 1))); - if (IsAsan()) - ASSERT_TRUE(__asan_is_valid(p, 1)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p + 1, 1)); ASSERT_EQ(p, realloc(p, 0)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p, 1)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p + 1, 1)); free(p); } TEST(realloc, sizeIsZero_shrinksAllocation) { char *p; ASSERT_NE(NULL, (p = malloc(1))); - if (IsAsan()) - ASSERT_TRUE(__asan_is_valid(p, 1)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p + 1, 1)); ASSERT_EQ(p, realloc(p, 0)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p, 1)); - if (IsAsan()) - ASSERT_FALSE(__asan_is_valid(p + 1, 1)); free(p); } diff --git a/test/libc/runtime/tls_test.c b/test/libc/runtime/tls_test.c index ef8f086cc..b47f3c0cb 100644 --- a/test/libc/runtime/tls_test.c +++ b/test/libc/runtime/tls_test.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/thread/tls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/testlib/testlib.h" #include "libc/thread/thread.h" @@ -35,9 +34,6 @@ dontubsan void *Worker(void *arg) { ASSERT_EQ(0, (uintptr_t)&a & (_Alignof(a) - 1)); ASSERT_EQ(42, x + y[0] + z); ASSERT_EQ(0, (intptr_t)&a & (A - 1)); - if (IsAsan()) { - ASSERT_EQ(kAsanProtected, __asan_check(y + 1, sizeof(long)).kind); - } return 0; } @@ -53,8 +49,4 @@ TEST(tls, test) { ASSERT_EQ(0, (intptr_t)&a & (A - 1)); ASSERT_EQ(0, pthread_create(&t, 0, Worker, 0)); ASSERT_EQ(0, pthread_join(t, 0)); - if (IsAsan()) { - // TODO(jart): Why isn't it poisoned? - // ASSERT_EQ(kAsanProtected, __asan_check(y + 1, sizeof(long)).kind); - } } diff --git a/test/libc/runtime/zipos_test.c b/test/libc/runtime/zipos_test.c index d25ea1540..c77614a85 100644 --- a/test/libc/runtime/zipos_test.c +++ b/test/libc/runtime/zipos_test.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" -#include "libc/intrin/asan.internal.h" #include "libc/limits.h" #include "libc/mem/gc.h" #include "libc/mem/mem.h" diff --git a/test/libc/stdio/dirstream_test.c b/test/libc/stdio/dirstream_test.c index e334f85c5..84b76387b 100644 --- a/test/libc/stdio/dirstream_test.c +++ b/test/libc/stdio/dirstream_test.c @@ -60,9 +60,6 @@ void SetUp(void) { TEST(opendir, efault) { ASSERT_SYS(EFAULT, NULL, opendir(0)); - if (!IsAsan()) - return; // not possible - ASSERT_SYS(EFAULT, NULL, opendir((void *)77)); } TEST(opendir, enoent) { diff --git a/test/libc/str/crc32z_test.c b/test/libc/str/crc32z_test.c index 92f329ace..7caced62d 100644 --- a/test/libc/str/crc32z_test.c +++ b/test/libc/str/crc32z_test.c @@ -19,7 +19,6 @@ #include "libc/assert.h" #include "libc/calls/struct/timespec.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" diff --git a/test/libc/thread/makecontext_test.c b/test/libc/thread/makecontext_test.c index 3f53241d6..629dc07b8 100644 --- a/test/libc/thread/makecontext_test.c +++ b/test/libc/thread/makecontext_test.c @@ -76,7 +76,7 @@ TEST(makecontext, args) { EXPECT_TRUE(gotsome); } -dontasan dontubsan void itsatrap(int x, int y) { +dontubsan void itsatrap(int x, int y) { *(int *)(intptr_t)x = scalbn(x, y); } diff --git a/third_party/chibicc/parse.c b/third_party/chibicc/parse.c index 8c1c98e9a..1ddb57693 100644 --- a/third_party/chibicc/parse.c +++ b/third_party/chibicc/parse.c @@ -17,7 +17,6 @@ // parser. #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" #include "libc/mem/mem.h" diff --git a/third_party/compiler_rt/BUILD.mk b/third_party/compiler_rt/BUILD.mk index 1bf28577c..dc933ee62 100644 --- a/third_party/compiler_rt/BUILD.mk +++ b/third_party/compiler_rt/BUILD.mk @@ -46,8 +46,7 @@ $(THIRD_PARTY_COMPILER_RT_A).pkg: \ $(THIRD_PARTY_COMPILER_RT_A_OBJS): private \ DEFAULT_CFLAGS += \ $(OLD_CODE) \ - -DCRT_HAS_128BIT \ - -fno-sanitize=address + -DCRT_HAS_128BIT # these assembly files are safe to build on aarch64 o/$(MODE)/third_party/compiler_rt/comprt.o: third_party/compiler_rt/comprt.S diff --git a/third_party/dlmalloc/BUILD.mk b/third_party/dlmalloc/BUILD.mk index 0a5ce8a35..8b7b9d6dc 100644 --- a/third_party/dlmalloc/BUILD.mk +++ b/third_party/dlmalloc/BUILD.mk @@ -55,7 +55,6 @@ $(THIRD_PARTY_DLMALLOC_A_OBJS): private \ -ffreestanding \ -fdata-sections \ -ffunction-sections \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/third_party/dlmalloc/vespene.c b/third_party/dlmalloc/vespene.c index b6a0349a2..02ab7e46c 100644 --- a/third_party/dlmalloc/vespene.c +++ b/third_party/dlmalloc/vespene.c @@ -17,8 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" -#include "libc/intrin/asancodes.h" #include "libc/runtime/runtime.h" #include "third_party/dlmalloc/vespene.internal.h" @@ -27,9 +25,5 @@ * @return memory map address on success, or null w/ errno */ void *dlmalloc_requires_more_vespene_gas(size_t size) { - char *p; - if ((p = _mapanon(size))) - if (IsAsan()) - __asan_poison(p, size, kAsanHeapFree); - return p; + return _mapanon(size); } diff --git a/third_party/getopt/BUILD.mk b/third_party/getopt/BUILD.mk index 535e43fd7..7e6b1e0cb 100644 --- a/third_party/getopt/BUILD.mk +++ b/third_party/getopt/BUILD.mk @@ -34,8 +34,6 @@ $(THIRD_PARTY_GETOPT_A).pkg: \ $(THIRD_PARTY_GETOPT_A_OBJS) \ $(foreach x,$(THIRD_PARTY_GETOPT_A_DIRECTDEPS),$($(x)_A).pkg) -$(THIRD_PARTY_GETOPT_A_OBJS): private COPTS += -fno-sanitize=address - THIRD_PARTY_GETOPT_LIBS = $(foreach x,$(THIRD_PARTY_GETOPT_ARTIFACTS),$($(x))) THIRD_PARTY_GETOPT_SRCS = $(foreach x,$(THIRD_PARTY_GETOPT_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_GETOPT_HDRS = $(foreach x,$(THIRD_PARTY_GETOPT_ARTIFACTS),$($(x)_HDRS)) diff --git a/third_party/linenoise/linenoise.c b/third_party/linenoise/linenoise.c index d402c6ae0..8c7c0d144 100644 --- a/third_party/linenoise/linenoise.c +++ b/third_party/linenoise/linenoise.c @@ -138,7 +138,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" -#include "libc/intrin/asan.internal.h" #include "libc/serialize.h" #include "libc/intrin/bsr.h" #include "libc/intrin/nomultics.internal.h" diff --git a/third_party/mbedtls/ecp384.c b/third_party/mbedtls/ecp384.c index 900b6e94b..896fff425 100644 --- a/third_party/mbedtls/ecp384.c +++ b/third_party/mbedtls/ecp384.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/asan.internal.h" #include "libc/nexgen32e/x86feature.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -411,8 +410,6 @@ int mbedtls_p384_double_jac( const mbedtls_ecp_group *G, { int ret; uint64_t T[4][12]; - if( IsAsan() ) __asan_verify( P, sizeof( *P ) ); - if( IsAsan() ) __asan_verify( R, sizeof( *R ) ); if( ( ret = mbedtls_p384_dim( R ) ) ) return( ret ); if( ( ret = mbedtls_p384_dim( (void *)P ) ) ) return( ret ); mbedtls_platform_zeroize( T, sizeof( T ) ); @@ -453,10 +450,6 @@ int mbedtls_p384_add_mixed( const mbedtls_ecp_group *G, uint64_t T1[12], T2[12], T3[12], T4[12]; size_t Xn, Yn, Zn, QXn, QYn; } s; - if( IsAsan() ) __asan_verify( G, sizeof( *G ) ); - if( IsAsan() ) __asan_verify( P, sizeof( *P ) ); - if( IsAsan() ) __asan_verify( Q, sizeof( *Q ) ); - if( IsAsan() ) __asan_verify( R, sizeof( *R ) ); if( ( ret = mbedtls_p384_dim( R ) ) ) return( ret ); mbedtls_platform_zeroize( &s, sizeof( s ) ); s.Xn = mbedtls_mpi_limbs( &P->X ); diff --git a/third_party/mbedtls/sha1.c b/third_party/mbedtls/sha1.c index be933c939..7507a7445 100644 --- a/third_party/mbedtls/sha1.c +++ b/third_party/mbedtls/sha1.c @@ -16,7 +16,6 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/mbedtls/sha1.h" -#include "libc/intrin/asan.internal.h" #include "libc/serialize.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/sha.h" @@ -111,11 +110,6 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, if( X86_HAVE( SHA ) ) { - if( IsAsan() ) - { - __asan_verify( data, 64 ); - __asan_verify( ctx, sizeof(*ctx) ); - } sha1_transform_ni( ctx->state, data, 1 ); return( 0 ); } @@ -123,11 +117,6 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, X86_HAVE( BMI2 ) && X86_HAVE( AVX2 ) ) { - if( IsAsan() ) - { - __asan_verify( data, 64 ); - __asan_verify( ctx, sizeof(*ctx) ); - } sha1_transform_avx2( ctx->state, data, 1 ); return( 0 ); } @@ -406,8 +395,6 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, { if( X86_HAVE( SHA ) ) { - if( IsAsan() ) - __asan_verify( input, ilen ); sha1_transform_ni( ctx->state, input, ilen / 64 ); input += ROUNDDOWN( ilen, 64 ); ilen -= ROUNDDOWN( ilen, 64 ); @@ -416,8 +403,6 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, X86_HAVE( BMI2 ) && X86_HAVE( AVX2 ) ) { - if( IsAsan() ) - __asan_verify( input, ilen ); sha1_transform_avx2( ctx->state, input, ilen / 64 ); input += ROUNDDOWN( ilen, 64 ); ilen -= ROUNDDOWN( ilen, 64 ); diff --git a/third_party/mbedtls/sha256.c b/third_party/mbedtls/sha256.c index 88e621b53..03e979011 100644 --- a/third_party/mbedtls/sha256.c +++ b/third_party/mbedtls/sha256.c @@ -17,7 +17,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/mbedtls/sha256.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/sha.h" @@ -170,8 +169,6 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, X86_HAVE( SSE2 ) && X86_HAVE( SSSE3 ) ) { - if( IsAsan() ) - __asan_verify( data, 64 ); sha256_transform_ni( ctx->state, data, 1 ); return( 0 ); } @@ -179,8 +176,6 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, X86_HAVE( AVX ) && X86_HAVE( AVX2 ) ) { - if( IsAsan() ) - __asan_verify( data, 64 ); sha256_transform_rorx( ctx->state, data, 1 ); return( 0 ); } @@ -306,8 +301,6 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, X86_HAVE( SSE2 ) && X86_HAVE( SSSE3 ) ) { - if( IsAsan() ) - __asan_verify( input, ilen ); sha256_transform_ni( ctx->state, input, ilen / 64 ); input += ROUNDDOWN( ilen, 64 ); ilen -= ROUNDDOWN( ilen, 64 ); @@ -316,8 +309,6 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, X86_HAVE( BMI2 ) && X86_HAVE( AVX2 ) ) { - if( IsAsan() ) - __asan_verify( input, ilen ); sha256_transform_rorx( ctx->state, input, ilen / 64 ); input += ROUNDDOWN( ilen, 64 ); ilen -= ROUNDDOWN( ilen, 64 ); diff --git a/third_party/mbedtls/sha512.c b/third_party/mbedtls/sha512.c index 8f4494787..82469e893 100644 --- a/third_party/mbedtls/sha512.c +++ b/third_party/mbedtls/sha512.c @@ -16,7 +16,6 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/mbedtls/sha512.h" -#include "libc/intrin/asan.internal.h" #include "libc/literal.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/nexgen32e.h" @@ -167,8 +166,6 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, if( !IsTiny() && X86_HAVE(AVX2) ) { - if (IsAsan()) - __asan_verify(data, 128); sha512_transform_rorx(ctx, data, 1); return 0; } @@ -279,7 +276,6 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, left = 0; } if (!IsTiny() && ilen >= 128 && X86_HAVE(AVX2)) { - if (IsAsan()) __asan_verify(input, ilen / 128 * 128); sha512_transform_rorx(ctx, input, ilen / 128); input += ROUNDDOWN(ilen, 128); ilen -= ROUNDDOWN(ilen, 128); diff --git a/third_party/nsync/BUILD.mk b/third_party/nsync/BUILD.mk index 67d1752a8..362f1dde0 100644 --- a/third_party/nsync/BUILD.mk +++ b/third_party/nsync/BUILD.mk @@ -53,7 +53,6 @@ $(THIRD_PARTY_NSYNC_A_OBJS): private \ -ffreestanding \ -fdata-sections \ -ffunction-sections \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/third_party/nsync/mem/BUILD.mk b/third_party/nsync/mem/BUILD.mk index bc50768d6..aa5c3c1e3 100644 --- a/third_party/nsync/mem/BUILD.mk +++ b/third_party/nsync/mem/BUILD.mk @@ -46,7 +46,6 @@ $(THIRD_PARTY_NSYNC_MEM_A_OBJS): private \ -ffreestanding \ -fdata-sections \ -ffunction-sections \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/third_party/puff/BUILD.mk b/third_party/puff/BUILD.mk index 791eea13a..9e531bbef 100644 --- a/third_party/puff/BUILD.mk +++ b/third_party/puff/BUILD.mk @@ -36,7 +36,6 @@ $(THIRD_PARTY_PUFF_A).pkg: \ $(THIRD_PARTY_PUFF_A_OBJS): private \ COPTS += \ -ffreestanding \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/third_party/python/Objects/object.c b/third_party/python/Objects/object.c index 7ff7bd7de..9f577f8b9 100644 --- a/third_party/python/Objects/object.c +++ b/third_party/python/Objects/object.c @@ -1897,7 +1897,7 @@ _Py_NewReference(PyObject *op) _Py_INC_TPALLOCS(op); } -dontasan void +void _Py_ForgetReference(PyObject *op) { #ifdef SLOW_UNREF_CHECK diff --git a/third_party/python/Objects/obmalloc.c b/third_party/python/Objects/obmalloc.c index 47a793fec..9d75a106d 100644 --- a/third_party/python/Objects/obmalloc.c +++ b/third_party/python/Objects/obmalloc.c @@ -7,7 +7,6 @@ #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/intrin/asan.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/map.h" @@ -1876,13 +1875,13 @@ bumpserialno(void) #define SST SIZEOF_SIZE_T -static inline optimizespeed dontasan size_t +static inline optimizespeed size_t read_size_t(const void *p) { return READ64BE(p); } -static inline optimizespeed dontasan void +static inline optimizespeed void write_size_t(void *p, size_t n) { WRITE64BE((char *)p, n); @@ -1950,11 +1949,6 @@ _PyMem_DebugRawAlloc(int use_calloc, void *ctx, size_t nbytes) write_size_t(tail + SST, serialno); _PyMem_DebugCheckAddress(api->api_id, p+2*SST); - if (IsAsan()) { - __asan_poison((p + SST + 1), SST-1, kAsanHeapUnderrun); - __asan_poison(tail, SST, kAsanHeapOverrun); - } - return p + 2*SST; } @@ -2007,15 +2001,12 @@ _PyMem_DebugRawFree(void *ctx, void *p) nbytes = read_size_t(q); nbytes += 4*SST; if (nbytes > 0) { - if (IsAsan()) { - __asan_unpoison(q, nbytes); - } memset(q, DEADBYTE, nbytes); } api->alloc.free(api->alloc.ctx, q); } -static dontasan void * +static void * _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) { _Static_assert(sizeof(size_t) == 8, ""); @@ -2047,14 +2038,9 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) tail = q + nbytes; w = 0x0101010101010101ull * FORBIDDENBYTE; WRITE64LE(tail, w); - if (IsAsan()) __asan_poison(tail, SST, kAsanHeapOverrun); write_size_t(tail + SST, serialno); if (nbytes > original_nbytes) { /* growing: mark new extra memory clean */ - if (IsAsan()) { - __asan_unpoison((q + original_nbytes), - nbytes - original_nbytes); - } memset(q + original_nbytes, CLEANBYTE, nbytes - original_nbytes); } @@ -2104,7 +2090,7 @@ _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes) * and call Py_FatalError to kill the program. * The API id, is also checked. */ -static dontasan void +static void _PyMem_DebugCheckAddress(char api, const void *p) { const uint8_t *q = (const uint8_t *)p; @@ -2157,7 +2143,7 @@ error: } /* Display info to stderr about the memory block at p. */ -static dontasan void +static void _PyObject_DebugDumpAddress(const void *p) { const uint8_t *q = (const uint8_t *)p; diff --git a/third_party/xed/BUILD.mk b/third_party/xed/BUILD.mk index c801832fb..daf77a61d 100644 --- a/third_party/xed/BUILD.mk +++ b/third_party/xed/BUILD.mk @@ -53,7 +53,6 @@ o/$(MODE)/third_party/xed/x86ild.greg.o: private \ $(THIRD_PARTY_XED_A_OBJS): private \ COPTS += \ -ffreestanding \ - -fno-sanitize=address \ -Wframe-larger-than=4096 \ -Walloca-larger-than=4096 diff --git a/tool/emacs/cosmo-c-keywords.el b/tool/emacs/cosmo-c-keywords.el index 3f4f691c5..ff4acc144 100644 --- a/tool/emacs/cosmo-c-keywords.el +++ b/tool/emacs/cosmo-c-keywords.el @@ -83,8 +83,6 @@ "hasatleast" "nodebuginfo" "wontreturn" - "dontasan" - "nomsan" "dontubsan" "nostackprotector" "mayalias" diff --git a/tool/emacs/cosmo-stuff.el b/tool/emacs/cosmo-stuff.el index c18fbec96..1ca81f45a 100644 --- a/tool/emacs/cosmo-stuff.el +++ b/tool/emacs/cosmo-stuff.el @@ -509,7 +509,7 @@ "V=1 OVERRIDE_COPTS='-w -fverbose-asm -fsanitize=undefined -fno-sanitize=null -fno-sanitize=alignment -fno-sanitize=pointer-overflow'")) ;; ((not (eq 0 (logand 8 arg))) ;; (cosmo--assembly (setq arg (logand (lognot 8))) - ;; "V=1 OVERRIDE_COPTS='-w -fverbose-asm -fsanitize=address'")) + ;; "V=1 OVERRIDE_COPTS='-w -fverbose-asm'")) (t (cosmo--assembly arg "V=1 OVERRIDE_COPTS='-w ' CPPFLAGS=''")))) (defun cosmo-assembly-native (arg)