5 ms·
I'm not familiar with OpenBSD and certainly not with pledge, so I'm having little luck finding the answer to: Can I start a process in some way that means "dem
by OJFord 11y ago
I'm not familiar with OpenBSD and certainly not with pledge, so I'm having little luck finding the answer to:
Can I start a process in some way that means "demand a pledge call, and only allow [x,y,z] / disallow [a,b,c]"?
- umanwizard 11y agoThe same way you start any other process: fork/exec. But in between (i.e., after you fork but before you exec), call pledge. I can't test that since I don't have openbsd installed, but I don't see why it wouldn't work.
- sdkmvx 11y agoThat won't work because exec resets pledge. A very important part of pledge's design is that a parent can be more restricted than its child. This isn't a sandboxing mechanism. It's intended to mitigate the dangers of some other vulnerability leading to remote code execution. With pledge, even if you get into the system you may not be able to make all the syscalls you need.
- umanwizard 11y ago> exec resets pledge Source? I didn't see that in the man page.
- sdkmvx 11y agoFrom the manpage: > exec: Allows a process to call execve(2). Coupled with the proc promise, this allows a process to fork and execute another program. The new program starts running without pledge active and hopefully makes a new pledge().
- umanwizard 11y agoThat's not clear, though. "The new program" it talks about is after running fork and exec, not just exec. It doesn't specify which call resets the pledge.
- heinrich5991 11y agoFrom the quoted text I'd understand it's the `exec` that resets the pledge.
- umanwizard 11y agoI installed OpenBSD so I could check this out. tl;dr, you were right. $ cat testpledge.c #include <unistd.h> #include <stdio.h> int main() { pledge("proc exec", NULL); execl("/bin/echo", "echo", "asdf", NULL); _exit(0); } $ cc testpledge.c $ ./a.out asdf
- gpvos 11y agoAfter fork, the original program is still running. The text specifically refers to the proc promise, which allows fork. It may be tersely formulated, but I really don't see how you could interpret this text otherwise.
- deleted 11y ago[deleted]
- amluto 11y ago> A very important part of pledge's design is that a parent can be more restricted than its child. This isn't a sandboxing mechanism. It's intended to mitigate the dangers of some other vulnerability leading to remote code execution. With pledge, even if you get into the system you may not be able to make all the syscalls you need. ISTM this will just slightly raise the bar so that attackers who get code execution have to force a call to execve. On the other hand, it avoids needing to worry about all the setuid issues that Linux's seccomp avoids using PR_SET_NO_NEW_PRIVS.
- ycmbntrthrwaway 11y ago> this will just slightly raise the bar so that attackers who get code execution have to force a call to execve In most cases your program doesn't need execve, so it can call pledge without "exec" promise. Sometimes you will still be able to open some shell script and add your commands there or something like this, but without "wpath" promise it is impossible.
- brynet 11y agoIt is indeed another security mitigation, any potential attack payload will need to do more work and hence require more code. In fact, most programs will not need the exec promise in which case any attempt to call execv(3).. Abort trap (core dumped) If you think about the semantics of execv(3), it needs a path to an existing executable. So an attacker will need to know of one in advance, or write one out to disk beforehand.. oh but-- Abort trap (core dumped) The exploited process pledged "stdio rpath proc exec" and cannot write to arbitrary files. Hmm. Bummer.
- amluto 11y ago> If you think about the semantics of execv(3), it needs a path to an existing executable. So an attacker will need to know of one in advance, or write one out to disk beforehand.. oh but-- /bin/sh, perhaps? It's harder to pass in machine code, but I bet there's a way. /bin/sh -c "echo -e shellcode_here >/tmp/foo; chmod 700 /tmp/foo; /tmp/foo" seems plausible to me.