From: Joanne Koong <joannelkoong@gmail.com>
To: bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org,
ast@kernel.org, netdev@vger.kernel.org, memxor@gmail.com,
kernel-team@fb.com, Joanne Koong <joannelkoong@gmail.com>
Subject: [PATCH v8 bpf-next 1/5] bpf: Allow "sk_buff" and "xdp_buff" as valid kfunc arg types
Date: Thu, 26 Jan 2023 15:34:35 -0800 [thread overview]
Message-ID: <20230126233439.3739120-2-joannelkoong@gmail.com> (raw)
In-Reply-To: <20230126233439.3739120-1-joannelkoong@gmail.com>
The bpf mirror of the in-kernel sk_buff and xdp_buff data structures are
__sk_buff and xdp_md. Currently, when we pass in the program ctx to a
kfunc where the program ctx is a skb or xdp buffer, we reject the
program if the in-kernel definition is sk_buff/xdp_buff instead of
__sk_buff/xdp_md.
This change allows sk_buff and __sk_buff, and xdp_buff and xdp_md to be
valid matches. The user program may pass in their program ctx as a
__sk_buff or xdp_md, and the in-kernel definition of the kfunc may
define this arg as a sk_buff or xdp_buff. Please note that the
__sk_buff/xdp_md -> sk_buff/xdp_buff conversion happens in
convert_ctx_accesses() in the verifier.
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
kernel/bpf/btf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 47b8cb96f2c2..b4da17688c65 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5606,6 +5606,10 @@ btf_get_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf,
* int socket_filter_bpf_prog(struct __sk_buff *skb)
* { // no fields of skb are ever used }
*/
+ if (strcmp(ctx_tname, "__sk_buff") == 0 && strcmp(tname, "sk_buff") == 0)
+ return ctx_type;
+ if (strcmp(ctx_tname, "xdp_md") == 0 && strcmp(tname, "xdp_buff") == 0)
+ return ctx_type;
if (strcmp(ctx_tname, tname))
return NULL;
return ctx_type;
--
2.30.2
next prev parent reply other threads:[~2023-01-27 0:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 23:34 [PATCH v8 bpf-next 0/5] Add skb + xdp dynptrs Joanne Koong
2023-01-26 23:34 ` Joanne Koong [this message]
2023-01-26 23:34 ` [PATCH v8 bpf-next 2/5] bpf: Allow initializing dynptrs in kfuncs Joanne Koong
2023-01-28 11:52 ` kernel test robot
2023-01-28 14:27 ` kernel test robot
2023-01-26 23:34 ` [PATCH v8 bpf-next 3/5] bpf: Add skb dynptrs Joanne Koong
2023-01-27 7:58 ` Martin KaFai Lau
2023-01-27 18:07 ` Joanne Koong
2023-01-28 13:15 ` kernel test robot
2023-01-26 23:34 ` [PATCH v8 bpf-next 4/5] bpf: Add xdp dynptrs Joanne Koong
2023-01-28 14:38 ` kernel test robot
2023-01-26 23:34 ` [PATCH v8 bpf-next 5/5] selftests/bpf: tests for using dynptrs to parse skb and xdp buffers Joanne Koong
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=20230126233439.3739120-2-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--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).