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

@ -19,7 +19,6 @@
#include "libc/calls/cp.internal.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"

View file

@ -1,38 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/sock/struct/msghdr.h"
#if IsAsan()
bool __asan_is_valid_msghdr(const struct msghdr *msg) {
if (!__asan_is_valid(msg, sizeof(struct msghdr)))
return false;
if (msg->msg_name) {
if (!__asan_is_valid(msg->msg_name, msg->msg_namelen))
return false;
}
if (msg->msg_control) {
if (!__asan_is_valid(msg->msg_control, msg->msg_controllen))
return false;
}
return __asan_is_valid_iov(msg->msg_iov, msg->msg_iovlen);
}
#endif

View file

@ -19,7 +19,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
@ -48,7 +47,7 @@
*/
int bind(int fd, const struct sockaddr *addr, uint32_t addrsize) {
int rc;
if (!addr || (IsAsan() && !__asan_is_valid(addr, addrsize))) {
if (!addr) {
rc = efault();
} else if (addrsize >= sizeof(struct sockaddr_in)) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {

View file

@ -20,7 +20,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
@ -45,7 +44,7 @@ int connect(int fd, const struct sockaddr *addr, uint32_t addrsize) {
int rc;
BEGIN_CANCELATION_POINT;
if (addr && !(IsAsan() && !__asan_is_valid(addr, addrsize))) {
if (addr) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {

View file

@ -19,7 +19,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/errors.h"
#include "libc/nt/thunk/msabi.h"

View file

@ -19,7 +19,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/internal.h"
@ -47,10 +46,6 @@ int getsockopt(int fd, int level, int optname, void *out_opt_optval,
if (level == -1 || !optname) {
rc = enoprotoopt(); // see libc/sysv/consts.sh
} else if (IsAsan() && (out_opt_optval && out_optlen &&
(!__asan_is_valid(out_optlen, sizeof(uint32_t)) ||
!__asan_is_valid(out_opt_optval, *out_optlen)))) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {

View file

@ -42,7 +42,7 @@ static textwindows void WinSockCleanup(void) {
NTTRACE("WSACleanup() → %d% lm", rc);
}
textwindows dontasan void WinSockInit(void) {
textwindows void WinSockInit(void) {
int rc;
atexit(WinSockCleanup);
NTTRACE("WSAStartup()");

View file

@ -20,7 +20,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
@ -45,9 +44,7 @@ ssize_t recv(int fd, void *buf, size_t size, int flags) {
ssize_t rc;
BEGIN_CANCELATION_POINT;
if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
rc = sys_recvfrom(fd, buf, size, flags, 0, 0);

View file

@ -21,7 +21,6 @@
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/winsock.h"
#include "libc/sock/internal.h"
@ -60,9 +59,7 @@ ssize_t recvfrom(int fd, void *buf, size_t size, int flags,
uint32_t addrsize = sizeof(addr);
BEGIN_CANCELATION_POINT;
if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
rc = sys_recvfrom(fd, buf, size, flags, &addr, &addrsize);

View file

@ -57,9 +57,7 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags) {
union sockaddr_storage_bsd bsd;
BEGIN_CANCELATION_POINT;
if (IsAsan() && !__asan_is_valid_msghdr(msg)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
if (IsBsd() && msg->msg_name) {

View file

@ -21,7 +21,6 @@
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
#include "libc/sock/internal.h"
@ -46,9 +45,7 @@ ssize_t send(int fd, const void *buf, size_t size, int flags) {
ssize_t rc;
BEGIN_CANCELATION_POINT;
if (IsAsan() && !__asan_is_valid(buf, size)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
rc = sys_sendto(fd, buf, size, flags, 0, 0);

View file

@ -25,7 +25,6 @@
#include "libc/cosmo.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/enum/wsaid.h"
@ -182,10 +181,7 @@ ssize_t sendfile(int outfd, int infd, int64_t *opt_in_out_inoffset,
// less error prone, since Linux may EINVAL if greater than INT64_MAX
uptobytes = MIN(uptobytes, 0x7ffff000);
if (IsAsan() && opt_in_out_inoffset &&
!__asan_is_valid(opt_in_out_inoffset, 8)) {
rc = efault();
} else if (IsLinux()) {
if (IsLinux()) {
rc = sys_sendfile(outfd, infd, opt_in_out_inoffset, uptobytes);
} else if (IsFreebsd() || IsXnu()) {
rc = sys_sendfile_bsd(outfd, infd, opt_in_out_inoffset, uptobytes);

View file

@ -23,7 +23,6 @@
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h"
@ -56,9 +55,7 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) {
union sockaddr_storage_bsd bsd;
BEGIN_CANCELATION_POINT;
if (IsAsan() && !__asan_is_valid_msghdr(msg)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
if (IsBsd() && msg->msg_name) {
@ -91,8 +88,7 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) {
// TODO(jart): Write a DescribeMsg() function.
if (strace_enabled(0) > 0) {
kprintf(STRACE_PROLOGUE "sendmsg(%d, ", fd);
if ((!IsAsan() && kisdangerous(msg)) ||
(IsAsan() && !__asan_is_valid(msg, sizeof(*msg)))) {
if (kisdangerous(msg)) {
kprintf("%p", msg);
} else {
kprintf("{");

View file

@ -22,7 +22,6 @@
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/iovec.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
#include "libc/sock/internal.h"
@ -61,10 +60,7 @@ ssize_t sendto(int fd, const void *buf, size_t size, int flags,
union sockaddr_storage_bsd bsd;
BEGIN_CANCELATION_POINT;
if (IsAsan() && (!__asan_is_valid(buf, size) ||
(opt_addr && !__asan_is_valid(opt_addr, addrsize)))) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();
} else if (!IsWindows()) {
if (!IsBsd() || !opt_addr) {

View file

@ -20,7 +20,6 @@
#include "libc/calls/struct/fd.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/winsock.h"
@ -63,8 +62,7 @@ int setsockopt(int fd, int level, int optname, const void *optval,
if (level == -1 || !optname) {
rc = enoprotoopt(); // see libc/sysv/consts.sh
} else if ((!optval && optlen) ||
(IsAsan() && !__asan_is_valid(optval, optlen))) {
} else if ((!optval && optlen)) {
rc = efault();
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
rc = enotsock();