aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
author6t8k <6t8k@noreply.codeberg.org>2023-10-05 10:22:44 +0000
committer6t8k <6t8k@noreply.codeberg.org>2023-10-05 10:33:05 +0000
commit61eb56dfda605427156b52d019be4bf5ce84c3aa (patch)
tree6eed5a0fadc6cc8de3582110072c2e298cf5e9bf /shm.c
parentterm_reset: log hard vs. soft reset (diff)
shm: if defined, set MFD_NOEXEC_SEAL flag for memfd_create
Effective from Linux 6.3.0 onward, this creates the memfd without execute permissions and prevents that setting from ever being changed. This is a defense-in-depth security measure and prevents a respective kernel warning from being emitted. See https://lwn.net/Articles/918106/ for more information.
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/shm.c b/shm.c
index 123adaf3..d543e1f4 100644
--- a/shm.c
+++ b/shm.c
@@ -330,8 +330,13 @@ get_new_buffers(struct buffer_chain *chain, size_t count,
struct buffer_pool *pool = NULL;
/* Backing memory for SHM */
+#if defined(MFD_NOEXEC_SEAL)
+ #define FOOT_MFD_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC_SEAL)
+#else
+ #define FOOT_MFD_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING)
+#endif
#if defined(MEMFD_CREATE)
- pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING);
+ pool_fd = memfd_create("foot-wayland-shm-buffer-pool", FOOT_MFD_FLAGS);
#elif defined(__FreeBSD__)
// memfd_create on FreeBSD 13 is SHM_ANON without sealing support
pool_fd = shm_open(SHM_ANON, O_RDWR | O_CLOEXEC, 0600);