git: 730eaf466493 - main - sound tests: Add PROT_EXEC rejection test

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Sat, 20 Jun 2026 19:05:36 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=730eaf466493315c1d1164eb6b59b14766f49322

commit 730eaf466493315c1d1164eb6b59b14766f49322
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-06-12 06:20:26 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-06-20 19:04:50 +0000

    sound tests: Add PROT_EXEC rejection test
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    markj, kib
    Pull-Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/30
---
 tests/sys/sound/mmap.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/sys/sound/mmap.c b/tests/sys/sound/mmap.c
index b44b16e7f312..e83193db9bc1 100644
--- a/tests/sys/sound/mmap.c
+++ b/tests/sys/sound/mmap.c
@@ -102,10 +102,38 @@ ATF_TC_BODY(mmap_buffer_lifetime, tc)
 	ATF_REQUIRE(munmap(buf, len) == 0);
 }
 
+ATF_TC(mmap_reject_prot_exec);
+ATF_TC_HEAD(mmap_reject_prot_exec, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "mmap PROT_EXEC rejection test");
+	atf_tc_set_md_var(tc, "require.kmods", "snd_dummy");
+}
+
+ATF_TC_BODY(mmap_reject_prot_exec, tc)
+{
+	uint8_t *buf;
+	size_t len;
+	int fd;
+
+	fd = open("/dev/dsp.dummy", O_RDWR);
+	ATF_REQUIRE_MSG(fd >= 0, FMT_ERR("open"));
+
+	len = 8;
+
+	buf = mmap(NULL, len, PROT_READ | PROT_EXEC | PROT_EXEC, MAP_SHARED,
+	    fd, 0);
+	ATF_REQUIRE_MSG(buf == MAP_FAILED, FMT_ERR("mmap"));
+
+	munmap(buf, len);
+
+	close(fd);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, mmap_offset_overflow);
 	ATF_TP_ADD_TC(tp, mmap_buffer_lifetime);
+	ATF_TP_ADD_TC(tp, mmap_reject_prot_exec);
 
 	return (atf_no_error());
 }