5 ms·
>One of those marks executable memory that is empowered to call into the kernel; on OpenBSD systems, only the C library is given that capability. That will prev
by Sirened 4y ago
>One of those marks executable memory that is empowered to call into the kernel; on OpenBSD systems, only the C library is given that capability. That will prevent hostile code loaded elsewhere from making direct system calls; protecting the rest of a process with mimmutable() will prevent the changing of protections to allow system calls from elsewhere (such changes would be done with msyscall() on OpenBSD).
This is, unfortunately, a continuation of OpenBSD's long tradition of security "mitigations" that are entirely detached from any actual understanding of exploitation [1]. The above suggestion that attackers can no longer make syscalls from their shellcode, while ostensibly true, is moot because you can simply JOP to one of the authorized syscall instructions and entirely defeat the mitigation. Even if mimutable outright prevented any new code from being mapped, this still wouldn't really stop anyone; just look at iOS where attackers have thrived despite there only being one process on the entire OS which is able to map arbitrary code.
> Whenever a process enters the kernel, its stack pointer is checked to see whether it is, indeed, pointing into a stack region; if not, the process is killed.
This too is trivially defeated. You simply need to add another stage to your payload in which you copy your ROP payload onto the legitimate stack, pivot, and continue executing. If you managed to pivot off the original stack, you already have a pivot gadget and so you only then need to trigger a call to memcpy. This mitigation isn't stopping any real attacker.
While I never hope to discourage kernel developers from thinking about security mitigations, I think it is really important that people working on these mitigations actually converse with people who write exploits. Other vendors have seen considerable success with their mitigations [2] in that they specifically target things that attackers need and want to do, such as heap spray.
[1] See: ROP gadget elimination, a feature which does not actually stop ROP but merely hopes that "a substantial reduction of gadgets is powerful." <https://marc.info/?l=openbsd-tech&m=150317547021396&w=2 https://marc.info/?l=openbsd-tech&m=150317547021396&w=2>. Speaking from experience and having written plenty of actual exploits on attacker hostile platforms, trying to block code execution against an attacker who already has kernel read/write is an utterly ridiculous idea because even if you manage to stamp out every single ROP gadget, they can just go and stomp on your kernel page tables to map new kernel code. Even baring that, kernel R/W is still a complete compromise even if kernel code execution is somehow impossible because you can still just use R/W to bypass any control the kernel could ever hope to enforce.
[2] Life and death of an iOS attacker by Luca Todesco <https://www.youtube.com/watch?v=8mQAYeozl5I https://www.youtube.com/watch?v=8mQAYeozl5I>, a discussion of exploit mitigations on iOS and the exponential cost of defeating mitigations on iOS. Luca's company writes exploits for iOS devices as a service and he is extremely knowledgable in this area.
- ChoHag 4y ago
- saagarjha 4y ago> trying to block code execution against an attacker who already has kernel read/write is an utterly ridiculous idea iOS does this. Kernel code is immutable (obviously), page tables are locked at reset and cannot be modified except by PPL code. ROP and JOP are mitigated against using hardware CFI (PAC). As you mentioned, when vendors actually understand what exploits look like and what attackers need to do, it enables them to do a good job. OpenBSD remains a system with a few good ideas and a model of what exploits look like that appears to be informed by dreams and idle musings, rather than actual research.
- Sirened 4y agoI believe I should have couched that statement with a "for most everyone else" :) The PPL is a strong mitigation, I agree, but it is definitely one that is really only supported through their ability to ship custom hardware. Pulling off a PPL-like thing using MPK or a hypervisor is technically possible but in practice no real platform other than Apple is actually able to enforce memory mappings on all devices on an SoC and so anything you dream up to protect page tables is as durable as a wet paper bag since there's usually a half dozen other chips that will hapilly DMA any and all parts of physical memory for you. I dream of a day where we have an SMMU in front of every single device on a regular smartphone SoC (or, hell, even a PC platform), but that day has not yet come and I'm not really holding my breath either. As such, nobody else can actually meaningfully guarantees kernel code integrity under kernel R/W and so even if they had a perfect PAC implementation (which, as I'm sure you know, is incredibly difficult), you could just corrupt the backing code pages and sidestep it.
- saagarjha 4y agoRight, iOS definitely has a different threat model which requires (and takes advantage of) Apple's ability to make custom hardware. In this case, though, OpenBSD is looking to protect userspace, and they could provide guarantees for that (iOS does this via codesigning, but you could also just force security-sensitive programs to stop using dlopen).