Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Lorenz Bauer <lmb@cloudflare.com>, <jakub@cloudflare.com>,
<john.fastabend@gmail.com>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: <kernel-team@cloudflare.com>, <netdev@vger.kernel.org>,
<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v3 5/6] bpf: sockmap: allow update from BPF
Date: Fri, 21 Aug 2020 08:47:54 -0700 [thread overview]
Message-ID: <fc988cf8-e039-61f5-3d73-0ecf8f27308f@fb.com> (raw)
In-Reply-To: <20200821102948.21918-6-lmb@cloudflare.com>
On 8/21/20 3:29 AM, Lorenz Bauer wrote:
> Allow calling bpf_map_update_elem on sockmap and sockhash from a BPF
> context. The synchronization required for this is a bit fiddly: we
> need to prevent the socket from changing its state while we add it
> to the sockmap, since we rely on getting a callback via
> sk_prot->unhash. However, we can't just lock_sock like in
> sock_map_sk_acquire because that might sleep. So instead we disable
> softirq processing and use bh_lock_sock to prevent further
> modification.
>
> Yet, this is still not enough. BPF can be called in contexts where
> the current CPU might have locked a socket. If the BPF can get
> a hold of such a socket, inserting it into a sockmap would lead to
> a deadlock. One straight forward example are sock_ops programs that
> have ctx->sk, but the same problem exists for kprobes, etc.
> We deal with this by allowing sockmap updates only from known safe
> contexts. Improper usage is rejected by the verifier.
>
> I've audited the enabled contexts to make sure they can't run in
> a locked context. It's possible that CGROUP_SKB and others are
> safe as well, but the auditing here is much more difficult. In
> any case, we can extend the safe contexts when the need arises.
>
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Acked-by: Yonghong Song <yhs@fb.com>
next prev parent reply other threads:[~2020-08-21 15:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-21 10:29 [PATCH bpf-next v3 0/6] Allow updating sockmap / sockhash " Lorenz Bauer
2020-08-21 10:29 ` [PATCH bpf-next v3 1/6] net: sk_msg: simplify sk_psock initialization Lorenz Bauer
2020-08-21 10:29 ` [PATCH bpf-next v3 2/6] bpf: sockmap: merge sockmap and sockhash update functions Lorenz Bauer
2020-08-21 10:29 ` [PATCH bpf-next v3 3/6] bpf: sockmap: call sock_map_update_elem directly Lorenz Bauer
2020-08-21 10:29 ` [PATCH bpf-next v3 4/6] bpf: override the meaning of ARG_PTR_TO_MAP_VALUE for sockmap and sockhash Lorenz Bauer
2020-08-21 15:46 ` Yonghong Song
2020-08-21 10:29 ` [PATCH bpf-next v3 5/6] bpf: sockmap: allow update from BPF Lorenz Bauer
2020-08-21 15:47 ` Yonghong Song [this message]
2020-08-21 10:29 ` [PATCH bpf-next v3 6/6] selftests: bpf: test sockmap " Lorenz Bauer
2020-08-21 16:13 ` Yonghong Song
2020-08-21 22:23 ` [PATCH bpf-next v3 0/6] Allow updating sockmap / sockhash " Alexei Starovoitov
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=fc988cf8-e039-61f5-3d73-0ecf8f27308f@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--subject='Re: [PATCH bpf-next v3 5/6] bpf: sockmap: allow update from BPF' \
/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).