netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Florian Westphal <fw@strlen.de>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@kernel.org
Subject: Re: [PATCH bpf] bpf: netfilter: add BPF_NETFILTER bpf_attach_type
Date: Tue, 30 May 2023 10:10:45 -0700	[thread overview]
Message-ID: <CAEf4BzYt-gFs3cWfcAsMz9kie_pZNnsCdzXCy0NscK0wU1fCtg@mail.gmail.com> (raw)
In-Reply-To: <20230526121124.3915-1-fw@strlen.de>

On Fri, May 26, 2023 at 5:11 AM Florian Westphal <fw@strlen.de> wrote:
>
> Andrii Nakryiko writes:
>
>  And we currently don't have an attach type for NETLINK BPF link.
>  Thankfully it's not too late to add it. I see that link_create() in
>  kernel/bpf/syscall.c just bypasses attach_type check. We shouldn't
>  have done that. Instead we need to add BPF_NETLINK attach type to enum
>  bpf_attach_type. And wire all that properly throughout the kernel and
>  libbpf itself.
>
> This adds BPF_NETFILTER and uses it.  This breaks uabi but this
> wasn't in any non-rc release yet, so it should be fine.
>
> Fixes: 84601d6ee68a ("bpf: add bpf_link support for BPF_NETFILTER programs")
> Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Link: https://lore.kernel.org/bpf/CAEf4BzZ69YgrQW7DHCJUT_X+GqMq_ZQQPBwopaJJVGFD5=d5Vg@mail.gmail.com/
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  include/uapi/linux/bpf.h       | 1 +
>  kernel/bpf/syscall.c           | 4 ++++
>  tools/include/uapi/linux/bpf.h | 1 +
>  tools/lib/bpf/libbpf.c         | 2 +-
>  4 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 1bb11a6ee667..c994ff5b157c 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -1035,6 +1035,7 @@ enum bpf_attach_type {
>         BPF_TRACE_KPROBE_MULTI,
>         BPF_LSM_CGROUP,
>         BPF_STRUCT_OPS,
> +       BPF_NETFILTER,
>         __MAX_BPF_ATTACH_TYPE
>  };
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 14f39c1e573e..cc1fc2404406 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -2433,6 +2433,10 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
>                 default:
>                         return -EINVAL;
>                 }
> +       case BPF_PROG_TYPE_NETFILTER:
> +               if (expected_attach_type == BPF_NETFILTER)
> +                       return 0;
> +               return -EINVAL;
>         case BPF_PROG_TYPE_SYSCALL:
>         case BPF_PROG_TYPE_EXT:
>                 if (expected_attach_type)

You've missed updating link_create() as well, there is a

case BPF_PROG_TYPE_NETFILTER:
    break;

switch case, which should validate that attr->link_create.attach_type
is BPF_NETFILTER


Other than that, it looks good to me, thanks!

> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index 1bb11a6ee667..c994ff5b157c 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -1035,6 +1035,7 @@ enum bpf_attach_type {
>         BPF_TRACE_KPROBE_MULTI,
>         BPF_LSM_CGROUP,
>         BPF_STRUCT_OPS,
> +       BPF_NETFILTER,
>         __MAX_BPF_ATTACH_TYPE
>  };
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ad1ec893b41b..532a97cf1cc1 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -8712,7 +8712,7 @@ static const struct bpf_sec_def section_defs[] = {
>         SEC_DEF("struct_ops+",          STRUCT_OPS, 0, SEC_NONE),
>         SEC_DEF("struct_ops.s+",        STRUCT_OPS, 0, SEC_SLEEPABLE),
>         SEC_DEF("sk_lookup",            SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
> -       SEC_DEF("netfilter",            NETFILTER, 0, SEC_NONE),
> +       SEC_DEF("netfilter",            NETFILTER, BPF_NETFILTER, SEC_NONE),
>  };
>
>  static size_t custom_sec_def_cnt;
> --
> 2.39.3
>

  reply	other threads:[~2023-05-30 17:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 11:00 [PATCH bpf-next 0/2] libbpf: add netfilter link attach helper Florian Westphal
2023-05-25 11:00 ` [PATCH bpf-next 1/2] tools: " Florian Westphal
2023-05-25 21:01   ` Andrii Nakryiko
2023-05-26 12:11     ` [PATCH bpf] bpf: netfilter: add BPF_NETFILTER bpf_attach_type Florian Westphal
2023-05-30 17:10       ` Andrii Nakryiko [this message]
2023-05-25 11:01 ` [PATCH bpf-next 2/2] selftests/bpf: Add bpf_program__attach_netfilter_opts helper test Florian Westphal
2023-05-25 21:05   ` Andrii Nakryiko

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=CAEf4BzYt-gFs3cWfcAsMz9kie_pZNnsCdzXCy0NscK0wU1fCtg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=fw@strlen.de \
    --cc=netdev@vger.kernel.org \
    /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).