Delete ASAN

It hasn't been helpful enough to be justify the maintenance burden. What
actually does help is mprotect(), kprintf(), --ftrace and --strace which
can always be counted upon to work correctly. We aren't losing much with
this change. Support for ASAN on AARCH64 was never implemented. Applying
ASAN to the core libc runtimes was disabled many months ago. If there is
some way to have an ASAN runtime for user programs that is less invasive
we can potentially consider reintroducing support. But now is premature.
This commit is contained in:
Justine Tunney 2024-06-22 05:45:49 -07:00
parent 6ffed14b9c
commit d1d4388201
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
198 changed files with 130 additions and 2954 deletions

View file

@ -162,7 +162,6 @@ o/$(MODE)/ape/ape-no-modify-self.o: \
libc/dce.h \ libc/dce.h \
libc/elf/def.h \ libc/elf/def.h \
libc/thread/tls.h \ libc/thread/tls.h \
libc/intrin/asancodes.h \
libc/macho.internal.h \ libc/macho.internal.h \
libc/macros.internal.h \ libc/macros.internal.h \
libc/nexgen32e/uart.internal.h \ libc/nexgen32e/uart.internal.h \
@ -189,7 +188,6 @@ o/$(MODE)/ape/ape-copy-self.o: \
libc/dce.h \ libc/dce.h \
libc/elf/def.h \ libc/elf/def.h \
libc/thread/tls.h \ libc/thread/tls.h \
libc/intrin/asancodes.h \
libc/macho.internal.h \ libc/macho.internal.h \
libc/macros.internal.h \ libc/macros.internal.h \
libc/nexgen32e/uart.internal.h \ libc/nexgen32e/uart.internal.h \

View file

@ -127,32 +127,10 @@ TARGET_ARCH ?= -msse3
PYFLAGS += -O1 PYFLAGS += -O1
endif 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 # Debug Mode
# #
# - `make MODE=dbg` # - `make MODE=dbg`
# - Backtraces # - Backtraces
# - Enables asan
# - Enables ubsan # - Enables ubsan
# - Stack canaries # - Stack canaries
# - No optimization # - No optimization
@ -161,9 +139,9 @@ endif
ifeq ($(MODE), dbg) ifeq ($(MODE), dbg)
ENABLE_FTRACE = 1 ENABLE_FTRACE = 1
CONFIG_OFLAGS ?= -g -ggdb 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_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O0 -fno-inline
CONFIG_COPTS += -fsanitize=address -fsanitize=undefined CONFIG_COPTS += -fsanitize=undefined
TARGET_ARCH ?= -msse3 TARGET_ARCH ?= -msse3
OVERRIDE_CCFLAGS += -fno-pie OVERRIDE_CCFLAGS += -fno-pie
QUOTA ?= -C64 -L300 QUOTA ?= -C64 -L300

View file

@ -64,9 +64,6 @@ BACKTRACES = \
-fno-optimize-sibling-calls \ -fno-optimize-sibling-calls \
-mno-omit-leaf-frame-pointer -mno-omit-leaf-frame-pointer
SANITIZER = \
-fsanitize=address
NO_MAGIC = \ NO_MAGIC = \
-ffreestanding \ -ffreestanding \
-fno-stack-protector \ -fno-stack-protector \

View file

@ -1,16 +0,0 @@
#include <stdlib.h>
__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;
}

View file

@ -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_ */

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/log/log.h" #include "libc/log/log.h"
@ -59,7 +58,7 @@ int chdir(const char *path) {
if (_weaken(GetProgramExecutableName)) { if (_weaken(GetProgramExecutableName)) {
_weaken(GetProgramExecutableName)(); _weaken(GetProgramExecutableName)();
} }
if (!path || (IsAsan() && !__asan_is_valid_str(path))) { if (!path) {
rc = efault(); rc = efault();
} else if (_weaken(__zipos_parseuri) && } else if (_weaken(__zipos_parseuri) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) { _weaken(__zipos_parseuri)(path, &zipname) != -1) {

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -49,7 +48,7 @@
*/ */
int chroot(const char *path) { int chroot(const char *path) {
int rc; int rc;
if (!path || (IsAsan() && !__asan_is_valid_str(path))) { if (!path) {
rc = efault(); rc = efault();
} else { } else {
rc = sys_chroot(path); rc = sys_chroot(path);

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/describeflags.internal.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 clock_getres(int clock, struct timespec *ts) {
int rc; int rc;
if (!ts || (IsAsan() && !__asan_is_valid_timespec(ts))) { if (!ts) {
rc = efault(); rc = efault();
} else if (clock == 127) { } else if (clock == 127) {
rc = einval(); // 127 is used by consts.sh to mean unsupported rc = einval(); // 127 is used by consts.sh to mean unsupported

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
@ -35,7 +34,7 @@ int clock_settime(int clockid, const struct timespec *ts) {
struct timeval tv; struct timeval tv;
if (clockid == 127) { if (clockid == 127) {
rc = einval(); // 127 is used by consts.sh to mean unsupported 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(); rc = efault();
} else if (IsXnu()) { } else if (IsXnu()) {
if (clockid == CLOCK_REALTIME) { if (clockid == CLOCK_REALTIME) {

View file

@ -27,7 +27,6 @@
#include "libc/cosmo.h" #include "libc/cosmo.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/sig.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) { if (!g_copy_file_range.ok) {
rc = enosys(); 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)) { } else if (__isfdkind(outfd, kFdZip)) {
rc = ebadf(); rc = ebadf();
} else if (__isfdkind(infd, kFdZip)) { } else if (__isfdkind(infd, kFdZip)) {

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -52,10 +51,8 @@
int faccessat(int dirfd, const char *path, int amode, int flags) { int faccessat(int dirfd, const char *path, int amode, int flags) {
int e, rc; int e, rc;
struct ZiposUri zipname; struct ZiposUri zipname;
if (IsAsan() && !__asan_is_valid_str(path)) { if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) ||
rc = efault(); !(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) {
} else if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) ||
!(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) {
rc = einval(); rc = einval();
} else if (__isfdkind(dirfd, kFdZip)) { } else if (__isfdkind(dirfd, kFdZip)) {
rc = enotsup(); rc = enotsup();

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.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 fchmodat(int dirfd, const char *path, uint32_t mode, int flags) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
rc = erofs(); rc = erofs();
} else if (!IsWindows()) { } else if (!IsWindows()) {
if (IsLinux() && flags) { if (IsLinux() && flags) {

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -43,10 +42,7 @@
int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid, int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid,
int flags) { int flags) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
rc = erofs(); rc = erofs();
} else { } else {
rc = sys_fchownat(dirfd, path, uid, gid, flags); rc = sys_fchownat(dirfd, path, uid, gid, flags);

View file

@ -21,7 +21,6 @@
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/f.h" #include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.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 || // if ((islock = cmd == F_GETLK || //
cmd == F_SETLK || // cmd == F_SETLK || //
cmd == F_SETLKW)) { cmd == F_SETLKW)) {
if ((!IsAsan() && !arg) || if (!arg) {
(IsAsan() &&
!__asan_is_valid((struct flock *)arg, sizeof(struct flock)))) {
return efault(); return efault();
} }
cosmo2flock(arg); cosmo2flock(arg);

View file

@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
@ -51,11 +50,8 @@ bool32 fileexists(const char *path) {
struct ZiposUri zipname; struct ZiposUri zipname;
uint16_t path16[PATH_MAX]; uint16_t path16[PATH_MAX];
e = errno; e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_open) &&
efault(); _weaken(__zipos_parseuri)(path, &zipname) != -1) {
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) {
res = true; res = true;
} else { } else {

View file

@ -20,7 +20,6 @@
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/struct/stat.internal.h" #include "libc/calls/struct/stat.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -42,9 +41,7 @@
*/ */
int fstat(int fd, struct stat *st) { int fstat(int fd, struct stat *st) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid(st, sizeof(*st))) { if (__isfdkind(fd, kFdZip)) {
rc = efault();
} else if (__isfdkind(fd, kFdZip)) {
rc = _weaken(__zipos_fstat)( rc = _weaken(__zipos_fstat)(
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st); (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
} else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) { } else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) {

View file

@ -23,7 +23,6 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.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 // execve() depends on this
int rc; int rc;
struct ZiposUri zipname; struct ZiposUri zipname;
if (IsAsan() && (!__asan_is_valid_str(path) || // if (flags & ~AT_SYMLINK_NOFOLLOW) {
!__asan_is_valid(st, sizeof(*st)))) {
rc = efault();
} else if (flags & ~AT_SYMLINK_NOFOLLOW) {
return einval(); return einval();
} else if (__isfdkind(dirfd, kFdZip)) { } else if (__isfdkind(dirfd, kFdZip)) {
STRACE("zipos dirfd not supported yet"); STRACE("zipos dirfd not supported yet");

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/groups.internal.h" #include "libc/calls/groups.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/stdckdint.h" #include "libc/stdckdint.h"
@ -34,11 +33,7 @@
*/ */
int getgroups(int size, uint32_t list[]) { int getgroups(int size, uint32_t list[]) {
int rc; int rc;
size_t n; if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
if (IsAsan() &&
(ckd_mul(&n, size, sizeof(list[0])) || !__asan_is_valid(list, n))) {
rc = efault();
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
rc = sys_getgroups(size, list); rc = sys_getgroups(size, list);
} else { } else {
rc = enosys(); rc = enosys();

View file

@ -29,7 +29,6 @@
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/asmflag.h" #include "libc/intrin/asmflag.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.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 getrandom(void *p, size_t n, unsigned f) {
ssize_t rc; ssize_t rc;
if ((!p && n) || (IsAsan() && !__asan_is_valid(p, n))) { if ((!p && n)) {
rc = efault(); rc = efault();
} else if (f & ~(GRND_RANDOM | GRND_NONBLOCK)) { } else if (f & ~(GRND_RANDOM | GRND_NONBLOCK)) {
rc = einval(); rc = einval();

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/rlimit.internal.h" #include "libc/calls/struct/rlimit.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
@ -41,7 +40,7 @@ int getrlimit(int resource, struct rlimit *rlim) {
int rc; int rc;
if (resource == 127) { if (resource == 127) {
rc = einval(); rc = einval();
} else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { } else if (!rlim) {
rc = efault(); rc = efault();
} else if (IsXnuSilicon()) { } else if (IsXnuSilicon()) {
rc = _sysret(__syslib->__getrlimit(resource, rlim)); rc = _sysret(__syslib->__getrlimit(resource, rlim));

View file

@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
@ -51,11 +50,8 @@ bool32 isdirectory(const char *path) {
union metastat st; union metastat st;
struct ZiposUri zipname; struct ZiposUri zipname;
e = errno; e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_open) &&
efault(); _weaken(__zipos_parseuri)(path, &zipname) != -1) {
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) {
res = S_ISDIR(st.cosmo.st_mode); res = S_ISDIR(st.cosmo.st_mode);
} else { } else {

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.h" #include "libc/runtime/zipos.internal.h"
@ -48,11 +47,8 @@ bool32 isregularfile(const char *path) {
union metastat st; union metastat st;
struct ZiposUri zipname; struct ZiposUri zipname;
e = errno; e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_open) &&
efault(); _weaken(__zipos_parseuri)(path, &zipname) != -1) {
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) { if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) {
res = !!S_ISREG(st.cosmo.st_mode); res = !!S_ISREG(st.cosmo.st_mode);
} else { } else {

View file

@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
@ -51,11 +50,8 @@ bool32 issymlink(const char *path) {
union metastat st; union metastat st;
struct ZiposUri zipname; struct ZiposUri zipname;
e = errno; e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_open) &&
efault(); _weaken(__zipos_parseuri)(path, &zipname) != -1) {
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
res = false; res = false;
} else if (IsMetal()) { } else if (IsMetal()) {
res = false; res = false;

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -40,12 +39,9 @@
int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
int flags) { int flags) {
int rc; int rc;
if (IsAsan() && if (_weaken(__zipos_notat) &&
(!__asan_is_valid_str(oldpath) || !__asan_is_valid_str(newpath))) { ((rc = __zipos_notat(olddirfd, oldpath)) == -1 ||
rc = efault(); (rc = __zipos_notat(newdirfd, newpath)) == -1)) {
} else if (_weaken(__zipos_notat) &&
((rc = __zipos_notat(olddirfd, oldpath)) == -1 ||
(rc = __zipos_notat(newdirfd, newpath)) == -1)) {
STRACE("zipos fchownat not supported yet"); STRACE("zipos fchownat not supported yet");
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_linkat(olddirfd, oldpath, newdirfd, newpath, flags); rc = sys_linkat(olddirfd, oldpath, newdirfd, newpath, flags);

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -38,9 +37,7 @@
*/ */
int madvise(void *addr, size_t length, int advice) { int madvise(void *addr, size_t length, int advice) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid(addr, length)) { if (!IsWindows()) {
rc = enomem();
} else if (!IsWindows()) {
rc = sys_madvise(addr, length, advice); rc = sys_madvise(addr, length, advice);
} else { } else {
rc = sys_madvise_nt(addr, length, advice); rc = sys_madvise_nt(addr, length, advice);

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -53,10 +52,7 @@
*/ */
int mkdirat(int dirfd, const char *path, unsigned mode) { int mkdirat(int dirfd, const char *path, unsigned mode) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
STRACE("zipos mkdirat not supported yet"); STRACE("zipos mkdirat not supported yet");
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_mkdirat(dirfd, path, mode); rc = sys_mkdirat(dirfd, path, mode);

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h" #include "libc/sysv/consts/s.h"
@ -42,8 +41,6 @@
*/ */
int mknod(const char *path, uint32_t mode, uint64_t dev) { int mknod(const char *path, uint32_t mode, uint64_t dev) {
int e, rc; int e, rc;
if (IsAsan() && !__asan_is_valid_str(path))
return efault();
if (mode & S_IFREG) if (mode & S_IFREG)
return creat(path, mode & ~S_IFREG); return creat(path, mode & ~S_IFREG);
if (mode & S_IFDIR) if (mode & S_IFDIR)

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.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" // 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 // which is an "8.3 filename" from the DOS days
if (!path || (IsAsan() && !__asan_is_valid_str(path))) { if (!path) {
return efault(); return efault();
} }

View file

@ -26,7 +26,6 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -180,7 +179,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
va_end(va); va_end(va);
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (!path || (IsAsan() && !__asan_is_valid_str(path))) { if (!path) {
rc = efault(); rc = efault();
} else if ((flags & O_UNLINK) && } else if ((flags & O_UNLINK) &&
(flags & (O_CREAT | O_EXCL)) != (O_CREAT | O_EXCL)) { (flags & (O_CREAT | O_EXCL)) != (O_CREAT | O_EXCL)) {

View file

@ -27,7 +27,6 @@
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/calls/termios.internal.h" #include "libc/calls/termios.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/log/rop.internal.h" #include "libc/log/rop.internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
@ -94,13 +93,6 @@ int openpty(int *mfd, int *sfd, char *name, //
if (IsWindows() || IsMetal()) { if (IsWindows() || IsMetal()) {
return enosys(); 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; BLOCK_CANCELATION;
rc = openpty_impl(mfd, sfd, name, tio, wsz); rc = openpty_impl(mfd, sfd, name, tio, wsz);
ALLOW_CANCELATION; ALLOW_CANCELATION;

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -36,7 +35,7 @@
*/ */
int pipe(int pipefd[hasatleast 2]) { int pipe(int pipefd[hasatleast 2]) {
int rc; int rc;
if (!pipefd || (IsAsan() && !__asan_is_valid(pipefd, sizeof(int) * 2))) { if (!pipefd) {
// needed for windows which is polyfilled // needed for windows which is polyfilled
// needed for xnu and netbsd which don't take an argument // needed for xnu and netbsd which don't take an argument
rc = efault(); rc = efault();

View file

@ -19,7 +19,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -44,8 +43,7 @@ int pipe2(int pipefd[hasatleast 2], int flags) {
int rc; int rc;
if (flags & ~(O_CLOEXEC | O_NONBLOCK | (O_DIRECT != -1u ? O_DIRECT : 0))) { if (flags & ~(O_CLOEXEC | O_NONBLOCK | (O_DIRECT != -1u ? O_DIRECT : 0))) {
return einval(); return einval();
} else if (!pipefd || } else if (!pipefd) {
(IsAsan() && !__asan_is_valid(pipefd, sizeof(int) * 2))) {
rc = efault(); rc = efault();
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_pipe2(pipefd, flags); rc = sys_pipe2(pipefd, flags);

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/cp.internal.h" #include "libc/calls/cp.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sock/struct/pollfd.h" #include "libc/sock/struct/pollfd.h"
#include "libc/sock/struct/pollfd.internal.h" #include "libc/sock/struct/pollfd.internal.h"
@ -65,13 +64,9 @@
*/ */
int poll(struct pollfd *fds, size_t nfds, int timeout_ms) { int poll(struct pollfd *fds, size_t nfds, int timeout_ms) {
int rc; int rc;
size_t n;
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (IsAsan() && if (!IsWindows()) {
(ckd_mul(&n, nfds, sizeof(struct pollfd)) || !__asan_is_valid(fds, n))) {
rc = efault();
} else if (!IsWindows()) {
if (!IsMetal()) { if (!IsMetal()) {
rc = sys_poll(fds, nfds, timeout_ms); rc = sys_poll(fds, nfds, timeout_ms);
} else { } else {

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sock/struct/pollfd.h" #include "libc/sock/struct/pollfd.h"
#include "libc/sock/struct/pollfd.internal.h" #include "libc/sock/struct/pollfd.internal.h"
@ -60,18 +59,12 @@
*/ */
int ppoll(struct pollfd *fds, size_t nfds, const struct timespec *timeout, int ppoll(struct pollfd *fds, size_t nfds, const struct timespec *timeout,
const sigset_t *sigmask) { const sigset_t *sigmask) {
size_t n;
int e, rc; int e, rc;
sigset_t oldmask; sigset_t oldmask;
struct timespec ts, *tsp; struct timespec ts, *tsp;
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (IsAsan() && if (!IsWindows()) {
(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()) {
e = errno; e = errno;
if (timeout) { if (timeout) {
ts = *timeout; ts = *timeout;

View file

@ -24,7 +24,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/macros.internal.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(); rc = einval();
} else if (fd < 0) { } else if (fd < 0) {
rc = ebadf(); rc = ebadf();
} else if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (__isfdkind(fd, kFdZip)) { } else if (__isfdkind(fd, kFdZip)) {
rc = _weaken(__zipos_read)( rc = _weaken(__zipos_read)(
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, (struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle,

View file

@ -24,7 +24,6 @@
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/likely.h" #include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.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(); return ebadf();
if (iovlen < 0) if (iovlen < 0)
return einval(); return einval();
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen))
return efault();
// XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX // XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX
// this is inconsistent with Linux which ignores huge requests // this is inconsistent with Linux which ignores huge requests

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sock/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; BEGIN_CANCELATION_POINT;
if (nfds < 0) { if (nfds < 0) {
rc = einval(); 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 { } else {
if (readfds) { if (readfds) {
old_readfds = *readfds; old_readfds = *readfds;

View file

@ -25,7 +25,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/stdio/sysparam.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(); rc = einval();
} else if (fd == -1) { } else if (fd == -1) {
rc = ebadf(); rc = ebadf();
} else if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (__isfdkind(fd, kFdZip)) { } else if (__isfdkind(fd, kFdZip)) {
rc = ebadf(); rc = ebadf();
} else if (!IsWindows()) { } else if (!IsWindows()) {

View file

@ -24,7 +24,6 @@
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/likely.h" #include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -52,8 +51,6 @@ static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen,
return ebadf(); return ebadf();
if (iovlen < 0) if (iovlen < 0)
return einval(); return einval();
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen))
return efault();
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip)
return ebadf(); return ebadf();

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.h" #include "libc/runtime/zipos.internal.h"
@ -74,7 +73,7 @@ ssize_t read(int fd, void *buf, size_t size) {
if (fd < 0) { if (fd < 0) {
rc = ebadf(); rc = ebadf();
} else if ((!buf && size) || (IsAsan() && !__asan_is_valid(buf, size))) { } else if ((!buf && size)) {
rc = efault(); rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = _weaken(__zipos_read)( rc = _weaken(__zipos_read)(

View file

@ -19,12 +19,12 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h" #include "libc/runtime/zipos.internal.h"
#include "libc/stdio/sysparam.h"
#include "libc/sysv/errfuns.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 readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) {
ssize_t bytes; ssize_t bytes;
if ((bufsiz && !buf) || (IsAsan() && (!__asan_is_valid_str(path) || if ((bufsiz && !buf)) {
!__asan_is_valid(buf, bufsiz)))) {
bytes = efault(); bytes = efault();
} else if (_weaken(__zipos_notat) && } else if (_weaken(__zipos_notat) &&
(bytes = __zipos_notat(dirfd, path)) == -1) { (bytes = __zipos_notat(dirfd, path)) == -1) {

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/likely.h" #include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.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(); return ebadf();
if (iovlen < 0) if (iovlen < 0)
return einval(); return einval();
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen))
return efault();
// XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX // XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX
// this is inconsistent with Linux which ignores huge requests // this is inconsistent with Linux which ignores huge requests

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -46,12 +45,9 @@
int renameat(int olddirfd, const char *oldpath, int newdirfd, int renameat(int olddirfd, const char *oldpath, int newdirfd,
const char *newpath) { const char *newpath) {
int rc; int rc;
if (IsAsan() && if (_weaken(__zipos_notat) &&
(!__asan_is_valid_str(oldpath) || !__asan_is_valid_str(newpath))) { ((rc = __zipos_notat(olddirfd, oldpath)) == -1 ||
rc = efault(); (rc = __zipos_notat(newdirfd, newpath)) == -1)) {
} else if (_weaken(__zipos_notat) &&
((rc = __zipos_notat(olddirfd, oldpath)) == -1 ||
(rc = __zipos_notat(newdirfd, newpath)) == -1)) {
STRACE("zipos renameat not supported yet"); STRACE("zipos renameat not supported yet");
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_renameat(olddirfd, oldpath, newdirfd, newpath); rc = sys_renameat(olddirfd, oldpath, newdirfd, newpath);

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sched_param.internal.h" #include "libc/calls/struct/sched_param.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -33,7 +32,7 @@
int sched_getparam(int pid, struct sched_param *param) { int sched_getparam(int pid, struct sched_param *param) {
int rc; int rc;
struct sched_param p; struct sched_param p;
if (!param || (IsAsan() && !__asan_is_valid(param, sizeof(*param)))) { if (!param) {
rc = efault(); rc = efault();
} else if (IsNetbsd()) { } else if (IsNetbsd()) {
if (!(rc = sys_sched_getscheduler_netbsd(pid, &p))) { if (!(rc = sys_sched_getscheduler_netbsd(pid, &p))) {

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sched_param.internal.h" #include "libc/calls/struct/sched_param.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -34,7 +33,7 @@
int sched_setparam(int pid, const struct sched_param *param) { int sched_setparam(int pid, const struct sched_param *param) {
int rc, policy; int rc, policy;
struct sched_param p; struct sched_param p;
if (!param || (IsAsan() && !__asan_is_valid(param, sizeof(*param)))) { if (!param) {
rc = efault(); rc = efault();
} else if (IsNetbsd()) { } else if (IsNetbsd()) {
if ((rc = policy = sys_sched_getscheduler_netbsd(pid, &p)) != -1) { if ((rc = policy = sys_sched_getscheduler_netbsd(pid, &p)) != -1) {

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/timeval.internal.h" #include "libc/calls/struct/timeval.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sock/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; BEGIN_CANCELATION_POINT;
if (nfds < 0) { if (nfds < 0) {
rc = einval(); 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 { } else {
if (readfds) { if (readfds) {
old_readfds = *readfds; old_readfds = *readfds;

View file

@ -19,7 +19,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/groups.internal.h" #include "libc/calls/groups.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/stdckdint.h" #include "libc/stdckdint.h"
@ -40,11 +39,7 @@
*/ */
int setgroups(size_t size, const uint32_t list[]) { int setgroups(size_t size, const uint32_t list[]) {
int rc; int rc;
size_t n; if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
if (IsAsan() &&
(ckd_mul(&n, size, sizeof(list[0])) || !__asan_is_valid(list, n))) {
rc = efault();
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
rc = sys_setgroups(size, list); rc = sys_setgroups(size, list);
} else { } else {
rc = enosys(); rc = enosys();

View file

@ -21,7 +21,6 @@
#include "libc/calls/struct/rlimit.internal.h" #include "libc/calls/struct/rlimit.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
@ -80,7 +79,7 @@ int setrlimit(int resource, const struct rlimit *rlim) {
int rc; int rc;
if (resource == 127) { if (resource == 127) {
rc = einval(); rc = einval();
} else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { } else if (!rlim) {
rc = efault(); rc = efault();
} else if (IsXnuSilicon()) { } else if (IsXnuSilicon()) {
rc = _sysret(__syslib->__setrlimit(resource, rlim)); rc = _sysret(__syslib->__setrlimit(resource, rlim));

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/timeval.internal.h" #include "libc/calls/struct/timeval.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
@ -29,7 +28,7 @@
*/ */
int settimeofday(const struct timeval *tv, const struct timezone *tz) { int settimeofday(const struct timeval *tv, const struct timezone *tz) {
int rc; int rc;
if (!tv || (IsAsan() && !__asan_is_valid_timeval(tv))) { if (!tv) {
rc = efault(); rc = efault();
} else { } else {
rc = sys_settimeofday(tv, 0); rc = sys_settimeofday(tv, 0);

View file

@ -30,7 +30,6 @@
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/calls/ucontext.h" #include "libc/calls/ucontext.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/dll.h" #include "libc/intrin/dll.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
@ -167,10 +166,6 @@ static int __sigaction(int sig, const struct sigaction *act,
return einval(); return einval();
if (sig == SIGKILL || sig == SIGSTOP) if (sig == SIGKILL || sig == SIGSTOP)
return einval(); return einval();
if (IsAsan() && ((act && !__asan_is_valid(act, sizeof(*act))) ||
(oldact && !__asan_is_valid(oldact, sizeof(*oldact))))) {
return efault();
}
if (!act) { if (!act) {
rva = (int32_t)(intptr_t)SIG_DFL; rva = (int32_t)(intptr_t)SIG_DFL;
} else if ((intptr_t)act->sa_handler < kSigactionMinRva) { } else if ((intptr_t)act->sa_handler < kSigactionMinRva) {

View file

@ -21,9 +21,9 @@
#include "libc/calls/struct/sigaltstack.internal.h" #include "libc/calls/struct/sigaltstack.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/runtime/syslib.internal.h" #include "libc/runtime/syslib.internal.h"
#include "libc/sysv/consts/ss.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 sigaltstack(const struct sigaltstack *neu, struct sigaltstack *old) {
int rc; int rc;
if (IsAsan() && ((old && !__asan_is_valid(old, sizeof(*old))) || if (neu && ((neu->ss_size >> 32) || //
(neu && !__asan_is_valid(neu, sizeof(*neu))))) { (neu->ss_flags & ~(SS_ONSTACK | SS_DISABLE)))) {
rc = efault();
} else if (neu && ((neu->ss_size >> 32) || //
(neu->ss_flags & ~(SS_ONSTACK | SS_DISABLE)))) {
rc = einval(); rc = einval();
} else if (neu && neu->ss_size < __get_minsigstksz()) { } else if (neu && neu->ss_size < __get_minsigstksz()) {
rc = enomem(); rc = enomem();

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/sigset.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/atomic.h" #include "libc/intrin/atomic.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
@ -38,7 +37,7 @@
*/ */
int sigpending(sigset_t *pending) { int sigpending(sigset_t *pending) {
int rc; int rc;
if (!pending || (IsAsan() && !__asan_is_valid(pending, sizeof(*pending)))) { if (!pending) {
rc = efault(); rc = efault();
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) { } else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
// 128 signals on NetBSD and FreeBSD, 64 on Linux, 32 on OpenBSD and XNU // 128 signals on NetBSD and FreeBSD, 64 on Linux, 32 on OpenBSD and XNU

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/sigset.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/atomic.h" #include "libc/intrin/atomic.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/nt/synchronization.h" #include "libc/nt/synchronization.h"
@ -48,9 +47,7 @@ int sigsuspend(const sigset_t *ignore) {
int rc; int rc;
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (IsAsan() && ignore && !__asan_is_valid(ignore, sizeof(*ignore))) { if (IsXnu() || IsOpenbsd()) {
rc = efault();
} else if (IsXnu() || IsOpenbsd()) {
// openbsd and xnu use a 32 signal register convention // openbsd and xnu use a 32 signal register convention
rc = sys_sigsuspend(ignore ? (void *)(intptr_t)(uint32_t)*ignore : 0, 8); rc = sys_sigsuspend(ignore ? (void *)(intptr_t)(uint32_t)*ignore : 0, 8);
} else { } else {

View file

@ -17,14 +17,12 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigtimedwait.h" #include "libc/calls/sigtimedwait.h"
#include "libc/calls/asan.internal.h"
#include "libc/calls/cp.internal.h" #include "libc/calls/cp.internal.h"
#include "libc/calls/sigtimedwait.internal.h" #include "libc/calls/sigtimedwait.internal.h"
#include "libc/calls/struct/siginfo.internal.h" #include "libc/calls/struct/siginfo.internal.h"
#include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/sigset.internal.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -52,11 +50,7 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info,
union siginfo_meta si = {0}; union siginfo_meta si = {0};
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) || if (IsLinux() || IsFreebsd() || IsNetbsd()) {
(info && !__asan_is_valid(info, sizeof(*info))) ||
(timeout && !__asan_is_valid_timespec(timeout)))) {
rc = efault();
} else if (IsLinux() || IsFreebsd() || IsNetbsd()) {
if (timeout) { if (timeout) {
// 1. Linux needs its size parameter // 1. Linux needs its size parameter
// 2. NetBSD modifies timeout argument // 2. NetBSD modifies timeout argument

View file

@ -23,7 +23,6 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/mem/alloca.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); cosmo_once(&g_splice.once, splice_init);
if (!g_splice.ok) { if (!g_splice.ok) {
rc = enosys(); 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)) { } else if (__isfdkind(infd, kFdZip) || __isfdkind(outfd, kFdZip)) {
rc = enotsup(); rc = enotsup();
} else { } else {

View file

@ -20,7 +20,6 @@
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
@ -41,10 +40,6 @@
*/ */
int symlinkat(const char *target, int newdirfd, const char *linkpath) { int symlinkat(const char *target, int newdirfd, const char *linkpath) {
int rc; int rc;
if (IsAsan() &&
(!__asan_is_valid_str(target) || !__asan_is_valid_str(linkpath))) {
rc = efault();
}
if (!IsWindows()) { if (!IsWindows()) {
rc = sys_symlinkat(target, newdirfd, linkpath); rc = sys_symlinkat(target, newdirfd, linkpath);
} else { } else {

View file

@ -22,7 +22,6 @@
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
@ -94,9 +93,7 @@ static int sys_sysinfo_bsd(struct sysinfo *info) {
int sysinfo(struct sysinfo *info) { int sysinfo(struct sysinfo *info) {
int rc; int rc;
struct sysinfo x = {0}; struct sysinfo x = {0};
if (IsAsan() && info && !__asan_is_valid(info, sizeof(*info))) { if (!IsWindows()) {
rc = efault();
} else if (!IsWindows()) {
if (IsLinux()) { if (IsLinux()) {
rc = sys_sysinfo(&x); rc = sys_sysinfo(&x);
} else { } else {

View file

@ -24,7 +24,6 @@
#include "libc/calls/termios.internal.h" #include "libc/calls/termios.internal.h"
#include "libc/calls/ttydefaults.h" #include "libc/calls/ttydefaults.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -91,7 +90,7 @@ int tcgetattr(int fd, struct termios *tio) {
int rc; int rc;
if (fd < 0) { if (fd < 0) {
rc = einval(); rc = einval();
} else if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { } else if (!tio) {
rc = efault(); rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotty(); rc = enotty();

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/termios.h" #include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -32,9 +31,7 @@
*/ */
int tcgetwinsize(int fd, struct winsize *ws) { int tcgetwinsize(int fd, struct winsize *ws) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { if (fd >= 0) {
rc = efault();
} else if (fd >= 0) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotty(); rc = enotty();
} else if (IsWindows()) { } else if (IsWindows()) {

View file

@ -24,7 +24,6 @@
#include "libc/calls/termios.internal.h" #include "libc/calls/termios.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/mem/alloca.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()) { if (IsMetal()) {
return 0; return 0;
} }

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/termios.h" #include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.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 tcsetwinsize(int fd, const struct winsize *ws) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid(ws, sizeof(*ws))) { if (fd >= 0) {
rc = efault();
} else if (fd >= 0) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotty(); rc = enotty();
} else if (!IsWindows()) { } else if (!IsWindows()) {

View file

@ -19,7 +19,6 @@
#include "libc/time.h" #include "libc/time.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**
@ -32,10 +31,7 @@
int64_t time(int64_t *opt_out_ret) { int64_t time(int64_t *opt_out_ret) {
int64_t secs; int64_t secs;
struct timeval tv; struct timeval tv;
if (IsAsan() && opt_out_ret && if (gettimeofday(&tv, 0) != -1) {
!__asan_is_valid(opt_out_ret, sizeof(*opt_out_ret))) {
secs = efault();
} else if (gettimeofday(&tv, 0) != -1) {
secs = tv.tv_sec; secs = tv.tv_sec;
if (opt_out_ret) { if (opt_out_ret) {
*opt_out_ret = secs; *opt_out_ret = secs;

View file

@ -19,7 +19,6 @@
#include "libc/calls/blockcancel.internal.h" #include "libc/calls/blockcancel.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#define ASAN_ERROR "error: tinyprint() passed invalid memory, or missing NULL\n" #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; BLOCK_CANCELATION;
va_start(va, s); va_start(va, s);
for (toto = n = 0; s; s = va_arg(va, const char *)) { 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++)) { while ((c = *s++)) {
buf[n++] = c; buf[n++] = c;
if (n == sizeof(buf)) { if (n == sizeof(buf)) {

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.h" #include "libc/runtime/zipos.internal.h"
@ -69,7 +68,7 @@ int truncate(const char *path, int64_t length) {
if (IsMetal()) { if (IsMetal()) {
rc = enosys(); rc = enosys();
} else if (!path || (IsAsan() && !__asan_is_valid_str(path))) { } else if (!path) {
rc = efault(); rc = efault();
} else if (_weaken(__zipos_parseuri) && } else if (_weaken(__zipos_parseuri) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) { _weaken(__zipos_parseuri)(path, &zipname) != -1) {

View file

@ -25,7 +25,6 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/macros.internal.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 uname(struct utsname *uts) {
int rc; int rc;
if (!uts || (IsAsan() && !__asan_is_valid(uts, sizeof(*uts)))) { if (!uts) {
rc = efault(); rc = efault();
} else if (IsLinux()) { } else if (IsLinux()) {
struct utsname_linux linux; struct utsname_linux linux;

View file

@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
@ -44,10 +43,7 @@
int unlinkat(int dirfd, const char *path, int flags) { int unlinkat(int dirfd, const char *path, int flags) {
int rc; int rc;
if (IsAsan() && !__asan_is_valid_str(path)) { if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
STRACE("zipos unlinkat not supported yet"); STRACE("zipos unlinkat not supported yet");
} else if (!IsWindows()) { } else if (!IsWindows()) {
rc = sys_unlinkat(dirfd, path, flags); rc = sys_unlinkat(dirfd, path, flags);

View file

@ -17,14 +17,12 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/asan.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.internal.h" #include "libc/calls/struct/timeval.internal.h"
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.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; struct ZiposUri zipname;
if (IsMetal()) { if (IsMetal()) {
rc = enosys(); 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)) { } else if ((flags & ~AT_SYMLINK_NOFOLLOW)) {
rc = einval(); // unsupported flag rc = einval(); // unsupported flag
} else if (__isfdkind(fd, kFdZip) || } else if (__isfdkind(fd, kFdZip) ||

View file

@ -22,7 +22,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.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) { if (fd < 0) {
rc = ebadf(); rc = ebadf();
} else if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) { } else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = ebadf(); // posix specifies this when not open()'d for writing rc = ebadf(); // posix specifies this when not open()'d for writing
} else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) { } else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) {

View file

@ -22,7 +22,6 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/likely.h" #include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.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(); return ebadf();
if (iovlen < 0) if (iovlen < 0)
return einval(); return einval();
if (IsAsan() && !__asan_is_valid_iov(iov, iovlen))
return efault();
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip)
return ebadf(); // posix specifies this when not open()'d for writing return ebadf(); // posix specifies this when not open()'d for writing

View file

@ -55,12 +55,6 @@
#define IsOptimized() 0 #define IsOptimized() 0
#endif #endif
#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif
#ifdef __aarch64__ #ifdef __aarch64__
#define IsAarch64() 1 #define IsAarch64() 1
#define IsXnuSilicon() IsXnu() #define IsXnuSilicon() IsXnu()

View file

@ -54,8 +54,6 @@ $(LIBC_DLOPEN_A_OBJS): private \
o/$(MODE)/libc/dlopen/foreign_tramp.o: libc/dlopen/foreign_tramp.S o/$(MODE)/libc/dlopen/foreign_tramp.o: libc/dlopen/foreign_tramp.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< @$(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_LIBS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)))
LIBC_DLOPEN_SRCS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_SRCS)) LIBC_DLOPEN_SRCS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_SRCS))
LIBC_DLOPEN_HDRS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_HDRS)) LIBC_DLOPEN_HDRS = $(foreach x,$(LIBC_DLOPEN_ARTIFACTS),$($(x)_HDRS))

View file

@ -55,8 +55,7 @@ $(LIBC_FMT_A).pkg: \
$(LIBC_FMT_A_OBJS): private \ $(LIBC_FMT_A_OBJS): private \
CFLAGS += \ CFLAGS += \
-fno-jump-tables \ -fno-jump-tables
-fno-sanitize=address
o/$(MODE)/libc/fmt/formatint64.o \ o/$(MODE)/libc/fmt/formatint64.o \
o/$(MODE)/libc/fmt/formatint64thousands.o \ o/$(MODE)/libc/fmt/formatint64thousands.o \

View file

@ -176,8 +176,7 @@ typedef struct {
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0))) #define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))
#ifndef privileged #ifndef privileged
#define privileged \ #define privileged _Section(".privileged") dontinline dontinstrument dontubsan
_Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif #endif
#ifndef wontreturn #ifndef wontreturn
@ -522,13 +521,6 @@ typedef struct {
#define nocallersavedregisters #define nocallersavedregisters
#endif #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 || \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
__has_attribute(__no_sanitize_undefined__)) __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__)) #define dontubsan __attribute__((__no_sanitize_undefined__))

View file

@ -62,12 +62,6 @@ o/$(MODE)/libc/intrin/kprintf.o: private \
-Wframe-larger-than=128 \ -Wframe-larger-than=128 \
-Walloca-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 \ o//libc/intrin/memmove.o: private \
CFLAGS += \ CFLAGS += \
-fno-toplevel-reorder -fno-toplevel-reorder

File diff suppressed because it is too large Load diff

View file

@ -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_ */

View file

@ -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_ */

View file

@ -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

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/bsr.h" #include "libc/intrin/bsr.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/sock/select.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) if (!fds)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(fds)) || if (kisdangerous(fds)) {
(IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) {
ksnprintf(buf, N, "%p", fds); ksnprintf(buf, N, "%p", fds);
return buf; return buf;
} }

View file

@ -19,7 +19,6 @@
#include "libc/calls/struct/flock.h" #include "libc/calls/struct/flock.h"
#include "libc/calls/struct/flock.internal.h" #include "libc/calls/struct/flock.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/sysv/consts/f.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) if (!l)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(l)) || if (kisdangerous(l)) {
(IsAsan() && !__asan_is_valid(l, sizeof(*l)))) {
ksnprintf(buf, N, "%p", l); ksnprintf(buf, N, "%p", l);
return buf; return buf;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/groups.internal.h" #include "libc/calls/groups.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/popcnt.h" #include "libc/intrin/popcnt.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
@ -34,8 +33,7 @@ const char *(DescribeGidList)(char buf[N], int rc, int size,
return "{}"; return "{}";
if (!list) if (!list)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(list)) || if (kisdangerous(list)) {
(IsAsan() && !__asan_is_valid(list, size * sizeof(list[0])))) {
ksnprintf(buf, N, "%p", list); ksnprintf(buf, N, "%p", list);
return buf; return buf;
} }

View file

@ -19,7 +19,6 @@
#include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/limits.h" #include "libc/limits.h"
#include "libc/macros.internal.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"; return "n/a";
if (rc == -2) if (rc == -2)
rc = SSIZE_MAX; rc = SSIZE_MAX;
if ((!IsAsan() && kisdangerous(iov)) || if (kisdangerous(iov)) {
(IsAsan() && !__asan_is_valid(iov, sizeof(*iov) * iovlen))) {
ksnprintf(buf, N, "%p", iov); ksnprintf(buf, N, "%p", iov);
return buf; return buf;
} }

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
@ -25,8 +24,7 @@
void DescribeIovNt(const struct NtIovec *iov, uint32_t iovlen, ssize_t rem) { void DescribeIovNt(const struct NtIovec *iov, uint32_t iovlen, ssize_t rem) {
int i; int i;
if ((!IsAsan() && kisdangerous(iov)) || if (kisdangerous(iov)) {
(IsAsan() && !__asan_is_valid(iov, iovlen * sizeof(struct NtIovec)))) {
kprintf("%p", iov); kprintf("%p", iov);
return; return;
} }

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/timeval.internal.h" #include "libc/calls/struct/timeval.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
@ -32,8 +31,7 @@ const char *(DescribeItimerval)(char buf[N], int rc,
return "NULL"; return "NULL";
if (rc == -1) if (rc == -1)
return "n/a"; return "n/a";
if ((!IsAsan() && kisdangerous(it)) || if (kisdangerous(it)) {
(IsAsan() && !__asan_is_valid(it, sizeof(*it)))) {
ksnprintf(buf, N, "%p", it); ksnprintf(buf, N, "%p", it);
} else { } else {
ksnprintf(buf, N, "{%s, %s}", DescribeTimeval(0, &it->it_interval), ksnprintf(buf, N, "{%s, %s}", DescribeTimeval(0, &it->it_interval),

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/limits.h" #include "libc/limits.h"
@ -36,8 +35,7 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds,
if (!fds) if (!fds)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(fds)) || if (kisdangerous(fds)) {
(IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) {
ksnprintf(buf, N, "%p", fds); ksnprintf(buf, N, "%p", fds);
return buf; return buf;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/rlimit.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.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"; return "n/a";
if (!rlim) if (!rlim)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(rlim)) || if (kisdangerous(rlim)) {
(IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
ksnprintf(buf, 64, "%p", rlim); ksnprintf(buf, 64, "%p", rlim);
} else { } else {
ksnprintf(buf, 64, "{%'ld, %'ld}", rlim->rlim_cur, rlim->rlim_max); ksnprintf(buf, 64, "{%'ld, %'ld}", rlim->rlim_cur, rlim->rlim_max);

View file

@ -21,9 +21,9 @@
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/sigset.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h"
#include "libc/mem/alloca.h" #include "libc/mem/alloca.h"
#include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sa.h"
@ -67,8 +67,7 @@ const char *(DescribeSigaction)(char buf[N], int rc,
return "n/a"; return "n/a";
if (!sa) if (!sa)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(sa)) || if (kisdangerous(sa)) {
(IsAsan() && !__asan_is_valid(sa, sizeof(*sa)))) {
ksnprintf(buf, N, "%p", sa); ksnprintf(buf, N, "%p", sa);
return buf; return buf;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/struct/sigaltstack.h" #include "libc/calls/struct/sigaltstack.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
@ -28,8 +27,7 @@ const char *(DescribeSigaltstk)(char buf[128], int rc,
return "n/a"; return "n/a";
if (!ss) if (!ss)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(ss)) || if (kisdangerous(ss)) {
(IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) {
ksnprintf(buf, 128, "%p", ss); ksnprintf(buf, 128, "%p", ss);
} else { } else {
ksnprintf(buf, 128, "{.ss_sp=%p, .ss_flags=%#lx, .ss_size=%'zu}", ss->ss_sp, ksnprintf(buf, 128, "{.ss_sp=%p, .ss_flags=%#lx, .ss_size=%'zu}", ss->ss_sp,

View file

@ -19,7 +19,6 @@
#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/siginfo.internal.h" #include "libc/calls/struct/siginfo.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/weaken.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"; return "n/a";
if (!si) if (!si)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(si)) || if (kisdangerous(si)) {
(IsAsan() && !__asan_is_valid(si, sizeof(*si)))) {
ksnprintf(buf, N, "%p", si); ksnprintf(buf, N, "%p", si);
return buf; return buf;
} }

View file

@ -21,7 +21,6 @@
#include "libc/calls/struct/sigset.internal.h" #include "libc/calls/struct/sigset.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/popcnt.h" #include "libc/intrin/popcnt.h"
#include "libc/str/str.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"; return "n/a";
if (!ss) if (!ss)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(ss)) || if (kisdangerous(ss)) {
(IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) {
ksnprintf(buf, N, "%p", ss); ksnprintf(buf, N, "%p", ss);
return buf; return buf;
} }

View file

@ -19,7 +19,6 @@
#include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.h"
#include "libc/calls/struct/stat.internal.h" #include "libc/calls/struct/stat.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#define N 300 #define N 300
@ -33,8 +32,7 @@ const char *(DescribeStat)(char buf[N], int rc, const struct stat *st) {
return "n/a"; return "n/a";
if (!st) if (!st)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(st)) || if (kisdangerous(st)) {
(IsAsan() && !__asan_is_valid(st, sizeof(*st)))) {
ksnprintf(buf, N, "%p", st); ksnprintf(buf, N, "%p", st);
return buf; return buf;
} }

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/statfs.internal.h" #include "libc/calls/struct/statfs.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/sysv/consts/st.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"; return "n/a";
if (!f) if (!f)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(f)) || if (kisdangerous(f)) {
(IsAsan() && !__asan_is_valid(f, sizeof(*f)))) {
ksnprintf(buf, N, "%p", f); ksnprintf(buf, N, "%p", f);
return buf; return buf;
} }

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
@ -30,10 +29,6 @@ const char *(DescribeStringList)(char buf[N], char *const list[]) {
if (!list) if (!list)
return "NULL"; return "NULL";
if (IsAsan() && !__asan_is_valid_strlist(list)) {
ksnprintf(buf, N, "%p", list);
return buf;
}
append("{"); append("{");
i = 0; i = 0;

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/termios.internal.h" #include "libc/calls/struct/termios.internal.h"
#include "libc/calls/ttydefaults.h" #include "libc/calls/ttydefaults.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
@ -37,8 +36,7 @@ const char *(DescribeTermios)(char buf[N], ssize_t rc,
if (!tio) if (!tio)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(tio)) || if (kisdangerous(tio)) {
(IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) {
ksnprintf(buf, N, "%p", tio); ksnprintf(buf, N, "%p", tio);
return buf; return buf;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/str/str.h" #include "libc/str/str.h"
@ -29,8 +28,7 @@ const char *(DescribeTimespec)(char buf[45], int rc,
return "n/a"; return "n/a";
if (!ts) if (!ts)
return "NULL"; return "NULL";
if ((!IsAsan() && kisdangerous(ts)) || if (kisdangerous(ts)) {
(IsAsan() && !__asan_is_valid(ts, sizeof(*ts)))) {
ksnprintf(buf, 45, "%p", ts); ksnprintf(buf, 45, "%p", ts);
} else { } else {
if (!memcmp(ts, &timespec_max, sizeof(*ts))) { if (!memcmp(ts, &timespec_max, sizeof(*ts))) {

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
@ -27,8 +26,7 @@ const char *(DescribeTimeval)(char buf[45], int rc, const struct timeval *tv) {
return "NULL"; return "NULL";
if (rc == -1) if (rc == -1)
return "n/a"; return "n/a";
if ((!IsAsan() && kisdangerous(tv)) || if (kisdangerous(tv)) {
(IsAsan() && !__asan_is_valid(tv, sizeof(*tv)))) {
ksnprintf(buf, 45, "%p", tv); ksnprintf(buf, 45, "%p", tv);
} else { } else {
ksnprintf(buf, 45, "{%ld, %ld}", tv->tv_sec, tv->tv_usec); ksnprintf(buf, 45, "{%ld, %ld}", tv->tv_sec, tv->tv_usec);

View file

@ -19,7 +19,6 @@
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"
#include "libc/calls/struct/winsize.internal.h" #include "libc/calls/struct/winsize.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/limits.h" #include "libc/limits.h"
@ -35,8 +34,7 @@ const char *(DescribeWinsize)(char buf[N], int rc, const struct winsize *ws) {
return "NULL"; return "NULL";
if (rc == -1) if (rc == -1)
return "n/a"; return "n/a";
if ((!IsAsan() && kisdangerous(ws)) || if (kisdangerous(ws)) {
(IsAsan() && !__asan_is_valid(ws, sizeof(*ws)))) {
ksnprintf(buf, N, "%p", ws); ksnprintf(buf, N, "%p", ws);
return buf; return buf;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.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) { void *_extend(void *p, size_t n, void *e, int f, intptr_t h) {
char *q; 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) { for (q = e; q < ((char *)p + n); q += 8) {
if (!((uintptr_t)q & (G - 1))) { if (!((uintptr_t)q & (G - 1))) {
if (q + G > (char *)h) 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 0;
} }
} }
return q; return q;
} }

View file

@ -3,14 +3,7 @@
#include "libc/dce.h" #include "libc/dce.h"
COSMOPOLITAN_C_START_ 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) #define IGNORE_LEAKS(FUNC)
#endif
extern intptr_t _leaky_end[] __attribute__((__weak__)); extern intptr_t _leaky_end[] __attribute__((__weak__));
extern intptr_t _leaky_start[] __attribute__((__weak__)); extern intptr_t _leaky_start[] __attribute__((__weak__));

Some files were not shown because too many files have changed in this diff Show more