Skip to content

Commit fcaaade

Browse files
stephensmalleyxjamesmorris
authored andcommitted
selinux: generalize disabling of execmem for plt-in-heap archs
On Tue, 2010-04-27 at 11:47 -0700, David Miller wrote: > From: "Tom \"spot\" Callaway" <tcallawa@redhat.com> > Date: Tue, 27 Apr 2010 14:20:21 -0400 > > > [root@apollo ~]$ cat /proc/2174/maps > > 00010000-00014000 r-xp 00000000 fd:00 15466577 > > /sbin/mingetty > > 00022000-00024000 rwxp 00002000 fd:00 15466577 > > /sbin/mingetty > > 00024000-00046000 rwxp 00000000 00:00 0 > > [heap] > > SELINUX probably barfs on the executable heap, the PLT is in the HEAP > just like powerpc32 and that's why VM_DATA_DEFAULT_FLAGS has to set > both executable and writable. > > You also can't remove the CONFIG_PPC32 ifdefs in selinux, since > because of the VM_DATA_DEFAULT_FLAGS setting used still in that arch, > the heap will always have executable permission, just like sparc does. > You have to support those binaries forever, whether you like it or not. > > Let's just replace the CONFIG_PPC32 ifdef in SELINUX with CONFIG_PPC32 > || CONFIG_SPARC as in Tom's original patch and let's be done with > this. > > In fact I would go through all the arch/ header files and check the > VM_DATA_DEFAULT_FLAGS settings and add the necessary new ifdefs to the > SELINUX code so that other platforms don't have the pain of having to > go through this process too. To avoid maintaining per-arch ifdefs, it seems that we could just directly use (VM_DATA_DEFAULT_FLAGS & VM_EXEC) as the basis for deciding whether to enable or disable these checks. VM_DATA_DEFAULT_FLAGS isn't constant on some architectures but instead depends on current->personality, but we want this applied uniformly. So we'll just use the initial task state to determine whether or not to enable these checks. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: James Morris <jmorris@namei.org>
1 parent cb84aa9 commit fcaaade

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,13 +2999,15 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd,
29992999
return file_has_perm(cred, file, av);
30003000
}
30013001

3002+
static int default_noexec;
3003+
30023004
static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
30033005
{
30043006
const struct cred *cred = current_cred();
30053007
int rc = 0;
30063008

3007-
#ifndef CONFIG_PPC32
3008-
if ((prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) {
3009+
if (default_noexec &&
3010+
(prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) {
30093011
/*
30103012
* We are making executable an anonymous mapping or a
30113013
* private file mapping that will also be writable.
@@ -3015,7 +3017,6 @@ static int file_map_prot_check(struct file *file, unsigned long prot, int shared
30153017
if (rc)
30163018
goto error;
30173019
}
3018-
#endif
30193020

30203021
if (file) {
30213022
/* read access is always possible with a mapping */
@@ -3076,8 +3077,8 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
30763077
if (selinux_checkreqprot)
30773078
prot = reqprot;
30783079

3079-
#ifndef CONFIG_PPC32
3080-
if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
3080+
if (default_noexec &&
3081+
(prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
30813082
int rc = 0;
30823083
if (vma->vm_start >= vma->vm_mm->start_brk &&
30833084
vma->vm_end <= vma->vm_mm->brk) {
@@ -3099,7 +3100,6 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
30993100
if (rc)
31003101
return rc;
31013102
}
3102-
#endif
31033103

31043104
return file_map_prot_check(vma->vm_file, prot, vma->vm_flags&VM_SHARED);
31053105
}
@@ -5662,6 +5662,8 @@ static __init int selinux_init(void)
56625662
/* Set the security state for the initial task. */
56635663
cred_init_security();
56645664

5665+
default_noexec = !(VM_DATA_DEFAULT_FLAGS & VM_EXEC);
5666+
56655667
sel_inode_cache = kmem_cache_create("selinux_inode_security",
56665668
sizeof(struct inode_security_struct),
56675669
0, SLAB_PANIC, NULL);

0 commit comments

Comments
 (0)