News for hackers. Stuff that matters.
Re:OpenBSD – pinning all system calls by woodruffw on Monday December 11, 2023 @07:11PM (#38607328)
Without a pre-formed opinion: does anybody have an intuition for the security benefits this provides? My first thought is that it’s primarily mitigating cases of attacker-introduced shellcode, which should already be pretty well covered by techniques like W^X. Code reuse techniques (ROP, JOP, etc.) aren’t impacted, right?

I would also think this would cause problems for JITed code, although maybe syscalls in JITed code aren’t common enough for this to be an issue (or the JIT gets around it by calling a syscall thunk, similar to how Go handled OpenBSD’s earlier syscall changes).

Re:OpenBSD – pinning all system calls by gary_0 on Monday December 11, 2023 @07:32PM (#38607538)
> Code reuse techniques (ROP, JOP, etc.) aren’t impacted, right?

Unless I'm mistaken, this should restrict what you can do with ROP gadgets that contain syscalls. You will only be able to use the gadget with its intended arguments, since other syscall types will be disallowed.

> I would also think this would cause problems for JITed code

They can probably just jump into precompiled code that performs the needed syscall. Also, making syscalls directly from something like JITed JavaScript is generally avoided anyways. AFAIK browsers don't even let the processes that run JavaScript touch much of the system at all, instead they have to use an IPC mechanism to ask a slightly more privileged process to perform specific tasks.

Re:OpenBSD – pinning all system calls by woodruffw on Monday December 11, 2023 @07:43PM (#38607616)
> You will only be able to use the gadget with its intended arguments, since other syscall types will be disallowed.

That makes sense, although "intended" arguments here means still being able to invoke `execve(2)`, etc., right? The gadget will still be able to mangle whatever it likes into the arguments for that syscall; it just won't be able to mangle a `wait(2)` into an `execve(2)`, I think.

Your points about JITs make sense, thanks.

Re:OpenBSD – pinning all system calls by gary_0 on Monday December 11, 2023 @07:53PM (#38607700)
Yes, that's how I understand it; you can't mangle one syscall into another, but you can still mangle the syscall's other argument values.
Re:OpenBSD – pinning all system calls by enjoytheview on Monday December 11, 2023 @08:53PM (#38608278)
The other comment on this thread mentions that it also does something else:

>disables all the system calls not explicitly invoked by the program text of a static binary

This means that if the original library didn't have an execve call in it, you would'nt be able to use it even if with ROP. In short, this seems useful to block attackers from using syscalls that were not originally used by the program and nothing else. It can be useful.

Re:OpenBSD – pinning all system calls by woodruffw on Monday December 11, 2023 @08:59PM (#38608331)
Sure, assuming your programs don't execute other programs. I don't know much about OpenBSD specifically, but spawning all over the place is the "norm" in terms of "Unix philosophy" program design.

(I agree with the point in the adjacent thread: it's hard to know what to make of security mitigations that aren't accompanied by a threat model and attacker profile!)

Re:OpenBSD – pinning all system calls by pdonis on Monday December 11, 2023 @10:46PM (#38609164)
> assuming your programs don't execute other programs.

What about language runtimes? They don't execute other programs in the sense of ELF executables (although the programs they interpret might), but they have to support every syscall that's included in the language. So, for example, the Python interpreter would have to include the appropriate code for every syscall that Python byte code could call (in addition to whatever internal syscalls are used by the interpreter itself). That would be a pretty complete set of syscalls.

Re:OpenBSD – pinning all system calls by woodruffw on Monday December 11, 2023 @11:19PM (#38609418)
Yep, language runtimes are an (inevitably?) large attack surface. My understanding is that OpenBSD userspace processes can voluntarily limit their own syscall behavior with pledge[1], so a Python program (or the interpreter itself) could limit the scope of a particular process. But I have no idea how common that is.

[1]: https://man.openbsd.org/pledge

Re:OpenBSD – pinning all system calls by masklinn on Tuesday December 12, 2023 @01:00AM (#38610066)
A langage runtime would dispatch to the libc, which is always whitelisted.

This is only an issue for the weirdo langage runtimes who’d also refuse to use libc.

Re:OpenBSD – pinning all system calls by arzig on Tuesday December 12, 2023 @08:06AM (#38611624)
cough go cough

Although it is periodically useful to be able to copy a binary to some random Linux server and know it will work.

Re:OpenBSD – pinning all system calls by masklinn on Tuesday December 12, 2023 @08:40AM (#38611911)
Even for go it should actually work as-is: the syscalls should exist statically in the binary, so the loader can enumerate and whitelist them.

What gets blocked is the system constructing the entire thing at runtime, or at least setting the syscall number dynamically.

Re:OpenBSD – pinning all system calls by saagarjha on Tuesday December 12, 2023 @08:35PM (#38621536)
Isn’t that how all syscalls work? The syscall number typically goes in a register.
Re:OpenBSD – pinning all system calls by masklinn on Wednesday December 13, 2023 @02:55AM (#38623995)
The syscall goes in a register but it does not have to appear literally right next to the `syscall` instruction in the binary. As TFA explains in the introduction, a syscall stub generally looks like

    mov eax,0x5
    syscall
However it doesn’t have to, `syscall` will work as long as `eax` is set no matter where it’s set, or where it’s set from. You could load it from an array or a computation for all `syscall` cares.

So as an attacker if you can get eax to a value you control (and probably a few other registries) then jump to the `syscall` instruction directly you have arbitrary syscall capabilities.

The point of this change is that the loader now records exact syscall stubs as “address X performs syscall S”, then on context switch the kernel validates if the syscall being performed matches what was recorded by the loader, and if not it aborts (I assume I didn’t actually check).

This means as long as your go binary uses a normal syscall stub it’ll be recognised by the loader and whitelisted, but if say a JIT constructs syscalls dynamically (instead of bouncing through libc or whatever) that will be rejected because the loader won’t have that (address, number) recorded.

Re:OpenBSD – pinning all system calls by tedunangst on Monday December 11, 2023 @09:28PM (#38608539)
It is now less normal for programs to run programs on openbsd.
Re:OpenBSD – pinning all system calls by torstenvl on Monday December 11, 2023 @09:07PM (#38608385)
*Agent Smith voice*

But what use is a fork() if you're unable to exec()?

Re:OpenBSD – pinning all system calls by NobodyNada on Tuesday December 12, 2023 @12:59AM (#38610064)
> Code reuse techniques (ROP, JOP, etc.) aren’t impacted, right?

One thing to note is that system calls can no longer be made from the program's .text section; only from within libc. This is highly important because of ASLR: in order to ROP into a syscall, an attacker must now know where libc is located in the virtual address space. Before this mitigation, an attacker that only knew the address of the program binary could search for a sequence of bytes within the .text section that happened to decode to a syscall instruction, and use that for ROP (code reuse techniques can often access a lot of unexpected instructions by jumping into the middle of a multibyte instruction, due to x86's complex and variable-length instruction encoding).