cosmopolitan/libc/mem
Justine Tunney 98254a7c1f Make pledge() and unveil() work amazingly
This change reconciles our pledge() implementation with the OpenBSD
kernel source code. We now a polyfill that's much closer to OpenBSD's
behavior. For example, it was discovered that "stdio" permits threads.
There were a bunch of Linux system calls that needed to be added, like
sched_yield(). The exec / execnative category division is now dropped.
We're instead using OpenBSD's "prot_exec" promise for launching APE
binaries and dynamic shared objects. We also now filter clone() flags.

The pledge.com command has been greatly improved. It now does unveiling
by default when Landlock is available. It's now smart enough to unveil a
superset of paths that OpenBSD automatically unveils with pledge(), such
as /etc/localtime. pledge.com also now checks if the executable being
launched is a dynamic shared object, in which case it unveils libraries.

These changes now make it possible to pledge curl on ubuntu 20.04 glibc:

    pledge.com -p 'stdio rpath prot_exec inet dns tty sendfd recvfd' \
        curl -s https://justine.lol/hello.txt

Here's what pledging curl on Alpine 3.16 with Musl Libc looks like:

    pledge.com -p 'stdio rpath prot_exec dns inet' \
        curl -s https://justine.lol/hello.txt

Here's what pledging curl.com w/ ape loader looks like:

    pledge.com -p 'stdio rpath prot_exec dns inet' \
        o//examples/curl.com https://justine.lol/hello.txt

The most secure sandbox, is curl.com converted to static ELF:

    o//tool/build/assimilate.com o//examples/curl.com
    pledge.com -p 'stdio rpath dns inet' \
        o//examples/curl.com https://justine.lol/hello.txt

A weird corner case needed to be handled when resolving symbolic links
during the unveiling process, that's arguably a Landlock bug. It's not
surprising since Musl and Glibc are also inconsistent here too.
2022-07-19 21:33:49 -07:00
..
cxx Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
hook Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
aligned_alloc.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
alloca.h Initial import 2020-06-15 07:18:57 -07:00
arena.c Make dlmalloc a little faster 2022-06-09 21:25:21 -07:00
arena.h Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
asprintf.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
balloc.c Improve memory safety 2021-10-13 17:27:13 -07:00
bfree.c Change license 2020-12-27 17:18:44 -08:00
bulk_free.S Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
calloc.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
copyfd.c Improve system call support on NT 2022-04-07 20:30:04 -07:00
defer.greg.c Improve memory safety 2021-10-13 17:27:13 -07:00
fmt.h Make Cosmopolitan ANSI C89 compatible 2021-02-03 17:48:59 -08:00
free.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
gc.c Expose public garbage collector API for C language 2021-03-08 10:59:34 -08:00
get_current_dir_name.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
internal.h Improve memory safety 2021-10-13 17:27:13 -07:00
io.h Improve system call support on NT 2022-04-07 20:30:04 -07:00
mallinfo.c Improve synchronization 2022-04-15 15:31:55 -07:00
malloc.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
malloc_inspect_all.c Improve synchronization 2022-04-15 15:31:55 -07:00
malloc_trim.S Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
malloc_usable_size.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
mem.h Improve synchronization 2022-04-15 15:31:55 -07:00
mem.mk Make improvements 2022-04-28 09:57:07 -07:00
memalign.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
pledge.c Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
posix_memalign.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
putenv.c Make some systemic improvements 2022-05-18 16:52:36 -07:00
pvalloc.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
realloc.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
realloc_in_place.S Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
reallocarray.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
setenv.c Introduce --strace flag for system call tracing 2022-03-18 18:07:28 -07:00
strdup.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
strndup.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
unhexstr.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
unveil.c Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
valloc.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
vasprintf.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
wcsdup.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00