1- From 3caad90ec607313a1c05a6c33c0414094998ccdc Mon Sep 17 00:00:00 2001
1+ From fdae5c3fa77e6d74c112c3aa2804a2cd2decbe0a Mon Sep 17 00:00:00 2001
22From: Piyush Jena <jepiyush@amazon.com>
33Date: Mon, 13 Jul 2026 23:23:32 +0000
44Subject: [PATCH] Revert "selinux: fix overlayfs mmap() and mprotect() access
55 checks"
66
77This reverts commit 8bacd09f12c27710228562e4d13163e58c5f4a45.
88---
9- security/selinux/hooks.c | 242 ++++++++----------------------
9+ security/selinux/hooks.c | 248 ++++++++----------------------
1010 security/selinux/include/objsec.h | 11 --
11- 2 files changed, 64 insertions(+), 189 deletions(-)
11+ 2 files changed, 64 insertions(+), 195 deletions(-)
1212
1313diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
14- index 1b89c8d5f..8e31d3b60 100644
14+ index 23d680d..8e31d3b 100644
1515--- a/security/selinux/hooks.c
1616+++ b/security/selinux/hooks.c
1717@@ -1724,72 +1724,49 @@ static inline int file_path_has_perm(const struct cred *cred,
@@ -92,11 +92,11 @@ index 1b89c8d5f..8e31d3b60 100644
9292+ rc = 0;
9393 if (av)
9494- return inode_has_perm(cred, inode, av, &ad);
95- -
96- - return 0;
97- - }
9895+ rc = inode_has_perm(cred, inode, av, &ad);
9996
97+ - return 0;
98+ - }
99+ -
100100- /* Check whether a task can use an open file descriptor to
101101- access an inode in a given way. Check access to the
102102- descriptor itself, and then use dentry_has_perm to
@@ -132,13 +132,13 @@ index 1b89c8d5f..8e31d3b60 100644
132132 /*
133133 * Check whether a task has the ioctl permission and cmd
134134 * operation to an inode.
135- @@ -3804,55 +3770,42 @@ static int selinux_file_ioctl_compat(struct file *file, unsigned int cmd,
135+ @@ -3804,57 +3770,42 @@ static int selinux_file_ioctl_compat(struct file *file, unsigned int cmd,
136136
137137 static int default_noexec __ro_after_init;
138138
139- - static int __file_map_prot_check(const struct cred *cred ,
140- - const struct file *file, unsigned long prot ,
141- - bool shared, bool bf_user_file)
139+ - static int __file_map_prot_check(const struct file *file, unsigned long prot ,
140+ - bool shared, bool mounter_check ,
141+ - bool bf_user_file)
142142+ static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
143143 {
144144- struct inode *inode = NULL;
@@ -152,10 +152,10 @@ index 1b89c8d5f..8e31d3b60 100644
152152- inode = file_inode(file);
153153- }
154154-
155- - if (default_noexec && prot_exec &&
155+ - if (!mounter_check && default_noexec && prot_exec &&
156156- (!file || IS_PRIVATE(inode) || (!shared && prot_write))) {
157157- int rc;
158- - u32 sid = cred_sid(cred );
158+ - u32 sid = current_sid( );
159159+ const struct cred *cred = current_cred();
160160+ u32 sid = cred_sid(cred);
161161+ int rc = 0;
@@ -180,6 +180,8 @@ index 1b89c8d5f..8e31d3b60 100644
180180 }
181181
182182 if (file) {
183+ - const struct cred *cred = mounter_check ?
184+ - file->f_cred : current_cred();
183185- /* "read" always possible, "write" only if shared */
184186+ /* read access is always possible with a mapping */
185187 u32 av = FILE__READ;
@@ -200,29 +202,31 @@ index 1b89c8d5f..8e31d3b60 100644
200202- return 0;
201203- }
202204-
203- - static inline int file_map_prot_check(const struct cred *cred ,
204- - const struct file *file ,
205- - unsigned long prot, bool shared )
205+ - static inline int file_map_prot_check(const struct file *file ,
206+ - unsigned long prot, bool shared ,
207+ - bool mounter_check )
206208- {
207- - return __file_map_prot_check(cred, file, prot, shared, false);
209+ - return __file_map_prot_check(file, prot, shared, mounter_check , false);
208210+ error:
209211+ return rc;
210212 }
211213
212214 static int selinux_mmap_addr(unsigned long addr)
213- @@ -3868,80 +3821,36 @@ static int selinux_mmap_addr(unsigned long addr)
215+ @@ -3870,84 +3821,36 @@ static int selinux_mmap_addr(unsigned long addr)
214216 return rc;
215217 }
216218
217- - static int selinux_mmap_file_common(const struct cred *cred, struct file *file ,
218- - unsigned long prot , bool shared )
219+ - static int selinux_mmap_file_common(struct file *file, unsigned long prot ,
220+ - bool shared , bool mounter_check )
219221+ static int selinux_mmap_file(struct file *file,
220222+ unsigned long reqprot __always_unused,
221223+ unsigned long prot, unsigned long flags)
222224 {
223225- if (file) {
224226- int rc;
225227- struct common_audit_data ad;
228+ - const struct cred *cred = mounter_check ?
229+ - file->f_cred : current_cred();
226230+ struct common_audit_data ad;
227231+ int rc;
228232
@@ -236,15 +240,16 @@ index 1b89c8d5f..8e31d3b60 100644
236240 return rc;
237241 }
238242
239- - return file_map_prot_check(cred, file, prot, shared);
243+ - return file_map_prot_check(file, prot, shared, mounter_check );
240244- }
241245-
242246- static int selinux_mmap_file(struct file *file,
243247- unsigned long reqprot __always_unused,
244248- unsigned long prot, unsigned long flags)
245249- {
246- - return selinux_mmap_file_common(current_cred(), file, prot,
247- - (flags & MAP_TYPE) == MAP_SHARED);
250+ - return selinux_mmap_file_common(file, prot,
251+ - (flags & MAP_TYPE) == MAP_SHARED,
252+ - false);
248253- }
249254-
250255- /**
@@ -276,8 +281,9 @@ index 1b89c8d5f..8e31d3b60 100644
276281- if (vma->vm_flags & VM_EXEC)
277282- prot |= PROT_EXEC;
278283-
279- - return selinux_mmap_file_common(backing_file->f_cred, backing_file,
280- - prot, vma->vm_flags & VM_SHARED);
284+ - return selinux_mmap_file_common(backing_file, prot,
285+ - vma->vm_flags & VM_SHARED,
286+ - true);
281287+ return file_map_prot_check(file, prot,
282288+ (flags & MAP_TYPE) == MAP_SHARED);
283289 }
@@ -302,7 +308,7 @@ index 1b89c8d5f..8e31d3b60 100644
302308 /*
303309 * We don't use the vma_is_initial_heap() helper as it has
304310 * a history of problems and is currently broken on systems
305- @@ -3955 ,15 +3864,11 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
311+ @@ -3961 ,15 +3864,11 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
306312 vma->vm_end <= vma->vm_mm->brk) {
307313 rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
308314 PROCESS__EXECHEAP, NULL);
@@ -320,7 +326,7 @@ index 1b89c8d5f..8e31d3b60 100644
320326 /*
321327 * We are making executable a file mapping that has
322328 * had some COW done. Since pages might have been
323- @@ -3971 ,29 +3876,13 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
329+ @@ -3977 ,29 +3876,13 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
324330 * modified content. This typically should only
325331 * occur for text relocations.
326332 */
@@ -338,11 +344,11 @@ index 1b89c8d5f..8e31d3b60 100644
338344 }
339345- }
340346-
341- - rc = __file_map_prot_check(cred, file, prot, shared, backing_file);
347+ - rc = __file_map_prot_check(file, prot, shared, false , backing_file);
342348- if (rc)
343349- return rc;
344350- if (backing_file) {
345- - rc = file_map_prot_check(file->f_cred, file, prot, shared);
351+ - rc = file_map_prot_check(file, prot, shared, true );
346352 if (rc)
347353 return rc;
348354 }
@@ -352,15 +358,15 @@ index 1b89c8d5f..8e31d3b60 100644
352358 }
353359
354360 static int selinux_file_lock(struct file *file, unsigned int cmd)
355- @@ -7071 ,7 +6960,6 @@ static void selinux_bpf_token_free(struct bpf_token *token)
361+ @@ -7077 ,7 +6960,6 @@ static void selinux_bpf_token_free(struct bpf_token *token)
356362 struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
357363 .lbs_cred = sizeof(struct task_security_struct),
358364 .lbs_file = sizeof(struct file_security_struct),
359365- .lbs_backing_file = sizeof(struct backing_file_security_struct),
360366 .lbs_inode = sizeof(struct inode_security_struct),
361367 .lbs_ipc = sizeof(struct ipc_security_struct),
362368 .lbs_key = sizeof(struct key_security_struct),
363- @@ -7277 ,11 +7165,9 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
369+ @@ -7283 ,11 +7165,9 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
364370
365371 LSM_HOOK_INIT(file_permission, selinux_file_permission),
366372 LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security),
@@ -373,7 +379,7 @@ index 1b89c8d5f..8e31d3b60 100644
373379 LSM_HOOK_INIT(file_mprotect, selinux_file_mprotect),
374380 LSM_HOOK_INIT(file_lock, selinux_file_lock),
375381diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h
376- index dc42282a2..c88cae81e 100644
382+ index dc42282..c88cae8 100644
377383--- a/security/selinux/include/objsec.h
378384+++ b/security/selinux/include/objsec.h
379385@@ -61,10 +61,6 @@ struct file_security_struct {
@@ -401,6 +407,6 @@ index dc42282a2..c88cae81e 100644
401407 static inline struct inode_security_struct *
402408 selinux_inode(const struct inode *inode)
403409 {
404- - -
410+ - -
4054112.53.0
406412
0 commit comments