サードパーティ/開発者のコードのバグ検出におけるSELinuxのユーティリティを示すために、メモリ保護テストがあります(最初のコード例を変更します):
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
int main (void) {
// open file read-write, get a memory-mapped pointer with private access, write permission
int fd = open ("file_to_test", O_RDWR);
char *p = mmap (NULL, 42, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
p[0] = 'a'; // put something
// Update protection mode; SELinux response depends on sebool: allow_execmod
int r = mprotect (p, 42, PROT_READ | PROT_EXEC);
// Display mprotect result
printf ("mprotect = %d\n", r);
close(fd);
return 0;
}
デフォルトをコンパイルして表示する(キャッチされない)
$ echo "test data" > file_to_test
$ gcc execmod.c
$ ./a.out
mprotect = 0
$ sudo aureport -a
AVC Report
========================================================
# date time comm subj syscall class permission obj event
========================================================
<no events of interest were found>
ブール値を変更して問題をキャッチします。
$ sudo getsebool allow_execmod
allow_execmod --> on
$ sudo setsebool allow_execmod 0
$ ./a.out
mprotect = -1
$ sudo aureport -a
AVC Report
========================================================
# date time comm subj syscall class permission obj event
========================================================
1. 04/30/2015 12:26:41 a.out unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 10 file execmod unconfined_u:object_r:user_home_t:s0 denied 3612