bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Lorenz Bauer <lmb@cloudflare.com>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <sdf@google.com>, <jakub@cloudflare.com>,
	<john.fastabend@gmail.com>
Cc: <kernel-team@cloudflare.com>, <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf v2 0/6] Fix attach / detach uapi for sockmap and flow_dissector
Date: Mon, 29 Jun 2020 22:48:51 -0700	[thread overview]
Message-ID: <07d10dab-64f7-d7af-25b9-a61b39c8daf2@fb.com> (raw)
In-Reply-To: <20200629095630.7933-1-lmb@cloudflare.com>



On 6/29/20 2:56 AM, Lorenz Bauer wrote:
> Both sockmap and flow_dissector ingnore various arguments passed to
> BPF_PROG_ATTACH and BPF_PROG_DETACH. We can fix the attach case by
> checking that the unused arguments are zero. I considered requiring
> target_fd to be -1 instead of 0, but this leads to a lot of churn
> in selftests. There is also precedent in that bpf_iter already
> expects 0 for a similar field. I think that we can come up with a

Since bpf_iter is mentioned here, I would like to provide a little
context on how target_fd in link_create is treated there.

Currently, target_fd is always 0 as it is not used. This is
just easier if we want to use it in the future.

In the future, bpf_iter can maintain that target_fd must be 0
or it may not so. For example, it can add a flag value in
link_create such that when flag is set it will take whatever
value in target_fd and use it. Or it may just take a non-0
target_fd as an indication of the flag is set. I have not
finalized patches yet. I intend to do the latter, i.e.,
taking a non-0 target_fd. But we will see once my bpf_iter
patches for map elements are out.

There is another example where 0 and non-0 prog_fd make a difference.
The attach_prog_fd field when doing prog_load.
When attach_prog_fd is 0, it means attaching to vmlinux through
attach_btf_id. If attach_prog_fd is not 0, it means attaching to
another bpf program (replace). So user space (libbpf) may
already need to pay attention to this.

> work around for fd 0 should we need to in the future.
> 
> The detach case is more problematic: both cgroups and lirc2 verify
> that attach_bpf_fd matches the currently attached program. This
> way you need access to the program fd to be able to remove it.
> Neither sockmap nor flow_dissector do this. flow_dissector even
> has a check for CAP_NET_ADMIN because of this. The patch set
> addresses this by implementing the desired behaviour.
> 
> There is a possibility for user space breakage: any callers that
> don't provide the correct fd will fail with ENOENT. For sockmap
> the risk is low: even the selftests assume that sockmap works
> the way I described. For flow_dissector the story is less
> straightforward, and the selftests use a variety of arguments.
> 
> I've includes fixes tags for the oldest commits that allow an easy
> backport, however the behaviour dates back to when sockmap and
> flow_dissector were introduced. What is the best way to handle these?
> 
> This set is based on top of Jakub's work "bpf, netns: Prepare
> for multi-prog attachment" available at
> https://lore.kernel.org/bpf/87k0zwmhtb.fsf@cloudflare.com/T/
> 
> Since v1:
> - Adjust selftests
> - Implement detach behaviour
> 
> Lorenz Bauer (6):
>    bpf: flow_dissector: check value of unused flags to BPF_PROG_ATTACH
>    bpf: flow_dissector: check value of unused flags to BPF_PROG_DETACH
>    bpf: sockmap: check value of unused args to BPF_PROG_ATTACH
>    bpf: sockmap: require attach_bpf_fd when detaching a program
>    selftests: bpf: pass program and target_fd in flow_dissector_reattach
>    selftests: bpf: pass program to bpf_prog_detach in flow_dissector
> 
>   include/linux/bpf-netns.h                     |  5 +-
>   include/linux/bpf.h                           | 13 ++++-
>   include/linux/skmsg.h                         | 13 +++++
>   kernel/bpf/net_namespace.c                    | 22 ++++++--
>   kernel/bpf/syscall.c                          |  6 +--
>   net/core/sock_map.c                           | 53 +++++++++++++++++--
>   .../selftests/bpf/prog_tests/flow_dissector.c |  4 +-
>   .../bpf/prog_tests/flow_dissector_reattach.c  | 12 ++---
>   8 files changed, 103 insertions(+), 25 deletions(-)
> 

  parent reply	other threads:[~2020-06-30  5:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29  9:56 [PATCH bpf v2 0/6] Fix attach / detach uapi for sockmap and flow_dissector Lorenz Bauer
2020-06-29  9:56 ` [PATCH bpf v2 1/6] bpf: flow_dissector: check value of unused flags to BPF_PROG_ATTACH Lorenz Bauer
2020-11-04 18:08   ` Jiri Benc
2020-11-05 11:00     ` Lorenz Bauer
2020-11-05 11:08       ` Jiri Benc
2020-11-05 16:04         ` Stanislav Fomichev
2020-06-29  9:56 ` [PATCH bpf v2 2/6] bpf: flow_dissector: check value of unused flags to BPF_PROG_DETACH Lorenz Bauer
2020-06-29  9:56 ` [PATCH bpf v2 3/6] bpf: sockmap: check value of unused args to BPF_PROG_ATTACH Lorenz Bauer
2020-06-29  9:56 ` [PATCH bpf v2 4/6] bpf: sockmap: require attach_bpf_fd when detaching a program Lorenz Bauer
2020-07-08  1:30   ` Martin KaFai Lau
2020-06-29  9:56 ` [PATCH bpf v2 5/6] selftests: bpf: pass program and target_fd in flow_dissector_reattach Lorenz Bauer
2020-06-29  9:56 ` [PATCH bpf v2 6/6] selftests: bpf: pass program to bpf_prog_detach in flow_dissector Lorenz Bauer
2020-06-30  5:48 ` Yonghong Song [this message]
2020-06-30  8:39   ` [PATCH bpf v2 0/6] Fix attach / detach uapi for sockmap and flow_dissector Lorenz Bauer
2020-06-30 15:08     ` Yonghong Song
2020-06-30 15:50       ` Lorenz Bauer
2020-06-30 18:00 ` Alexei Starovoitov
2020-06-30 18:31   ` Jakub Sitnicki
2020-06-30 18:42     ` Alexei Starovoitov
2020-07-01  7:45       ` Jakub Sitnicki

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=07d10dab-64f7-d7af-25b9-a61b39c8daf2@fb.com \
    --to=yhs@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@cloudflare.com \
    --cc=lmb@cloudflare.com \
    --cc=sdf@google.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).