by the8472 · 4y ago · 0 comments
Not having an option to opt out when your program voluntarily tries to secure itself is terrible because it means fewer programs can use it to secure themselves. A classic example would be an ssh server. You want to factor it into several components, one that talks to the network and a privileged (root) part that spawns the child processes with arbitrary uids. The latter part can reasonably pledge away a lot of its privileges but its children must run unrestricted (but often on unprivileged users).
Keep in mind that if you can:
1. write to a file 2. Make that file executable (or write to an already-executable file, or an executable that provides scripting/ code exec natively)
And you have the `exec` capability, the sandbox is trivial to bypass in the face of code execution in the pledge'd process.
int main(int argc, char *argv[]) {
CHECK_NE(-1, pledge("stdio rpath wpath cpath exec", 0));
CHECK_NE(-1, open("/tmp/doge.exe", O_CREAT | O_WRONLY | O_TRUNC, 0755));
return 0;
}
But if other people are noticing it too, then I think I might change the tool to simply disallow creating new executables. Since that makes more sense to me. But naturally would make even more sense for OpenBSD.