From: Eduard Zingerman <eddyz87@gmail.com>
To: Stanislav Fomichev <sdf@google.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com,
jolsa@kernel.org,
syzbot+838346b979830606c854@syzkaller.appspotmail.com
Subject: Re: [PATCH bpf 1/3] bpf: Add BPF_PROG_TYPE_CGROUP_SKB attach type enforcement in BPF_LINK_CREATE
Date: Mon, 29 Apr 2024 12:34:06 -0700 [thread overview]
Message-ID: <7c5553d33d0796a22ffa3d4c7e1791e7f033d43d.camel@gmail.com> (raw)
In-Reply-To: <20240426231621.2716876-2-sdf@google.com>
On Fri, 2024-04-26 at 16:16 -0700, Stanislav Fomichev wrote:
> bpf_prog_attach uses attach_type_to_prog_type to enforce proper
> attach type for BPF_PROG_TYPE_CGROUP_SKB. link_create uses
> bpf_prog_get and relies on bpf_prog_attach_check_attach_type
> to properly verify prog_type <> attach_type association.
>
> Add missing attach_type enforcement for the link_create case.
> Otherwise, it's currently possible to attach cgroup_skb prog
> types to other cgroup hooks.
>
> Fixes: af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment")
> Link: https://lore.kernel.org/bpf/0000000000004792a90615a1dde0@google.com/
> Reported-by: syzbot+838346b979830606c854@syzkaller.appspotmail.com
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
I've spent some time comparing:
- syscall.c:bpf_prog_attach()
- syscall.c:link_create()
- syscall.c:bpf_prog_attach_check_attach_type()
- syscall.c:attach_type_to_prog_type()
- verifier.c:check_return_code()
And it looks like BPF_PROG_TYPE_CGROUP_SKB is the only thing with
missing attach type checks.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
(The interplay between the above functions seems a bit messy,
but I don't have good suggestions for refactoring at the moment.
It appears that bpf_prog_attach_check_attach_type() could be simplified
if prog->enforce_expected_attach_type would be set more aggressively and
if (prog->enforce_expected_attach_type &&
prog->expected_attach_type != attach_type)
return -EINVAL;
moved as a top-level check outside of the switch.
Also BPF_PROG_TYPE_SCHED_CLS case could be removed as it is handled
by default branch. But these are larger changes).
next prev parent reply other threads:[~2024-04-29 19:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 23:16 [PATCH bpf 0/3] bpf: Add BPF_PROG_TYPE_CGROUP_SKB attach type enforcement in BPF_LINK_CREATE Stanislav Fomichev
2024-04-26 23:16 ` [PATCH bpf 1/3] " Stanislav Fomichev
2024-04-29 19:34 ` Eduard Zingerman [this message]
2024-04-29 21:17 ` Stanislav Fomichev
2024-04-26 23:16 ` [PATCH bpf 2/3] selftests/bpf: Extend sockopt tests to use BPF_LINK_CREATE Stanislav Fomichev
2024-04-29 19:57 ` Eduard Zingerman
2024-04-26 23:16 ` [PATCH bpf 3/3] selftests/bpf: Add sockopt case to verify prog_type Stanislav Fomichev
2024-04-29 19:58 ` Eduard Zingerman
2024-04-30 18:20 ` [PATCH bpf 0/3] bpf: Add BPF_PROG_TYPE_CGROUP_SKB attach type enforcement in BPF_LINK_CREATE patchwork-bot+netdevbpf
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=7c5553d33d0796a22ffa3d4c7e1791e7f033d43d.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=syzbot+838346b979830606c854@syzkaller.appspotmail.com \
--cc=yhs@fb.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).