cosmopolitan/libc/str
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
..
a64l.c Add base64 support 2021-03-27 18:17:54 -07:00
bcmp.c Change noinline to dontinline (#312) 2021-11-12 15:12:18 -08:00
blake2.c Flatten InfoZIP directory and fix build issues 2022-04-20 22:40:33 -07:00
blake2.h Decentralize Python native module linkage 2021-09-07 11:40:11 -07:00
bsf.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
bsfl.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
bsfll.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
bsr.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
bsrl.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
bsrll.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
btowc.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
c16rtomb.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
c32rtomb.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
chomp.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
chomp16.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
classifypath.c Add NET_HTTP to the amalgamation 2022-05-16 14:47:49 -07:00
compareslices.c Refactor out some duplicated code 2021-08-14 06:17:56 -07:00
compareslicescase.c Refactor out some duplicated code 2021-08-14 06:17:56 -07:00
crc32.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
crc32c.c Restart CI for New Technology and UBSAN hunting 2022-03-21 04:32:57 -07:00
crc32z.c Make numerous improvements 2021-09-28 01:52:34 -07:00
djbsort.c Change noinline to dontinline (#312) 2021-11-12 15:12:18 -08:00
dosdatetimetounix.c Undiamond Python headers 2021-08-12 14:07:40 -07:00
endswith.c Perform some code cleanup 2021-02-27 10:33:32 -08:00
endswith16.c Change license 2020-12-27 17:18:44 -08:00
escapedos.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
explicit_bzero.S Undiamond Python headers 2021-08-12 14:07:40 -07:00
findembeddedape.c Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
getcachesize.c Fix Clang support 2021-02-06 00:29:09 -08:00
getutf16.ncabi.c Change license 2020-12-27 17:18:44 -08:00
getx86processormodel.c Change license 2020-12-27 17:18:44 -08:00
getzipcdir.c Apply fixes and speedups 2021-10-04 03:23:31 -07:00
getzipcdircomment.c Make redbean StoreAsset() work better 2021-05-14 05:44:37 -07:00
getzipcdircommentsize.c Make redbean StoreAsset() work better 2021-05-14 05:44:37 -07:00
getzipcdiroffset.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getzipcdirrecords.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getzipcdirsize.c Mold the redbean binary to minimize page faults 2021-05-03 12:14:13 -07:00
getzipcfilecompressedsize.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getzipcfilemode.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getzipcfileoffset.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getzipcfiletimestamps.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
getzipcfileuncompressedsize.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getziplfilecompressedsize.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
getziplfileuncompressedsize.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
hextoint.c Change license 2020-12-27 17:18:44 -08:00
highwayhash64.c Make numerous improvements 2021-09-28 01:52:34 -07:00
highwayhash64.h Make numerous improvements 2021-09-28 01:52:34 -07:00
index.c Make more functions friendly to Address Sanitizer 2021-02-02 03:45:31 -08:00
indexdoublenulstring.c Change license 2020-12-27 17:18:44 -08:00
insertionsort.greg.c Make C memory safe like Rust 2021-02-01 03:58:46 -08:00
internal.h Fix Clang support 2021-02-06 00:29:09 -08:00
isabspath.c Add NET_HTTP to the amalgamation 2022-05-16 14:47:49 -07:00
isalnum.c Change license 2020-12-27 17:18:44 -08:00
isalpha.c Change license 2020-12-27 17:18:44 -08:00
isascii.c Change license 2020-12-27 17:18:44 -08:00
isblank.c Change license 2020-12-27 17:18:44 -08:00
iscntrl.c Change license 2020-12-27 17:18:44 -08:00
isdigit.c Change license 2020-12-27 17:18:44 -08:00
isdirsep.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
isgraph.c Change license 2020-12-27 17:18:44 -08:00
islower.c Change license 2020-12-27 17:18:44 -08:00
isprint.c Change license 2020-12-27 17:18:44 -08:00
ispunct.c Change license 2020-12-27 17:18:44 -08:00
isspace.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
istext.c Introduce --strace flag for system call tracing 2022-03-18 18:07:28 -07:00
isupper.c Change license 2020-12-27 17:18:44 -08:00
isutf8.c Introduce --strace flag for system call tracing 2022-03-18 18:07:28 -07:00
iswalnum.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswalpha.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswblank.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswcntrl.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswctype.c Improve LLVM compatibility a little bit 2021-05-16 20:34:46 -07:00
iswdigit.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswgraph.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswlower.c Improve Python and Linenoise 2021-09-11 22:30:37 -07:00
iswprint.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswpunct.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswseparator.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
iswspace.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iswupper.c Improve Python and Linenoise 2021-09-11 22:30:37 -07:00
iswxdigit.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
isxdigit.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
iszipcdir32.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
iszipcdir64.c Make redbean StoreAsset() work better 2021-05-14 05:44:37 -07:00
khextoint.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
kmonthyearday.c Undiamond Python headers 2021-08-12 14:07:40 -07:00
kx86processormodels.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
l64a.c Add base64 support 2021-03-27 18:17:54 -07:00
longsort.c Make improvements 2022-04-27 05:39:39 -07:00
lz4check.c Change license 2020-12-27 17:18:44 -08:00
lz4cpy.c Make ANSI mode closer to being ANSI 2021-02-03 17:14:17 -08:00
lz4decode.c Make _Thread_local work across platforms 2022-07-10 04:01:17 -07:00
mb.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mb.internal.h Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mblen.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbrlen.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbrtoc16.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbrtoc32.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbrtowc.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbsinit.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbsnrtowcs.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbsrtowcs.c Add SSL to redbean 2021-06-24 13:20:50 -07:00
mbstowcs.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
mbtowc.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
memcasecmp.c Make numerous improvements 2021-09-28 01:52:34 -07:00
memccpy.c Refactor some code 2022-05-28 14:09:21 -07:00
memchr.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
memfrob.c Change license 2020-12-27 17:18:44 -08:00
memmem.c Mold the redbean binary to minimize page faults 2021-05-03 12:14:13 -07:00
memrchr.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
memrchr16.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
memset16.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
oldutf16.internal.h Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
path.h Make pledge() and unveil() work amazingly 2022-07-19 21:33:49 -07:00
pututf16.ncabi.c Implement more security stuff 2021-02-02 20:21:06 -08:00
qsort.c Make improvements 2022-04-24 10:06:05 -07:00
rawmemchr.c Improve memory safety 2021-10-13 17:27:13 -07:00
rindex.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
rldecode2.c Make numerous improvements 2021-09-28 01:52:34 -07:00
slice.h Fixup and polish chibicc some more 2022-06-20 04:32:25 -07:00
startswith.c Change license 2020-12-27 17:18:44 -08:00
startswith16.c Change license 2020-12-27 17:18:44 -08:00
startswithi.c Add lua repl interface to redbean 2022-04-16 20:31:16 -07:00
stpncpy.c Make numerous improvements 2021-09-28 01:52:34 -07:00
str.h Perform some code cleanup 2022-06-23 10:21:07 -07:00
str.mk Make fixes and improvements 2022-05-19 16:57:49 -07:00
strcasecmp.c Improve ZIP filesystem and change its prefix 2021-08-22 01:11:53 -07:00
strcasecmp8to16.c Change license 2020-12-27 17:18:44 -08:00
strcasecmp16.c Make major improvements to redbean and libraries 2021-04-18 12:34:15 -07:00
strcat.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
strcat16.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
strchr.c Improve memory safety 2021-10-13 17:27:13 -07:00
strchrnul.c Make improvements 2022-04-27 05:39:39 -07:00
strclen.c Change noinline to dontinline (#312) 2021-11-12 15:12:18 -08:00
strclen16.c Change noinline to dontinline (#312) 2021-11-12 15:12:18 -08:00
strcmp.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
strcmp8to16.c Change license 2020-12-27 17:18:44 -08:00
strcmp8to16i.internal.h Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
strcmp16.c Change license 2020-12-27 17:18:44 -08:00
strcoll.c Add more POSIX function stubs 2021-03-02 03:27:55 -08:00
strcpy16.c Implement getcwd() for XNU 2021-01-30 08:54:12 -08:00
strcspn.c Make numerous improvements 2021-09-28 01:52:34 -07:00
strcspn16.c Change license 2020-12-27 17:18:44 -08:00
strlcat.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
strlcpy.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
strlen16.c Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
strncasecmp.c Change license 2020-12-27 17:18:44 -08:00
strncasecmp8to16.c Change license 2020-12-27 17:18:44 -08:00
strncasecmp16.c Tune SQLite build for redbean (#97) 2021-06-10 08:00:08 -07:00
strncat.c Add NetBSD support 2021-02-05 06:19:45 -08:00
strncat16.c Undiamond Python headers 2021-08-12 14:07:40 -07:00
strncmp.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
strncmp8to16.c Change license 2020-12-27 17:18:44 -08:00
strncmp16.c Change license 2020-12-27 17:18:44 -08:00
strncpy.c Make numerous improvements 2021-09-28 01:52:34 -07:00
strnlen.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
strnlen16.c Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
strnlen_s.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
strntolower.c Change license 2020-12-27 17:18:44 -08:00
strntoupper.c Implement more security stuff 2021-02-02 20:21:06 -08:00
strpbrk.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
strpbrk16.c Change license 2020-12-27 17:18:44 -08:00
strrchr.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
strrchr16.c Change license 2020-12-27 17:18:44 -08:00
strsep.c Perform some code cleanup 2021-02-27 10:33:32 -08:00
strspn.c Change license 2020-12-27 17:18:44 -08:00
strspn16.c Change license 2020-12-27 17:18:44 -08:00
strstr.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
strstr16.c Perform some code cleanup 2021-02-27 10:33:32 -08:00
strtok.c Change license 2020-12-27 17:18:44 -08:00
strtok_r.c Change license 2020-12-27 17:18:44 -08:00
strtolower.c Implement more security stuff 2021-02-02 20:21:06 -08:00
strtoupper.c Implement more security stuff 2021-02-02 20:21:06 -08:00
strverscmp.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
strxfrm.c Make redbean StoreAsset() work better 2021-05-14 05:44:37 -07:00
thompike.h Import some Lua documentation 2021-08-22 15:03:04 -07:00
timespectowindowstime.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
timevaltowindowstime.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
timingsafe_bcmp.c Change noinline to dontinline (#312) 2021-11-12 15:12:18 -08:00
timingsafe_memcmp.c Make numerous improvements 2021-09-28 01:52:34 -07:00
tolower.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
toupper.c Change license 2020-12-27 17:18:44 -08:00
towctrans.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
towlower.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
towupper.c Make fixes, improvements, and chibicc python bindings 2021-10-08 08:41:57 -07:00
tpdecode.internal.h Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
tpdecode.ncabi.c Implement more security stuff 2021-02-02 20:21:06 -08:00
tpdecodecb.internal.h wip on intellisense (again) 2021-02-02 11:14:45 -05:00
tpenc.h Add MODE=optlinux build mode (#141) 2021-10-14 19:36:49 -07:00
tpencode.internal.h Get Cosmopolitan into releasable state 2020-11-25 08:19:00 -08:00
tpencode.ncabi.c Change license 2020-12-27 17:18:44 -08:00
tprecode8to16.c Make SSL handshakes much faster 2021-07-11 23:17:47 -07:00
tprecode16to8.c Make SSL handshakes much faster 2021-07-11 23:17:47 -07:00
undeflate.c Add support for symbol table in .com files 2022-03-23 06:34:46 -07:00
undeflate.h Initial import 2020-06-15 07:18:57 -07:00
utf16.h Make improvements 2022-03-16 13:40:10 -07:00
wchomp.c Fix basename() and dirname() 2022-04-06 00:13:44 -07:00
wcrtomb.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wcscasecmp.c Change license 2020-12-27 17:18:44 -08:00
wcscat.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
wcscmp.c Change license 2020-12-27 17:18:44 -08:00
wcscpy.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
wcscspn.c Change license 2020-12-27 17:18:44 -08:00
wcsendswith.c Change license 2020-12-27 17:18:44 -08:00
wcslen.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wcsncasecmp.c Change license 2020-12-27 17:18:44 -08:00
wcsncat.c Undiamond Python headers 2021-08-12 14:07:40 -07:00
wcsncmp.c Change license 2020-12-27 17:18:44 -08:00
wcsncpy.c Change license 2020-12-27 17:18:44 -08:00
wcsnrtombs.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wcspbrk.c Change license 2020-12-27 17:18:44 -08:00
wcsrchr.c Change license 2020-12-27 17:18:44 -08:00
wcsrtombs.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wcsspn.c Change license 2020-12-27 17:18:44 -08:00
wcsstartswith.c Change license 2020-12-27 17:18:44 -08:00
wcstok.c Added wcstok and wmemcmp (#183) 2021-06-09 19:34:27 -07:00
wcstombs.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wctob.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wctomb.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wctrans.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
wctype.c Improve some unicode functions 2021-05-05 07:25:39 -07:00
windowsdurationtotimespec.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
windowsdurationtotimeval.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
windowstimetotimespec.c Get more Python tests passing (#141) 2021-08-16 15:26:31 -07:00
windowstimetotimeval.c Import some Lua documentation 2021-08-22 15:03:04 -07:00
wmemcmp.c Added wcstok and wmemcmp (#183) 2021-06-09 19:34:27 -07:00
wmemcpy.c Change license 2020-12-27 17:18:44 -08:00
wmemmove.c Change license 2020-12-27 17:18:44 -08:00
wmempcpy.c Add Musl multibyte functions 2021-03-06 09:53:16 -08:00
wmemrchr.c Perform some code cleanup 2022-06-23 10:21:07 -07:00
wmemset.c Add APE interpreter example (#263) 2021-09-04 00:58:21 -07:00