mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
98254a7c1f
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.
35 lines
980 B
C
35 lines
980 B
C
#ifndef COSMOPOLITAN_LIBC_INTRIN_PROMISES_H_
|
|
#define COSMOPOLITAN_LIBC_INTRIN_PROMISES_H_
|
|
|
|
#define PROMISE_STDIO 0
|
|
#define PROMISE_RPATH 1
|
|
#define PROMISE_WPATH 2
|
|
#define PROMISE_CPATH 3
|
|
#define PROMISE_DPATH 4
|
|
#define PROMISE_FLOCK 5
|
|
#define PROMISE_FATTR 6
|
|
#define PROMISE_INET 7
|
|
#define PROMISE_UNIX 8
|
|
#define PROMISE_DNS 9
|
|
#define PROMISE_TTY 10
|
|
#define PROMISE_RECVFD 11
|
|
#define PROMISE_PROC 12
|
|
#define PROMISE_EXEC 13
|
|
#define PROMISE_ID 14
|
|
#define PROMISE_UNVEIL 15
|
|
#define PROMISE_SENDFD 16
|
|
#define PROMISE_SETTIME 17
|
|
#define PROMISE_PROT_EXEC 18
|
|
#define PROMISE_VMINFO 19
|
|
|
|
#define PLEDGED(x) ((~__promises >> PROMISE_##x) & 1)
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
hidden extern unsigned long __promises;
|
|
hidden extern unsigned long __execpromises;
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_INTRIN_PROMISES_H_ */
|