git: b9c10eeb380b - main - sound: Improve hw.snd.compat_linux_mmap
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 15 May 2026 15:08:51 UTC
The branch main has been updated by christos:
URL: https://cgit.FreeBSD.org/src/commit/?id=b9c10eeb380b3ba629421062af8658e79a9171cd
commit b9c10eeb380b3ba629421062af8658e79a9171cd
Author: Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-05-15 14:07:59 +0000
Commit: Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-05-15 15:08:11 +0000
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
---
share/man/man4/pcm.4 | 26 +++++++++++++++++---------
sys/dev/sound/pcm/dsp.c | 13 +++++--------
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/share/man/man4/pcm.4 b/share/man/man4/pcm.4
index 518c37b54f1d..8a92cefa3549 100644
--- a/share/man/man4/pcm.4
+++ b/share/man/man4/pcm.4
@@ -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.
diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index 7bc1decc283b..d9726ffdd6bb 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -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;
+#ifdef SV_ABI_LINUX
/*
- * 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
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);