cosmopolitan/test/libc
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
..
alg Make build hermetic without shell scripts 2022-05-25 13:55:57 -07:00
bits Add fixups for previous change 2022-06-27 15:00:51 -07:00
calls Use futexes on OpenBSD and improve threading 2022-07-17 19:59:49 -07:00
dns Add fixups for previous change 2022-06-27 15:00:51 -07:00
fmt Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
intrin Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
log Make more fixes and improvements 2022-06-13 11:02:13 -07:00
mem Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
nexgen32e Fix MODE=tiny build 2022-07-14 05:42:24 -07:00
rand Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
release Fixup and polish chibicc some more 2022-06-20 04:32:25 -07:00
runtime Always initialize thread local storage 2022-07-19 00:21:46 -07:00
sock Improve system calls 2022-07-08 06:42:03 -07:00
stdio Always initialize thread local storage 2022-07-19 00:21:46 -07:00
str Make fixes and improvements 2022-06-25 21:09:09 -07:00
thread Always initialize thread local storage 2022-07-19 00:21:46 -07:00
time Make build hermetic without shell scripts 2022-05-25 13:55:57 -07:00
tinymath Import more Musl math 2022-07-12 15:55:12 -07:00
unicode Add Deflate() / Inflate() to redbean and fix bugs 2022-07-08 09:47:04 -07:00
x Make more fixes and improvements 2022-06-13 11:02:13 -07:00
xed Make build hermetic without shell scripts 2022-05-25 13:55:57 -07:00
test.mk Fix bugs and make improvements 2022-04-20 10:05:34 -07:00