From: Yonghong Song <yonghong.song@linux.dev>
To: Sami Tolvanen <samitolvanen@google.com>, bpf@vger.kernel.org
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/4] bpf: crypto: Use the correct destructor kfunc type
Date: Fri, 25 Jul 2025 16:11:27 -0700 [thread overview]
Message-ID: <932a6a4d-d30b-4b85-b6a9-2eabeb5eaf2e@linux.dev> (raw)
In-Reply-To: <20250725214401.1475224-7-samitolvanen@google.com>
On 7/25/25 2:44 PM, Sami Tolvanen wrote:
> With CONFIG_CFI_CLANG enabled, the kernel strictly enforces that
> indirect function calls use a function pointer type that matches the
> target function. I ran into the following type mismatch when running
> BPF self-tests:
>
> CFI failure at bpf_obj_free_fields+0x190/0x238 (target:
> bpf_crypto_ctx_release+0x0/0x94; expected type: 0xa488ebfc)
> Internal error: Oops - CFI: 00000000f2008228 [#1] SMP
> ...
>
> As bpf_crypto_ctx_release() is also used in BPF programs and using
> a void pointer as the argument would make the verifier unhappy, add
> a simple stub function with the correct type and register it as the
> destructor kfunc instead.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> ---
> kernel/bpf/crypto.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
> index 94854cd9c4cc..f44aa454826b 100644
> --- a/kernel/bpf/crypto.c
> +++ b/kernel/bpf/crypto.c
> @@ -261,6 +261,13 @@ __bpf_kfunc void bpf_crypto_ctx_release(struct bpf_crypto_ctx *ctx)
> call_rcu(&ctx->rcu, crypto_free_cb);
> }
>
> +__used __retain void __bpf_crypto_ctx_release(void *ctx)
> +{
> + bpf_crypto_ctx_release(ctx);
> +}
> +
> +CFI_NOSEAL(__bpf_crypto_ctx_release);
Okay, looks like Peter has made similar changes before.
See https://lore.kernel.org/all/20231215092707.799451071@infradead.org/
To be consistent with existing code base, I think the following
change is better:
diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
index 94854cd9c4cc..a267d9087d40 100644
--- a/kernel/bpf/crypto.c
+++ b/kernel/bpf/crypto.c
@@ -261,6 +261,12 @@ __bpf_kfunc void bpf_crypto_ctx_release(struct bpf_crypto_ctx *ctx)
call_rcu(&ctx->rcu, crypto_free_cb);
}
+__bpf_kfunc void bpf_crypto_ctx_release_dtor(void *ctx)
+{
+ bpf_crypto_ctx_release(ctx);
+}
+CFI_NOSEAL(bpf_crypto_ctx_release_dtor);
+
static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr_kern *src,
const struct bpf_dynptr_kern *dst,
@@ -368,7 +374,7 @@ static const struct btf_kfunc_id_set crypt_kfunc_set = {
BTF_ID_LIST(bpf_crypto_dtor_ids)
BTF_ID(struct, bpf_crypto_ctx)
-BTF_ID(func, bpf_crypto_ctx_release)
+BTF_ID(func, bpf_crypto_ctx_release_dtor)
static int __init crypto_kfunc_init(void)
{
The same code pattern can be done for patch 2 and patch 3.
> +
> static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
> const struct bpf_dynptr_kern *src,
> const struct bpf_dynptr_kern *dst,
> @@ -368,7 +375,7 @@ static const struct btf_kfunc_id_set crypt_kfunc_set = {
>
> BTF_ID_LIST(bpf_crypto_dtor_ids)
> BTF_ID(struct, bpf_crypto_ctx)
> -BTF_ID(func, bpf_crypto_ctx_release)
> +BTF_ID(func, __bpf_crypto_ctx_release)
>
> static int __init crypto_kfunc_init(void)
> {
next prev parent reply other threads:[~2025-07-25 23:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 21:44 [PATCH bpf-next v2 0/4] Use correct destructor kfunc types Sami Tolvanen
2025-07-25 21:44 ` [PATCH bpf-next v2 1/4] bpf: crypto: Use the correct destructor kfunc type Sami Tolvanen
2025-07-25 23:11 ` Yonghong Song [this message]
2025-07-28 18:18 ` Sami Tolvanen
2025-07-25 21:44 ` [PATCH bpf-next v2 2/4] bpf: net_sched: " Sami Tolvanen
2025-07-25 21:44 ` [PATCH bpf-next v2 3/4] selftests/bpf: " Sami Tolvanen
2025-07-25 21:44 ` [PATCH bpf-next v2 4/4] bpf, btf: Enforce destructor kfunc type with CFI Sami Tolvanen
2025-07-25 23:37 ` Yonghong Song
2025-07-25 23:42 ` [PATCH bpf-next v2 0/4] Use correct destructor kfunc types Yonghong Song
2025-07-28 18:21 ` Sami Tolvanen
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=932a6a4d-d30b-4b85-b6a9-2eabeb5eaf2e@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=vadim.fedorenko@linux.dev \
--cc=xiyou.wangcong@gmail.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
all inboxes | Powered by JetHome®