summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/lsm.c
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2020-08-31 22:16:51 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2020-08-31 23:03:57 +0200
commitf56407fa6e69499a06bf1e0543fa93be6922acba (patch)
tree4bee8de2bdfd2f3caa3c4499c54b9196129c6525 /tools/testing/selftests/bpf/progs/lsm.c
parentsamples/bpf: Fix to xdpsock to avoid recycling frames (diff)
downloadlinux-f56407fa6e69499a06bf1e0543fa93be6922acba.tar.xz
linux-f56407fa6e69499a06bf1e0543fa93be6922acba.zip
bpf: Remove bpf_lsm_file_mprotect from sleepable list.
Technically the bpf programs can sleep while attached to bpf_lsm_file_mprotect, but such programs need to access user memory. So they're in might_fault() category. Which means they cannot be called from file_mprotect lsm hook that takes write lock on mm->mmap_lock. Adjust the test accordingly. Also add might_fault() to __bpf_prog_enter_sleepable() to catch such deadlocks early. Fixes: 1e6c62a88215 ("bpf: Introduce sleepable BPF programs") Fixes: e68a144547fc ("selftests/bpf: Add sleepable tests") Reported-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20200831201651.82447-1-alexei.starovoitov@gmail.com
Diffstat (limited to '')
-rw-r--r--tools/testing/selftests/bpf/progs/lsm.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/tools/testing/selftests/bpf/progs/lsm.c b/tools/testing/selftests/bpf/progs/lsm.c
index 49fa6ca99755..ff4d343b94b5 100644
--- a/tools/testing/selftests/bpf/progs/lsm.c
+++ b/tools/testing/selftests/bpf/progs/lsm.c
@@ -36,14 +36,10 @@ int monitored_pid = 0;
int mprotect_count = 0;
int bprm_count = 0;
-SEC("lsm.s/file_mprotect")
+SEC("lsm/file_mprotect")
int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
unsigned long reqprot, unsigned long prot, int ret)
{
- char args[64];
- __u32 key = 0;
- __u64 *value;
-
if (ret != 0)
return ret;
@@ -53,18 +49,6 @@ int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
is_stack = (vma->vm_start <= vma->vm_mm->start_stack &&
vma->vm_end >= vma->vm_mm->start_stack);
- bpf_copy_from_user(args, sizeof(args), (void *)vma->vm_mm->arg_start);
-
- value = bpf_map_lookup_elem(&array, &key);
- if (value)
- *value = 0;
- value = bpf_map_lookup_elem(&hash, &key);
- if (value)
- *value = 0;
- value = bpf_map_lookup_elem(&lru_hash, &key);
- if (value)
- *value = 0;
-
if (is_stack && monitored_pid == pid) {
mprotect_count++;
ret = -EPERM;
@@ -77,10 +61,26 @@ SEC("lsm.s/bprm_committed_creds")
int BPF_PROG(test_void_hook, struct linux_binprm *bprm)
{
__u32 pid = bpf_get_current_pid_tgid() >> 32;
+ char args[64];
+ __u32 key = 0;
+ __u64 *value;
if (monitored_pid == pid)
bprm_count++;
+ bpf_copy_from_user(args, sizeof(args), (void *)bprm->vma->vm_mm->arg_start);
+ bpf_copy_from_user(args, sizeof(args), (void *)bprm->mm->arg_start);
+
+ value = bpf_map_lookup_elem(&array, &key);
+ if (value)
+ *value = 0;
+ value = bpf_map_lookup_elem(&hash, &key);
+ if (value)
+ *value = 0;
+ value = bpf_map_lookup_elem(&lru_hash, &key);
+ if (value)
+ *value = 0;
+
return 0;
}
SEC("lsm/task_free") /* lsm/ is ok, lsm.s/ fails */