Skip to content

Commit 9d59067

Browse files
committed
Merge tag 'selinux-pr-20240814' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux fixes from Paul Moore: - Fix a xperms counting problem where we adding to the xperms count even if we failed to add the xperm. - Propogate errors from avc_add_xperms_decision() back to the caller so that we can trigger the proper cleanup and error handling. - Revert our use of vma_is_initial_heap() in favor of our older logic as vma_is_initial_heap() doesn't correctly handle the no-heap case and it is causing issues with the SELinux process/execheap access control. While the older SELinux logic may not be perfect, it restores the expected user visible behavior. Hopefully we will be able to resolve the problem with the vma_is_initial_heap() macro with the mm folks, but we need to fix this in the meantime. * tag 'selinux-pr-20240814' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: revert our use of vma_is_initial_heap() selinux: add the processing of the failure of avc_add_xperms_decision() selinux: fix potential counting error in avc_add_xperms_decision()
2 parents 4ac0f08 + 05a3d6e commit 9d59067

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

security/selinux/avc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ static int avc_add_xperms_decision(struct avc_node *node,
330330
{
331331
struct avc_xperms_decision_node *dest_xpd;
332332

333-
node->ae.xp_node->xp.len++;
334333
dest_xpd = avc_xperms_decision_alloc(src->used);
335334
if (!dest_xpd)
336335
return -ENOMEM;
337336
avc_copy_xperms_decision(&dest_xpd->xpd, src);
338337
list_add(&dest_xpd->xpd_list, &node->ae.xp_node->xpd_head);
338+
node->ae.xp_node->xp.len++;
339339
return 0;
340340
}
341341

@@ -907,7 +907,11 @@ static int avc_update_node(u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
907907
node->ae.avd.auditdeny &= ~perms;
908908
break;
909909
case AVC_CALLBACK_ADD_XPERMS:
910-
avc_add_xperms_decision(node, xpd);
910+
rc = avc_add_xperms_decision(node, xpd);
911+
if (rc) {
912+
avc_node_kill(node);
913+
goto out_unlock;
914+
}
911915
break;
912916
}
913917
avc_node_replace(node, orig);

security/selinux/hooks.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3852,7 +3852,17 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
38523852
if (default_noexec &&
38533853
(prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
38543854
int rc = 0;
3855-
if (vma_is_initial_heap(vma)) {
3855+
/*
3856+
* We don't use the vma_is_initial_heap() helper as it has
3857+
* a history of problems and is currently broken on systems
3858+
* where there is no heap, e.g. brk == start_brk. Before
3859+
* replacing the conditional below with vma_is_initial_heap(),
3860+
* or something similar, please ensure that the logic is the
3861+
* same as what we have below or you have tested every possible
3862+
* corner case you can think to test.
3863+
*/
3864+
if (vma->vm_start >= vma->vm_mm->start_brk &&
3865+
vma->vm_end <= vma->vm_mm->brk) {
38563866
rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
38573867
PROCESS__EXECHEAP, NULL);
38583868
} else if (!vma->vm_file && (vma_is_initial_stack(vma) ||

0 commit comments

Comments
 (0)