<?xml version="1.0"?>
<!DOCTYPE webpage
  PUBLIC "-//NetBSD//DTD Website-based NetBSD Extension//EN"
         "http://www.NetBSD.org/XML/htdocs/lang/share/xml/website-netbsd.dtd" [
]>

<webpage id="docs-kernel-non-exec">
<config param="desc" value="Non-executable stack and heap"/>
<config param="cvstag" value="$NetBSD: non-exec.xml,v 1.2 2008/01/10 05:52:25 jnemeth Exp $"/>
<config param="rcsdate" value="$Date: 2008/01/10 05:52:25 $"/>
<head>
<title>Non-executable stack and heap</title>
</head>

<sect1 id="top">

<para>
Starting with version 2.0, NetBSD supports non-executable mappings on
platforms where the hardware allows it. Process stack and heap mappings are
non-executable by default. This makes exploiting potential buffer overflows
harder. NetBSD supports PROT_EXEC permission via mmap() for all platforms
where the hardware differentiates execute access from data access, though
not necessarily with single-page granularity. When the hardware has a
larger granularity, the rule is that if any page in the larger unit is
executable, then the entire larger unit is executable, otherwise the entire
larger unit is not executable.
</para>

<para>
No compile-time option is needed to enable this software support,
it's always available. 
</para>

<sect2 id="supported-platforms">
<title>Supported platforms</title>

<para>
Here is a list of support levels based on hardware
limitations. In this list "the stack" refers to the traditional UNIX
process stack, not pthreads stacks.
</para>

<itemizedlist>
<listitem>
<emphasis role="bold">amd64, sparc64, sparc (sun4m, sun4d), powerpc (ibm4xx), 
alpha, hppa:</emphasis>
Full support, each page is independently executable or not.
</listitem>
<listitem>
<emphasis role="bold">powerpc (eg. macppc):</emphasis>
The hardware granularity is a segment (256MB) instead of a page.
By default, the segment containing the stack is not executable.
</listitem>
<listitem>
<emphasis role="bold">i386:</emphasis>
The hardware support is pretty limited, so the granularity is very coarse.
The current software implementation in NetBSD is that there are only two
regions of the application address space which may be independently
executable or not: the stack and everything else.  By default,
the stack is not executable and everything else is executable
</listitem>
<listitem>
<emphasis role="bold">Everything else; arm, m68k, mips, sh3, 
sparc(sun, sun4c), vax:</emphasis>
No support, the hardware does not differentiate execute vs. data accesses,
so anything readable to a process as data is executable by the process
as code.
</listitem>
</itemizedlist>

</sect2>
</sect1>

</webpage>
