From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AE53C38142 for ; Fri, 27 Jan 2023 19:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234090AbjA0TTC (ORCPT ); Fri, 27 Jan 2023 14:19:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbjA0TSv (ORCPT ); Fri, 27 Jan 2023 14:18:51 -0500 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D17C7BE56 for ; Fri, 27 Jan 2023 11:18:36 -0800 (PST) Received: by devvm15675.prn0.facebook.com (Postfix, from userid 115148) id 705984CC621B; Fri, 27 Jan 2023 11:18:24 -0800 (PST) From: Joanne Koong 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 Subject: [PATCH v9 bpf-next 1/5] bpf: Allow "sk_buff" and "xdp_buff" as valid kfunc arg types Date: Fri, 27 Jan 2023 11:16:59 -0800 Message-Id: <20230127191703.3864860-2-joannelkoong@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230127191703.3864860-1-joannelkoong@gmail.com> References: <20230127191703.3864860-1-joannelkoong@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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") =3D=3D 0 && strcmp(tname, "sk_buff")= =3D=3D 0) + return ctx_type; + if (strcmp(ctx_tname, "xdp_md") =3D=3D 0 && strcmp(tname, "xdp_buff") =3D= =3D 0) + return ctx_type; if (strcmp(ctx_tname, tname)) return NULL; return ctx_type; --=20 2.30.2