summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/lsm.c
diff options
context:
space:
mode:
authorKP Singh <kpsingh@google.com>2020-04-02 22:07:51 +0200
committerAlexei Starovoitov <ast@kernel.org>2020-04-02 19:42:52 -0700
commit5222d69642a09261222fb9703761a029db16cadf (patch)
tree79a2b386c0cc2f1dbbcd1e186f5b38ecb6947447 /tools/testing/selftests/bpf/progs/lsm.c
parent7a1ca97269ee197ea967de2c9412d8e7e2274ee6 (diff)
downloadlinux-stable-5222d69642a09261222fb9703761a029db16cadf.tar.gz
linux-stable-5222d69642a09261222fb9703761a029db16cadf.tar.bz2
linux-stable-5222d69642a09261222fb9703761a029db16cadf.zip
bpf, lsm: Fix the file_mprotect LSM test.
The test was previously using an mprotect on the heap memory allocated using malloc and was expecting the allocation to be always using sbrk(2). This is, however, not always true and in certain conditions malloc may end up using anonymous mmaps for heap alloctions. This means that the following condition that is used in the "lsm/file_mprotect" program is not sufficent to detect all mprotect calls done on heap memory: is_heap = (vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk); The test is updated to use an mprotect on memory allocated on the stack. While this would result in the splitting of the vma, this happens only after the security_file_mprotect hook. So, the condition used in the BPF program holds true. Fixes: 03e54f100d57 ("bpf: lsm: Add selftests for BPF_PROG_TYPE_LSM") Reported-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: KP Singh <kpsingh@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200402200751.26372-1-kpsingh@chromium.org
Diffstat (limited to 'tools/testing/selftests/bpf/progs/lsm.c')
-rw-r--r--tools/testing/selftests/bpf/progs/lsm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/testing/selftests/bpf/progs/lsm.c b/tools/testing/selftests/bpf/progs/lsm.c
index a4e3c223028d..b4598d4bc4f7 100644
--- a/tools/testing/selftests/bpf/progs/lsm.c
+++ b/tools/testing/selftests/bpf/progs/lsm.c
@@ -23,12 +23,12 @@ int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
return ret;
__u32 pid = bpf_get_current_pid_tgid() >> 32;
- int is_heap = 0;
+ int is_stack = 0;
- is_heap = (vma->vm_start >= vma->vm_mm->start_brk &&
- vma->vm_end <= vma->vm_mm->brk);
+ is_stack = (vma->vm_start <= vma->vm_mm->start_stack &&
+ vma->vm_end >= vma->vm_mm->start_stack);
- if (is_heap && monitored_pid == pid) {
+ if (is_stack && monitored_pid == pid) {
mprotect_count++;
ret = -EPERM;
}