News for hackers. Stuff that matters.
Re:OpenBSD's Pledge and Unveil from Python by travisgriggs on Wednesday September 15, 2021 @12:56AM (#28535413)
I was not familiar with these syscalls. Are they primarily in a “if you build it they will come” stage right now? Or is there an upswing of usage in the BSD world? Does the Linux kernel have any analog to pledge and unveil?
Re:OpenBSD's Pledge and Unveil from Python by moonchild on Wednesday September 15, 2021 @02:08AM (#28535793)
> BSD world

Pledge/unveil are openbsd-specific. Freebsd has capsicum which, like seccomp (mentioned else-thread) is much more complex and flexible.

Pledge/unveil are manifestly more successful, being used pervasively (though not really by programs which do not primarily target openbsd). Seccomp and capsicum are barely used at all (likely due to their higher complexity), and capsicum usage was even removed from a few freebsd utilities. At the same time, there have been some valid criticisms of pledge/unveil by capsicum people; IIRC something to do with its restrictions not persisting following an exec?

Re:OpenBSD's Pledge and Unveil from Python by foxfluff on Wednesday September 15, 2021 @05:12AM (#28536918)
> At the same time, there have been some valid criticisms of pledge/unveil by capsicum people; IIRC something to do with its restrictions not persisting following an exec?

The validity of that criticism is so-so. It's a common complaint from people who are trying to build an externally imposed sandbox that dictates what a program can do.

But that's not what pledge and unveil are. They're more of an internally imposed set of constraints: the program just announces what it's going to do. After that, if it breaks the contract (due to a bug or malicious intervention), the system has license to kill it.

The program knows what it is going to do, so it can write the contract for itself. But it doesn't know what some other program is going to do, so it doesn't make sense for these restrictions to persist after exec. The program-to-be-exec'd should have its own pledges.

In reality it's even more complicated than that: programs often need to perform some "privileged" operations before they are ready to put on their straight jacket. It'd be very hard for program A to say that program B starts with privileges X, Y, Z, and then after instruction Q drops Y and Z. And program B might require more privileges than what A had when it called exec, so again it's just not going to work for this at all. If A's privileges were to persist, then it would have to have some way to elevate them or it'd never drop them in the first place. Both seem like a bad deal.

It's just a completely different mechanism, but people think sandbox sandbox sandbox and if that's all one can think of, pledge and unveil might seem like a terrible tool for that. They're not a tool for sandboxing untrusted programs.

Re:OpenBSD's Pledge and Unveil from Python by ori_b on Wednesday September 15, 2021 @09:05AM (#28538590)
It's also worth noting that you can pledge for an execed process using the second argument to pledge. This is for when you know what the child is expected to do on your behalf.
Re:OpenBSD's Pledge and Unveil from Python by xnormal on Wednesday September 15, 2021 @10:42AM (#28539725)
> Pledge/unveil are manifestly more successful, being used pervasively (though not really by programs which do not primarily target openbsd).

Because of their simplicity, they are easily added as a patch to a ported application. There are probably more ports using them than programs that target openbsd.

Re:OpenBSD's Pledge and Unveil from Python by protomyth on Wednesday September 15, 2021 @11:24AM (#28540319)
It really doesn't make much sense to compare pledge/unveil to seccomp and capsicum or any other sandboxing solution.

Pledge and Unveil are really part of the program's specification. They are much closer in practice to asserts, pre-conditions, or contracts depending on the programming language you have used. They basically make sure that the program you are writing doesn't do anything stupid with bad inputs from the outside world. Its part of the development process, and not very hard to add to an existing program.

Re:OpenBSD's Pledge and Unveil from Python by the8472 on Wednesday September 15, 2021 @08:23AM (#28538158)
A major limitation of seccomp is that you can't turn off inheritance. With pledge inheritance is opt-in.

This has major consequences because it makes it possible for a process to secure itself without affecting its ability to spawn child processes. You could apply seccomp in-process or use a spawn-helper before securing it. But more realistically it means that one applies an external seccomp profile to a group of processes (e.g. a container) that contains the union of all needed syscalls.

So while seccomp is more flexible in some sense (being able to run BPF filters on every syscall) its architecture leads to it being applied in a less flexible way.

Re:OpenBSD's Pledge and Unveil from Python by toast0 on Wednesday September 15, 2021 @05:55AM (#28537181)
> Freebsd has capsicum which, like seccomp (mentioned else-thread) is much more complex and flexible.

Capsicum may be more flexible in some ways, but it's also less flexible in others.

After you a process entera capsicum mode, it can't open new sockets, except by accepting on an existing listen socket or by receiving them on a unix socket, sent by a cooperating non-capsicum process. This means you can't capsicum a TLS proxy like hitch, which would be a great thing to capsicum since the operation is pretty simple and OpenSSL is scary.

Re:OpenBSD's Pledge and Unveil from Python by trasz on Wednesday September 15, 2021 @07:40AM (#28537818)
No true, of course you can do that. Not being able to open files or sockets only means you need a small separate process to do that for you and then send you the file descriptors.
Re:OpenBSD's Pledge and Unveil from Python by toast0 on Wednesday September 15, 2021 @08:11AM (#28538051)
I said you could get them from a cooperating uncapsicumed process. But, it's not simple, and what are you going to write that loophole process in, and why does it get access to the filesystem if it only needed sockets, etc.

Capsicum is simply not flexible in this way. Maybe if there was a way to open a new socket with a capability you setup earlier, that would be flexible enough.

Re:OpenBSD's Pledge and Unveil from Python by trasz on Wednesday September 15, 2021 @08:40AM (#28538323)
It is pretty simple - implementing that for irssi(1) took a dozen or two lines of C, IIRC. Sure, it could be simpler, and hopefully libcasper(3) will make it happen, but it's not much of a difference.
Re:OpenBSD's Pledge and Unveil from Python by ingve on Wednesday September 15, 2021 @02:29AM (#28535900)
They are also available (and used) in SerenityOS:

https://awesomekling.github.io/pledge-and-unveil-in-Serenity...

Re:OpenBSD's Pledge and Unveil from Python by dbt00 on Wednesday September 15, 2021 @01:01AM (#28535435)
they only exist on OpenBSD. They're used a lot for default OpenBSD binaries, but they are mostly hopeless for openbsd developers/porters to try to apply to portable software after the fact if the upstream devs aren't supporting that work.

(There are other mechanisms like containers or freebsd' jail that try to accomplish the same thing, but those tend to be "lots of functionality inside the sandbox" solutions, whereas openbsd is mostly aiming for "allow nothing besides the minimum in the sandbox".

(edited for clarity, thanks for the nudge ghoward).

Re:OpenBSD's Pledge and Unveil from Python by ghoward on Wednesday September 15, 2021 @01:23AM (#28535538)
I upvoted, but I wanted to correct a small thing.

> ...they are mostly hopeless to try to apply to portable software after the fact if the devs aren't constantly testing with it.

They don't have to be hopeless. They were pretty easy ([1], [2]) to add to my bc.

[1]: https://git.yzena.com/gavin/bc/commit/3e8cd345de9d5b65ac7c33...

[2]: https://git.yzena.com/gavin/bc/commit/b6c65bb44c910c054bedfa...

Re:OpenBSD's Pledge and Unveil from Python by dbt00 on Wednesday September 15, 2021 @01:29AM (#28535572)
Yes. That's awesome!

I was referring to the OpenBSD devs trying to hack pledges into other people's software by trying to guess what capabilities it needs while porting. That's not a good thing to try to do -- see also all the various attempts at guessing seccomp profiles in the Linux world, which has the same problem.

Re:OpenBSD's Pledge and Unveil from Python by ben_bai on Wednesday September 15, 2021 @07:46AM (#28537867)
Has been done to some 3rd party applications. Notably Chromium is pledged an unveiled, Firefox (unveil), pdf readers, compression tools, mail clients, ...

grep the ports tree for pledge patches.

Re:OpenBSD's Pledge and Unveil from Python by ghoward on Wednesday September 15, 2021 @10:06AM (#28539194)
I see what you mean now, and I think you are completely correct in that!
Re:OpenBSD's Pledge and Unveil from Python by baq on Wednesday September 15, 2021 @03:20AM (#28536222)
looks like unveil() has an rough analog in Linux 5.13: https://landlock.io/, there was even a HN discussion which I missed: https://news.ycombinator.com/item?id=27215563
Re:OpenBSD's Pledge and Unveil from Python by rbanffy on Wednesday September 15, 2021 @08:53AM (#28538469)
Would be useful to have a unified API…
Re:OpenBSD's Pledge and Unveil from Python by oneplane on Wednesday September 15, 2021 @12:23PM (#28541069)
Indeed, but on the other hand, almost all of the projects mentioned in the comments here are of the 'for this project, we do it this way' type of implementation meaning that in their local use case their way is the unified API.

That is both the benefit and the downside of non-commercial projects: you get to do whatever you want.

Re:OpenBSD's Pledge and Unveil from Python by rbanffy on Thursday September 16, 2021 @05:22AM (#28549622)
True. It may be worth postponing a unified API when the semantics solidify. I really like the pledge/unveil semantics, but it's not a consensus.
Re:OpenBSD's Pledge and Unveil from Python by chousuke on Wednesday September 15, 2021 @01:53AM (#28535713)
To my understanding, you can use existing Linux kernel facilities like seccomp to build equivalents for pledge and unveil. The latter are less flexible but also easier to use, which is a point in their favour; ease of use matters for security.
Re:OpenBSD's Pledge and Unveil from Python by masklinn on Wednesday September 15, 2021 @01:09AM (#28535475)
> I was not familiar with these syscalls. Are they primarily in a “if you build it they will come” stage right now?

It’s an openbsd feature they built for themselves and deployed throughout the base system.

Re:OpenBSD's Pledge and Unveil from Python by robmusial on Wednesday September 15, 2021 @01:08AM (#28535468)
seccomp in linux is _roughly_ similar to pledge. they aim to accomplish the same goals but pledge is more straightforward. think of it like sudo vs doas.
Re:OpenBSD's Pledge and Unveil from Python by Godel_unicode on Wednesday September 15, 2021 @02:06AM (#28535773)
Seccomp profiles are typically applied externally to a process in my experience though. I think this is more analogous to using capset() to remove capabilities in highly permissioned processes. For instance dnsmasq makes use of this ability to be minimally permissioned.