Skip to contentSkip to conversation

selinux: check MAP_SHARED_VALIDATE mappings as shared

PATCH In review Stephen Smalley 3 participants 3 messages Nov 6 – Nov 9 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 selinux: check MAP_SHARED_VALIDATE mappings as shared

selinux_mmap_file() only recognizes MAP_SHARED as a shared mapping, but MAP_SHARED_VALIDATE is also a shared mapping type. The mmap flags reach this hook before the mm code processes the mapping type.

Consequently, a writable MAP_SHARED_VALIDATE mapping was failing to check the file write permission at mmap time, and a writable executable file mapping was wrongly checking process execmem permission as if it were private.

Fixes 1c9725974074 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
---
 security/selinux/hooks.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
security/selinux/hooks.c +4 -1
index 6168dd5f91c2..ce92632e7db6 100644
@@ -4180,8 +4180,11 @@ static int selinux_mmap_file(struct file *file,
 			     unsigned long reqprot __always_unused,
 			     unsigned long prot, unsigned long flags)
 {
+	const unsigned long map_type = (flags & MAP_TYPE);
+
 	return selinux_mmap_file_common(file, prot,
-					(flags & MAP_TYPE) == MAP_SHARED,
+					(map_type == MAP_SHARED ||
+					 map_type == MAP_SHARED_VALIDATE),
 					false);
 }
 
Signature · 1 line
2.56.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

selinux_mmap_file() only recognizes MAP_SHARED as a shared mapping, but MAP_SHARED_VALIDATE is also a shared mapping type. The mmap flags reach this hook before the mm code processes the mapping type.

Quoted 8 lines

Consequently, a writable MAP_SHARED_VALIDATE mapping was failing to check the file write permission at mmap time, and a writable executable file mapping was wrongly checking process execmem permission as if it were private.

Fixes 1c9725974074 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Stephen Smalley
Quoted 10 lines · On Nov 6, 2026 [email protected] wrote:

selinux_mmap_file() only recognizes MAP_SHARED as a shared mapping, but MAP_SHARED_VALIDATE is also a shared mapping type. The mmap flags reach this hook before the mm code processes the mapping type.

Consequently, a writable MAP_SHARED_VALIDATE mapping was failing to check the file write permission at mmap time, and a writable executable file mapping was wrongly checking process execmem permission as if it were private.

Quoted 6 lines
Fixes 1c9725974074 ("mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap flags")
---
 security/selinux/hooks.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Looks good, thanks Stephen. Merging into selinux/stable-7.4.

--
paul-moore.com