Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, davem@davemloft.net
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH bpf-next] bpf: Remove bpf_lsm_file_mprotect from sleepable list.
Date: Mon, 31 Aug 2020 23:25:23 +0200	[thread overview]
Message-ID: <c6df42da-6185-3958-0528-55a43d0a9444@iogearbox.net> (raw)
In-Reply-To: <20200831201651.82447-1-alexei.starovoitov@gmail.com>

On 8/31/20 10:16 PM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> 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@fb.com>
> Fixes: 1e6c62a88215 ("bpf: Introduce sleepable BPF programs")
> Fixes: e68a144547fc ("selftests/bpf: Add sleepable tests")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
>   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)

      reply	other threads:[~2020-08-31 21:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 20:16 Alexei Starovoitov
2020-08-31 21:25 ` Daniel Borkmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c6df42da-6185-3958-0528-55a43d0a9444@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH bpf-next] bpf: Remove bpf_lsm_file_mprotect from sleepable list.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).