Re: [PATCH bpf-next] bpf: Remove bpf_lsm_file_mprotect from sleepable list.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/31/20 10:16 PM, Alexei Starovoitov wrote:
From: Alexei Starovoitov <ast@xxxxxxxxxx>

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.

Reported-by: Yonghong Song <yhs@xxxxxx>
Fixes: 1e6c62a88215 ("bpf: Introduce sleepable BPF programs")
Fixes: e68a144547fc ("selftests/bpf: Add sleepable tests")
Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
---
  kernel/bpf/trampoline.c                 |  1 +
  kernel/bpf/verifier.c                   |  1 -
  tools/testing/selftests/bpf/progs/lsm.c | 34 ++++++++++++-------------
  3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index c2b76545153c..7dd523a7e32d 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -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();

Makes sense, was wondering about a __might_sleep() but that will cover it internally
too. Applied, thanks!

  }
void notrace __bpf_prog_exit_sleepable(void)



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux