From: Joanne Koong <joannelkoong@gmail.com>
To: bpf@vger.kernel.org
Cc: martin.lau@kernel.org, andrii@kernel.org, ast@kernel.org,
memxor@gmail.com, daniel@iogearbox.net, netdev@vger.kernel.org,
toke@kernel.org, Joanne Koong <joannelkoong@gmail.com>
Subject: [PATCH v12 bpf-next 01/10] bpf: Support "sk_buff" and "xdp_buff" as valid kfunc arg types
Date: Sun, 26 Feb 2023 00:51:11 -0800 [thread overview]
Message-ID: <20230226085120.3907863-2-joannelkoong@gmail.com> (raw)
In-Reply-To: <20230226085120.3907863-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 <--> __sk_buff" and "xdp_buff <--> xdp_md"
to be recognized as 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.
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 fa22ec79ac0e..84cca8473873 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5683,6 +5683,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)) {
/* bpf_user_pt_regs_t is a typedef, so resolve it to
* underlying struct and check name again
--
2.34.1
next prev parent reply other threads:[~2023-02-26 8:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-26 8:51 [PATCH v12 bpf-next 00/10] Add skb + xdp dynptrs Joanne Koong
2023-02-26 8:51 ` Joanne Koong [this message]
2023-02-26 8:51 ` [PATCH v12 bpf-next 02/10] bpf: Refactor process_dynptr_func Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 03/10] bpf: Allow initializing dynptrs in kfuncs Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 04/10] bpf: Define no-ops for externally called bpf dynptr functions Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 05/10] bpf: Refactor verifier dynptr into get_dynptr_arg_reg Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 06/10] bpf: Add __uninit kfunc annotation Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 07/10] bpf: Add skb dynptrs Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 08/10] bpf: Add xdp dynptrs Joanne Koong
2023-02-26 8:51 ` [PATCH v12 bpf-next 09/10] bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr Joanne Koong
2023-02-26 10:03 ` kernel test robot
2023-02-26 10:14 ` kernel test robot
2023-02-26 10:54 ` kernel test robot
2023-02-26 8:51 ` [PATCH v12 bpf-next 10/10] 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=20230226085120.3907863-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=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=toke@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).