Remove malloc() dependency on pledge() / unveil()

This change also fixes a bug with gettid() being incorrect after fork().
We now implement the ENOENT behavior for getauxval(). The getuid() etc.
system calls are now faster too. Plus issetugid() will work on BSDs.
This commit is contained in:
Justine Tunney 2022-07-24 19:40:32 -07:00
parent c921dc78f0
commit 3d2cf95af1
33 changed files with 270 additions and 100 deletions

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/pledge.internal.h"
#include "libc/calls/struct/bpf.h"
#include "libc/calls/struct/filter.h"
#include "libc/calls/struct/flock.h"
@ -562,6 +563,28 @@ TEST(pledge, threadWithLocks_canCodeMorph) {
EXPECT_EQ(0, WEXITSTATUS(ws));
}
TEST(pledge, everything) {
int ws, pid;
if (!fork()) {
// contains 548 bpf instructions [2022-07-24]
ASSERT_SYS(0, 0,
pledge("stdio rpath wpath cpath dpath "
"flock fattr inet unix dns tty "
"recvfd sendfd proc exec id "
"unveil settime prot_exec "
"vminfo tmppath",
"stdio rpath wpath cpath dpath "
"flock fattr inet unix dns tty "
"recvfd sendfd proc exec id "
"unveil settime prot_exec "
"vminfo tmppath"));
_Exit(0);
}
EXPECT_NE(-1, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(0, WEXITSTATUS(ws));
}
TEST(pledge, execWithoutRpath) {
int ws, pid;
ASSERT_SYS(0, 0, touch("foo", 0644));

View file

@ -63,6 +63,8 @@ o/$(MODE)/test/libc/calls/%.com.dbg: \
o/$(MODE)/test/libc/calls/life-nomod.com.zip.o \
o/$(MODE)/test/libc/calls/life-classic.com.zip.o \
o/$(MODE)/test/libc/calls/tiny64.elf.zip.o \
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
o/$(MODE)/test/libc/mem/prog/sock.elf.zip.o \
o/$(MODE)/third_party/python/Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt.zip.o \
o/$(MODE)/test/libc/calls/calls.pkg \
$(LIBC_TESTMAIN) \