by CJefferson · 9y ago · 0 comments
I work on several C programs. I wish for the day when we have an easy to use, cross platform method of setting up a small set of open files at the start of a program, then be able to say "No more file access, no more network connections".
I know this hides a whole bunch of complication, which is why it's hard and why there are so many ways to do it -- I view it the same way as the move to distinct virtual memory spaces for each process. Once we have it we'll wonder why we ever allowed every program free access to the whole file system for it's entire life-span by default.
> say "No more file access, no more network connections".
Looks like you're advocating OpenBSD's pledge(2). http://man.openbsd.org/OpenBSD-current/man2/pledge.2Hopefully someone (and it won't be me :) ) will write a library which looks like pledge but wraps all the various things in different OSses (I hear words like seccomp on linux)
on linux the low-level building blocks that can achieve similar are seccomp and namespaces, but the only abstractions that I am aware of involve separate launcher processes like runc[0] or firejail[1].
A library providing similar functionality to pledge that could be added during application startup or when doing fork+exec would be great.
[0] https://github.com/opencontainers/runtime-spec/blob/master/c... [1] https://firejail.wordpress.com/features-3/
Sadly that's a huge change in programming and security model for most and wouldn't be an easy change to make.
You could potentially use setrlimit on RLIMIT_NOFILE to limit your number of open files.
Although... you probably still want to display something to the terminal which means you still want stdout and stderr, so an attacker could just close stdout and stderr before doing whatever they wanted with their 2 remaining fds.
Just thought it was an interesting approach I'd share.