Skip to content

Commit

Permalink
Delete ASAN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jart committed Jun 22, 2024
1 parent 6ffed14 commit d1d4388
Show file tree
Hide file tree
Showing 198 changed files with 130 additions and 2,954 deletions.
2 changes: 0 additions & 2 deletions ape/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ o/$(MODE)/ape/ape-no-modify-self.o: \
libc/dce.h \
libc/elf/def.h \
libc/thread/tls.h \
libc/intrin/asancodes.h \
libc/macho.internal.h \
libc/macros.internal.h \
libc/nexgen32e/uart.internal.h \
Expand All @@ -189,7 +188,6 @@ o/$(MODE)/ape/ape-copy-self.o: \
libc/dce.h \
libc/elf/def.h \
libc/thread/tls.h \
libc/intrin/asancodes.h \
libc/macho.internal.h \
libc/macros.internal.h \
libc/nexgen32e/uart.internal.h \
Expand Down
26 changes: 2 additions & 24 deletions build/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,10 @@ TARGET_ARCH ?= -msse3
PYFLAGS += -O1
endif

# Asan Mode
#
# Safer binaries good for backend production serving.
#
# - `make MODE=asan`
# - Memory safety
# - Production worthy
# - Backtraces
# - Debuggability
# - Larger binaries
#
ifeq ($(MODE), asan)
ENABLE_FTRACE = 1
CONFIG_OFLAGS ?= -g -ggdb
CONFIG_CPPFLAGS += -D__SANITIZE_ADDRESS__
CONFIG_CCFLAGS += $(BACKTRACES) -O2 -DSYSDEBUG
CONFIG_COPTS += -fsanitize=address
TARGET_ARCH ?= -msse3
QUOTA ?= -C64 -L300
endif

# Debug Mode
#
# - `make MODE=dbg`
# - Backtraces
# - Enables asan
# - Enables ubsan
# - Stack canaries
# - No optimization
Expand All @@ -161,9 +139,9 @@ endif
ifeq ($(MODE), dbg)
ENABLE_FTRACE = 1
CONFIG_OFLAGS ?= -g -ggdb
CONFIG_CPPFLAGS += -DMODE_DBG -D__SANITIZE_ADDRESS__ -D__SANITIZE_UNDEFINED__
CONFIG_CPPFLAGS += -DMODE_DBG -D__SANITIZE_UNDEFINED__
CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O0 -fno-inline
CONFIG_COPTS += -fsanitize=address -fsanitize=undefined
CONFIG_COPTS += -fsanitize=undefined
TARGET_ARCH ?= -msse3
OVERRIDE_CCFLAGS += -fno-pie
QUOTA ?= -C64 -L300
Expand Down
3 changes: 0 additions & 3 deletions build/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ BACKTRACES = \
-fno-optimize-sibling-calls \
-mno-omit-leaf-frame-pointer

SANITIZER = \
-fsanitize=address

NO_MAGIC = \
-ffreestanding \
-fno-stack-protector \
Expand Down
16 changes: 0 additions & 16 deletions examples/asantest.c

This file was deleted.

27 changes: 0 additions & 27 deletions libc/calls/asan.internal.h

This file was deleted.

3 changes: 1 addition & 2 deletions libc/calls/chdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/log/log.h"
Expand Down Expand Up @@ -59,7 +58,7 @@ int chdir(const char *path) {
if (_weaken(GetProgramExecutableName)) {
_weaken(GetProgramExecutableName)();
}
if (!path || (IsAsan() && !__asan_is_valid_str(path))) {
if (!path) {
rc = efault();
} else if (_weaken(__zipos_parseuri) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
Expand Down
3 changes: 1 addition & 2 deletions libc/calls/chroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/errfuns.h"

Expand Down Expand Up @@ -49,7 +48,7 @@
*/
int chroot(const char *path) {
int rc;
if (!path || (IsAsan() && !__asan_is_valid_str(path))) {
if (!path) {
rc = efault();
} else {
rc = sys_chroot(path);
Expand Down
3 changes: 1 addition & 2 deletions libc/calls/clock_getres.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/describeflags.internal.h"
Expand Down Expand Up @@ -63,7 +62,7 @@ static int sys_clock_getres_xnu(int clock, struct timespec *ts) {
*/
int clock_getres(int clock, struct timespec *ts) {
int rc;
if (!ts || (IsAsan() && !__asan_is_valid_timespec(ts))) {
if (!ts) {
rc = efault();
} else if (clock == 127) {
rc = einval(); // 127 is used by consts.sh to mean unsupported
Expand Down
3 changes: 1 addition & 2 deletions libc/calls/clock_settime.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h"
Expand All @@ -35,7 +34,7 @@ int clock_settime(int clockid, const struct timespec *ts) {
struct timeval tv;
if (clockid == 127) {
rc = einval(); // 127 is used by consts.sh to mean unsupported
} else if (!ts || (IsAsan() && !__asan_is_valid_timespec(ts))) {
} else if (!ts) {
rc = efault();
} else if (IsXnu()) {
if (clockid == CLOCK_REALTIME) {
Expand Down
6 changes: 0 additions & 6 deletions libc/calls/copy_file_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "libc/cosmo.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/sig.h"
Expand Down Expand Up @@ -109,11 +108,6 @@ ssize_t copy_file_range(int infd, int64_t *opt_in_out_inoffset, int outfd,

if (!g_copy_file_range.ok) {
rc = enosys();
} else if (IsAsan() && ((opt_in_out_inoffset &&
!__asan_is_valid(opt_in_out_inoffset, 8)) ||
(opt_in_out_outoffset &&
!__asan_is_valid(opt_in_out_outoffset, 8)))) {
rc = efault();
} else if (__isfdkind(outfd, kFdZip)) {
rc = ebadf();
} else if (__isfdkind(infd, kFdZip)) {
Expand Down
7 changes: 2 additions & 5 deletions libc/calls/faccessat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand Down Expand Up @@ -52,10 +51,8 @@
int faccessat(int dirfd, const char *path, int amode, int flags) {
int e, rc;
struct ZiposUri zipname;
if (IsAsan() && !__asan_is_valid_str(path)) {
rc = efault();
} else if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) ||
!(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) {
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS)) ||
!(amode == F_OK || !(amode & ~(R_OK | W_OK | X_OK)))) {
rc = einval();
} else if (__isfdkind(dirfd, kFdZip)) {
rc = enotsup();
Expand Down
6 changes: 1 addition & 5 deletions libc/calls/fchmodat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand Down Expand Up @@ -52,10 +51,7 @@ int sys_fchmodat2(int, const char *, unsigned, int);
*/
int fchmodat(int dirfd, const char *path, uint32_t mode, int flags) {
int rc;
if (IsAsan() && !__asan_is_valid_str(path)) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = erofs();
} else if (!IsWindows()) {
if (IsLinux() && flags) {
Expand Down
6 changes: 1 addition & 5 deletions libc/calls/fchownat.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand All @@ -43,10 +42,7 @@
int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid,
int flags) {
int rc;
if (IsAsan() && !__asan_is_valid_str(path)) {
rc = efault();
} else if (_weaken(__zipos_notat) &&
(rc = __zipos_notat(dirfd, path)) == -1) {
if (_weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
rc = erofs();
} else {
rc = sys_fchownat(dirfd, path, uid, gid, flags);
Expand Down
5 changes: 1 addition & 4 deletions libc/calls/fcntl-sysv.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
Expand All @@ -32,9 +31,7 @@ int sys_fcntl(int fd, int cmd, uintptr_t arg, int impl(int, int, ...)) {
if ((islock = cmd == F_GETLK || //
cmd == F_SETLK || //
cmd == F_SETLKW)) {
if ((!IsAsan() && !arg) ||
(IsAsan() &&
!__asan_is_valid((struct flock *)arg, sizeof(struct flock)))) {
if (!arg) {
return efault();
}
cosmo2flock(arg);
Expand Down
8 changes: 2 additions & 6 deletions libc/calls/fileexists.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nt/files.h"
Expand Down Expand Up @@ -51,11 +50,8 @@ bool32 fileexists(const char *path) {
struct ZiposUri zipname;
uint16_t path16[PATH_MAX];
e = errno;
if (IsAsan() && !__asan_is_valid_str(path)) {
efault();
res = false;
} else if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_open) &&
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
if (_weaken(__zipos_stat)(&zipname, &st.cosmo) != -1) {
res = true;
} else {
Expand Down
5 changes: 1 addition & 4 deletions libc/calls/fstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand All @@ -42,9 +41,7 @@
*/
int fstat(int fd, struct stat *st) {
int rc;
if (IsAsan() && !__asan_is_valid(st, sizeof(*st))) {
rc = efault();
} else if (__isfdkind(fd, kFdZip)) {
if (__isfdkind(fd, kFdZip)) {
rc = _weaken(__zipos_fstat)(
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
} else if (IsLinux() || IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd()) {
Expand Down
6 changes: 1 addition & 5 deletions libc/calls/fstatat.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand Down Expand Up @@ -76,10 +75,7 @@ int fstatat(int dirfd, const char *path, struct stat *st, int flags) {
// execve() depends on this
int rc;
struct ZiposUri zipname;
if (IsAsan() && (!__asan_is_valid_str(path) || //
!__asan_is_valid(st, sizeof(*st)))) {
rc = efault();
} else if (flags & ~AT_SYMLINK_NOFOLLOW) {
if (flags & ~AT_SYMLINK_NOFOLLOW) {
return einval();
} else if (__isfdkind(dirfd, kFdZip)) {
STRACE("zipos dirfd not supported yet");
Expand Down
1 change: 0 additions & 1 deletion libc/calls/futimes.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/asan.internal.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timespec.internal.h"
#include "libc/calls/struct/timeval.h"
Expand Down
7 changes: 1 addition & 6 deletions libc/calls/getgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "libc/calls/calls.h"
#include "libc/calls/groups.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/stdckdint.h"
Expand All @@ -34,11 +33,7 @@
*/
int getgroups(int size, uint32_t list[]) {
int rc;
size_t n;
if (IsAsan() &&
(ckd_mul(&n, size, sizeof(list[0])) || !__asan_is_valid(list, n))) {
rc = efault();
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
rc = sys_getgroups(size, list);
} else {
rc = enosys();
Expand Down
3 changes: 1 addition & 2 deletions libc/calls/getrandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/asmflag.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
Expand Down Expand Up @@ -182,7 +181,7 @@ ssize_t __getrandom(void *p, size_t n, unsigned f) {
*/
ssize_t getrandom(void *p, size_t n, unsigned f) {
ssize_t rc;
if ((!p && n) || (IsAsan() && !__asan_is_valid(p, n))) {
if ((!p && n)) {
rc = efault();
} else if (f & ~(GRND_RANDOM | GRND_NONBLOCK)) {
rc = einval();
Expand Down
Loading

0 comments on commit d1d4388

Please sign in to comment.