cosmopolitan/libc/runtime
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
..
__utmpxname.S Add finger demo to redbean and fix regression 2022-06-23 03:42:05 -07:00
abort.greg.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
arch_prctl.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
brk.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
buffer.h Initial import 2020-06-15 07:18:57 -07:00
clearenv.c Introduce --strace flag for system call tracing 2022-03-18 18:07:28 -07:00
clktck.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
clktck.h Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
clone-linux.S Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
clone-openbsd.S Make fixes and improvements 2022-06-25 21:09:09 -07:00
clone.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
close_s.c Improve locks and signals 2022-04-12 05:20:17 -07:00
closesymboltable.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
construct.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
cosmo.S Always initialize thread local storage 2022-07-19 00:21:46 -07:00
directmap.internal.h Improve signals and memory protection 2022-04-12 22:11:00 -07:00
dlfcn.h Get Fabrice Bellard's JavaScript engine to build 2021-04-09 01:06:57 -07:00
dsohandle.S Introduce --strace flag for system call tracing 2022-03-18 18:07:28 -07:00
e820.internal.h Support malloc() on bare metal 2021-02-24 00:53:24 -08:00
efimain.greg.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
enable_threads.c Make some minor fixups to bug reporting, etc. 2022-07-11 05:58:24 -07:00
enable_tls.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
exit.c Get life.com in MODE=tiny back down to 12kb 2022-03-23 08:09:01 -07:00
exit2.c Support malloc() on bare metal 2021-02-24 00:53:24 -08:00
ezmap.c Make numerous improvements 2021-09-28 01:52:34 -07:00
ezmap.internal.h Improve documentation 2020-12-27 07:02:35 -08:00
fegetround.c Get Fabrice Bellard's JavaScript engine to build 2021-04-09 01:06:57 -07:00
fenv.c Get Fabrice Bellard's JavaScript engine to build 2021-04-09 01:06:57 -07:00
fenv.h Get Fabrice Bellard's JavaScript engine to build 2021-04-09 01:06:57 -07:00
fesetround.c Fix issues revealed by ECMAScript test262 2021-04-10 17:15:35 -07:00
findcombinary.c Make improvements 2022-04-28 09:57:07 -07:00
finddebugbinary.c Make build hermetic without shell scripts 2022-05-25 13:55:57 -07:00
fltrounds.c Fix issues revealed by ECMAScript test262 2021-04-10 17:15:35 -07:00
fork-nt.c Make fixes and improvements 2022-06-25 21:09:09 -07:00
fork.c Reduce Makefile dependencies by 4% 2022-05-23 15:07:01 -07:00
fpreset.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
free_s.c Improve locks and signals 2022-04-12 05:20:17 -07:00
ftrace-hook.S Make some systemic improvements 2022-05-18 16:52:36 -07:00
ftraceinit.greg.c Make some systemic improvements 2022-05-18 16:52:36 -07:00
ftracer.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
gc.h Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
gc.internal.h Fix regression in _gclongjmp() 2021-08-19 09:34:24 -07:00
getargmax.c Make improvements 2022-04-28 09:57:07 -07:00
getdosargv.c Improve synchronization 2022-04-15 15:31:55 -07:00
getdosenviron.c Refactor some code 2022-05-28 14:09:21 -07:00
getinstructionlengths.c Support thread local storage 2022-05-16 13:20:08 -07:00
getinterpreterexecutablename.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
getmaxfd.c Reduce Makefile dependencies by 4% 2022-05-23 15:07:01 -07:00
getmemtracksize.c Add malloc logging tool 2022-05-26 23:19:22 -07:00
getpagesize.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
getresourcelimit.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
getsymbolname.c Improve memory safety 2021-10-13 17:27:13 -07:00
getsymboltable.c Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
grow.c Make numerous improvements 2021-09-28 01:52:34 -07:00
hook.greg.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
inflate.c Improve redbean plus code size optimizations 2022-05-29 08:21:19 -07:00
init.S Add ASAN guards to some asm data structures 2022-03-18 13:02:57 -07:00
interceptflag.greg.c Improve synchronization 2022-04-15 15:31:55 -07:00
internal.h Always initialize thread local storage 2022-07-19 00:21:46 -07:00
interruptiblecall.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
interruptiblecall.h Initial import 2020-06-15 07:18:57 -07:00
isheap.c Fix some issues and do some code cleanup 2022-05-23 10:15:53 -07:00
ismemtracked.greg.c Make some more fixups 2022-06-12 09:37:17 -07:00
issetugid.c Change license 2020-12-27 17:18:44 -08:00
jmpstack.S Improve signals and memory protection 2022-04-12 22:11:00 -07:00
ldso.c Get Fabrice Bellard's JavaScript engine to build 2021-04-09 01:06:57 -07:00
mapanon.c Always initialize thread local storage 2022-07-19 00:21:46 -07:00
mapelfread.c Change license 2020-12-27 17:18:44 -08:00
mapstack.c Add pipelining to cocmd 2022-07-15 20:47:20 -07:00
memtrack.internal.h Make some minor fixups to bug reporting, etc. 2022-07-11 05:58:24 -07:00
memtrack32.txt Fix build breakage in MODE=dbg 2022-06-15 19:37:39 -07:00
memtrack64.txt Add torture test for zipos file descriptors 2022-06-15 16:29:49 -07:00
memtracknt.c Make improvements 2022-04-07 00:15:35 -07:00
metalprintf.greg.c Improve synchronization 2022-04-15 15:31:55 -07:00
metalprintf.internal.h Support malloc() on bare metal 2021-02-24 00:53:24 -08:00
mman.internal.h Support malloc() on bare metal 2021-02-24 00:53:24 -08:00
mmap.c Make fixes and improvements 2022-06-25 21:09:09 -07:00
morph.greg.c Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
mprotect-nt.greg.c Make locks more reliable 2022-06-11 02:07:20 -07:00
mprotect.c Make fixes and improvements 2022-06-25 21:09:09 -07:00
mremap.c Reduce Makefile dependencies by 4% 2022-05-23 15:07:01 -07:00
msync-nt.c Make locks more reliable 2022-06-11 02:07:20 -07:00
msync.c Reduce Makefile dependencies by 4% 2022-05-23 15:07:01 -07:00
munmap.c Make fixes and improvements 2022-06-25 21:09:09 -07:00
openexecutable.S Fix Redbean when file is read-only (#365) 2022-03-14 17:13:28 -07:00
opensymboltable.greg.c Fix bugs and make improvements 2022-04-20 10:05:34 -07:00
pc.internal.h Add syscalls to Blinkenlights and fix bugs 2022-05-13 13:31:21 -07:00
peekall.S Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
printargs.c Make some minor fixups to bug reporting, etc. 2022-07-11 05:58:24 -07:00
printmaps.c Make locks more reliable 2022-06-11 02:07:20 -07:00
printmemoryintervals.c Make fixes and improvements 2022-06-25 21:09:09 -07:00
progname.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
program_invocation_short_name.S Add syscalls to Blinkenlights and fix bugs 2022-05-13 13:31:21 -07:00
runtime.h Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
runtime.mk Improve redbean plus code size optimizations 2022-05-29 08:21:19 -07:00
setstack.S Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
stack.h Third time's a charm with stack remaining checker 2022-07-14 07:38:44 -07:00
stackchkfail.c Fix some issues and do some code cleanup 2022-05-23 10:15:53 -07:00
stackchkfaillocal.c Change license 2020-12-27 17:18:44 -08:00
stackuse.c Make some touchups 2022-07-15 18:07:34 -07:00
straceinit.greg.c Add support for symbol table in .com files 2022-03-23 06:34:46 -07:00
symbolic.h wip on intellisense (again) 2021-02-02 11:14:45 -05:00
symbols.c Fix many thread and file descriptor issues on Windows 2022-05-20 20:57:19 -07:00
symbols.internal.h Add support for symbol table in .com files 2022-03-23 06:34:46 -07:00
sysconf.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
sysconf.h Fix a few more Python tests 2021-08-16 23:47:47 -07:00
untrackmemoryintervals.c Make some systemic improvements 2022-05-18 16:52:36 -07:00
unwind.c Fix libunwind stubs 2022-06-26 05:29:25 -07:00
unwind.h Fix libunwind stubs 2022-06-26 05:29:25 -07:00
utmp.h Add finger demo to redbean and fix regression 2022-06-23 03:42:05 -07:00
utmpx.h Add finger demo to redbean and fix regression 2022-06-23 03:42:05 -07:00
valist.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
valist.h Further refine documentation 2020-12-27 17:05:03 -08:00
vfork.S Don't use vfork() on XNU (#426) 2022-06-23 01:18:47 -07:00
warnifpowersave.c Print warning when microbenchmarking w/ powersave 2022-06-10 21:07:03 -07:00
weakfree.c Expose public garbage collector API for C language 2021-03-08 10:59:34 -08:00
winargs.internal.h Add torture test for zipos file descriptors 2022-06-15 16:29:49 -07:00
winmain.greg.c Make some minor fixups to bug reporting, etc. 2022-07-11 05:58:24 -07:00
winthreadlaunch.S Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00