[PATCH 1/2] OpenBSD: Always unveil
From: Klemens Nanni
To: list+catgirl
Cc: Klemens Nanni
Even though catgirl never ends up with any write/create permissions on the filesystem outside of the logdir, explicitly unveiling `/' (root) executable-only guards against any programming mistakes while also documenting the behaviour through code. This also decouples `log' and `restrict' semantics further, simplifing logic. Note that `logdir' must be unveiled first, otherwise unveiling root hides the data directory and creating `logdir' prior to unveiling it fails (obvious in hindsight but worth mentioning nonetheless). --- chat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chat.c b/chat.c index 9934fc3..0bdb69c 100644 --- a/chat.c +++ b/chat.c @@ -282,12 +282,17 @@ int main(int argc, char *argv[]) { } #ifdef __OpenBSD__ - if (self.restricted && log) { + if (log) { const char *logdir = dataMkdir("log"); int error = unveil(logdir, "wc"); if (error) err(EX_OSERR, "unveil"); } + if (!self.restricted) { + int error = unveil("/", "x"); + if (error) err(EX_OSERR, "unveil"); + } + char promises[64] = "stdio tty"; char *ptr = &promises[strlen(promises)], *end = &promises[sizeof(promises)]; if (log) ptr = seprintf(ptr, end, " wpath cpath"); -- 2.32.0