Software (emulated) NoExecute on *BSD? reddit / BSD ---------------------------------------------------------------------- aGIFTedTroll · 2021-05-14 03:19 Greetings, anyone up-to-date on the status of software NoExecute (W\^X or NX) on all the BSD OSes? And any other \*nix-like including Linux, for that matter, since PaX has been paywalled for some time and other Linux patches look like they ceased to exist around ~2005. I'm asking in general, but I'm particularly interested in implementations for 32-bit x86 as well as older ARM architectures like might be found in a Raspberry Pi Zero. I'm assuming the related ASLR (in userspace) is available in all of them, since it shouldn't depend on CPU features. I know even 15 year old PC hardware is likely to be 64-bit x86 by now, which comes with executable memory protection as an architectural feature, but what about platforms that don't have that? Or oddball architectures that do have such a feature, but where ports might not have implemented it? Old things on the web I've seen make it sound like OpenBSD at least has this on 32-bit x86, but googling the topic failed to get me any info and I don't currently have time to try installing every BSD on real hardware and compile/run paxtest (which might be getting old and thus hard to get working, especially outside linux). Doing that also wouldn't get me any info on the implementation, compared to if someone here knows about it. Thanks! edit: Answering a bit of my own question, here's a mailing list post (from 2003) [about OpenBSD's i386 implementation](https://marc.info/?l=openbsd-misc&m=105056000801065), and here's [a page about NetBSD's](https://www.netbsd.org/docs/kernel/non-exec.html) for all relevant architectures. For NetBSD on i386, due to hardware limitiations "By default, the stack is not executable and everything else is executable". Does anyone know if this means the implementation might leave holes open (compared to OpenBSD or hardware NX), or is it just a matter of "ugly code but it works"? edit 2: More info on NetBSD, [man 7 security](https://man.netbsd.org/NetBSD-9.1/i386/security.7). Also, HardenedBSD [here](https://hardenedbsd.org/article/shawn- webb/2015-03-19/introducing-noexec). ---------------------------------------------------------------------- vermaden · 2021-05-14 09:09 For FreeBSD ... Quote from the [https://www.freebsd.org/releases/13.0R/relnotes/](http s://www.freebsd.org/releases/13.0R/relnotes/) page: ***The kernel now supports enforcing a W\^X memory mapping policy for user processes.*** *The policy is not enforced by default but can be enabled by setting the* ***kern.elf32.allow\_wx*** *and* ***kern.elf64.allow\_wx*** *sysctls to* ***0***\*. Individual binaries can be exempted from the policy by\* ***elfctl(1)*** *via the* ***wxneeded*** *feature.* ***(Sponsored by The FreeBSD Foundation)*** ---------------------------------------------------------------------- photons_are_scary · 2021-05-14 10:30 fully supported in NetBSD for all architectures that support it, which is most (excludes i386 without PAE and powerpc, which protect only the stack via other means - presumably segmentation on i386 and BAT tables on powerpc) NetBSD implements it's protections using PaX, btw. ---------------------------------------------------------------------- FUZxxl · 2021-05-14 12:20 All modern architectures have hardware support for no execute and FreeBSD of course supports that. In fact, it strictly sets up no- execute for the data segment and stack. You can even enforce W\^X by setting a certain sysctl (but then some applications won't run). The special OpenBSD trick was to use segment limits (an i386-only feature) to get a sort of poor man's no execute on i386 systems that do not support the no execute bit. Such systems have been obsolete for a long time now. ---------------------------------------------------------------------- shawn_webb · 2021-05-14 17:35 Both HardenedBSD and NetBSD have PaX NOEXEC-inspired strict W^X implementations. Both implementations are effective at emulating the NX bit for userland applications. ---------------------------------------------------------------------- PitifulView · 2021-05-14 20:01 You don't need software emulation for the Raspberry Pi Zero. ARMv6 introduced support for hardware NoExecute (called "Execute Never" in ARM terminology). [NetBSD/arm certainly seems to have code for setting this bit](https:/ /nxr.netbsd.org/search?q=L2_XS_XN&project=src&defs=&refs=&path=&hist=) , I'm not qualified to understand where it's used. ---------------------------------------------------------------------- aGIFTedTroll · 2021-05-14 22:05 Ah, neat. I must have recalled wrong when I thought ARMv6 didn't have execute never, as a 2002 architecture it's certainly old enough... but it does. ---------------------------------------------------------------------- aGIFTedTroll · 2021-05-14 22:21 About this blurb on [NetBSD's page](https://www.netbsd.org/docs/kernel/non-exec.html) (for i386), "stack is not executable and everything else is"... that's basically the same as OpenBSD and PaX on Linux, right? Which to my understanding is as secure as hardware NX, right? I'm no expert by any means, but since they put that special note on the page it makes it sound like e.g. heap corruption could still be an issue (relatedly, I know JIT software (web browsers) has an issue with NX/W\^X in general, but am only concerned with issues that might exist on i386 that wouldn't on x86-64). I also assume all these implementations are similar to PaX Pageexec and don't bother with the lower overhead Segmexec (mirroring/splitting the address space in half), too, or might that be possible on a BSD if one cared about the 1-5% performance? ---------------------------------------------------------------------- shawn_webb · 2021-05-14 22:50 Ah, good catch. I misread your original post. It's not really possible to properly apply exploit mitigations like ASLR and W^X on 32-bit Intel. With ASLR, the address space is too limited to introduce enough entropy. And the lack of true memory protection limits makes W^X largely ineffective. ---------------------------------------------------------------------- aGIFTedTroll · 2021-05-15 02:43 >I misread your original post. It's not really possible to properly apply exploit mitigations like ASLR and W\^X on 32-bit Intel. I'm pretty sure you did read it right (but maybe missed the one detail in the OP I pointed out in my comment). ASLR is pretty limited on 32-bit, but should provide enough protection that a hostile process will \*probably\* pick a bad address and get terminated. For my use case (desktop with very few daemons (x,dhclient,cron,syslog...)), that's more than good enough as 99% of stuff won't be internet facing and no daemons will be auto-restarting for an attacker to repeatedly try again, just don't want an IRC client (which are usually written in C) or something to be a pwn vector. And some i386 NX software implementations do appear to have per-4k-page granularity (see [this OpenBSD mailing list post](https://marc.info/?l=openbsd-misc&m=105056000801065) in the OP), but it depends on the implementation... that's why I'm asking how they all compare to hardware NX =) I am aware 20 year old\*\* hardware is ancient, of course, but except for the modern web and HD video, things are snappier than you'd expect. \*\*Unless you bought a 32-bit netbook 8 or more years ago (old but not ancient yet). ---------------------------------------------------------------------- Kernigh · 2021-05-21 02:43 The old 32-bit PowerPC misses this feature, but the 64-bit PowerPC or Power ISA has the N bit (no execute) for each page of memory. These 64-bit systems include the old Mac G5, and the new POWER9 boards from Raptor Computing Systems. If you boot BSD (either 32-bit or 64-bit) on a G5, it should use the G5's N bit. The old 32-bit PowerPC has 2 ways to limit execution: * Block Address Translation (BAT). It can map 4 blocks of executable instructions (IBAT0 to IBAT3) and 4 blocks of data. The blocks are too big for user processes, but OpenBSD uses them in the kernel. The only executable block is [IBAT0, of size 8M or 16M](https://github.com/open bsd/src/blob/ff00584bbe2c4f832fd8a5b15c3e8e861b836c91/sys/arch/powerpc /powerpc/pmap.c#L1636). * Segments. There is a NOEXEC bit for each 256M segment of pages. If any page in a segment is executable, then its entire segment must be executable. For a user process, it would be good to map its stack and its malloc(3)s in a no-execute segment. ---------------------------------------------------------------------- photons_are_scary · 2021-05-21 03:17 yes - however, NetBSD has no support for 64 bit PowerPC yet, and while it can run on the PowerMac G5 it can only do so in 32 bit mode and cannot make full use of the processor. (i have a Raptor Computing Blackbird donated to me by an open source developer and was intending to work on this 64 bit PowerPC/POWER9 support in NetBSD myself, but the board was damaged in shipping and i have yet to fully repair it even with the assistance of Raptor)