sound: Improve hw.snd.compat_linux_mmap

- Reject PROT_EXEC in all cases when Linux support is not compiled in.
- Define sysctl only when Linux support is compiled in.
- Document better.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	emaste
Pull Request:	https://ron-dev.freebsd.org/FreeBSD/src/pulls/29
This commit is contained in:
Christos Margiolis
2026-05-15 16:07:59 +02:00
parent 776584319f
commit b9c10eeb38
2 changed files with 24 additions and 19 deletions
+17 -9
View File
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 15, 2025
.Dd May 15, 2026
.Dt SOUND 4
.Os
.Sh NAME
@@ -254,21 +254,29 @@ are global settings and
are device specific.
.Bl -tag -width indent
.It Va hw.snd.compat_linux_mmap
Linux
This
.Xr sysctl 8
variable is available only when Linux application support is compiled into the
kernel, and affects Linux binaries only.
It is a hack to get around the fact that, for i386 emulation,
.Xr linux 4
historically set PROT_EXEC automatically when PROT_READ or PROT_WRITE was set
during an
.Xr mmap 2
compatibility.
call, which
.Fx
does not.
.Pp
The following values are supported (default is 0):
.Bl -tag -width 2n
.It -1
Force disabling/denying PROT_EXEC
Force-disable PROT_EXEC
.Xr mmap 2
requests.
requests, even for Linux applications.
.It 0
Auto detect proc/ABI type, allow
Allow PROT_EXEC
.Xr mmap 2
for Linux applications, and deny for everything else.
.It 1
Always allow PROT_EXEC page mappings.
requests for Linux applications only.
.El
.It Va hw.snd.default_auto
Automatically assign the default sound unit.
+7 -10
View File
@@ -54,10 +54,12 @@ struct dsp_cdevpriv {
struct pcm_channel *wrch;
};
#ifdef SV_ABI_LINUX
static int dsp_mmap_allow_prot_exec = 0;
SYSCTL_INT(_hw_snd, OID_AUTO, compat_linux_mmap, CTLFLAG_RWTUN,
&dsp_mmap_allow_prot_exec, 0,
"linux mmap compatibility (-1=force disable 0=auto 1=force enable)");
"linux mmap compatibility (-1=force-disable 0=auto)");
#endif
static int dsp_basename_clone = 1;
SYSCTL_INT(_hw_snd, OID_AUTO, basename_clone, CTLFLAG_RWTUN,
@@ -1923,20 +1925,15 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offset,
struct pcm_channel *wrch, *rdch, *c;
int err;
/*
* Reject PROT_EXEC by default. It just doesn't makes sense.
* Unfortunately, we have to give up this one due to linux_mmap
* changes.
*
* https://lists.freebsd.org/pipermail/freebsd-emulation/2007-June/003698.html
*
*/
#ifdef SV_ABI_LINUX
/*
* https://lists.freebsd.org/pipermail/freebsd-emulation/2007-June/003698.html
*/
if ((nprot & PROT_EXEC) && (dsp_mmap_allow_prot_exec < 0 ||
(dsp_mmap_allow_prot_exec == 0 &&
SV_CURPROC_ABI() != SV_ABI_LINUX)))
#else
if ((nprot & PROT_EXEC) && dsp_mmap_allow_prot_exec < 1)
if (nprot & PROT_EXEC)
#endif
return (EINVAL);