BACKPORT: 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
Change-Id: I2d055e892c87609fd96d3dde8e8dce81f63882f0
This commit is contained in:
Alexei Starovoitov 2020-08-31 13:16:51 -07:00 • committed by basamaryan
commit 0c276f22b8
No known key found for this signature in database
GPG key ID: 210D5384FB2A5885
2 changed files with 1 additions and 1 deletions

View file

@ -409,6 +409,7 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start)
void notrace __bpf_prog_enter_sleepable(void)
{
rcu_read_lock_trace();
might_fault();
}
void notrace __bpf_prog_exit_sleepable(void)

View file

@ -11204,7 +11204,6 @@ static int check_attach_modify_return(struct bpf_prog *prog, unsigned long addr)
/* non exhaustive list of sleepable bpf_lsm_*() functions */
BTF_SET_START(btf_sleepable_lsm_hooks)
#ifdef CONFIG_BPF_LSM
BTF_ID(func, bpf_lsm_file_mprotect)
BTF_ID(func, bpf_lsm_bprm_committed_creds)
#else
BTF_ID_UNUSED