BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint
@ 2024-08-28 19:48 Juntong Deng
  2024-08-28 19:51 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add test for zero offset or non-zero offset pointers as KF_ACQUIRE kfuncs argument Juntong Deng
  2024-08-29  0:20 ` [PATCH bpf-next v2 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Juntong Deng @ 2024-08-28 19:48 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, memxor, snorcht
  Cc: bpf, linux-kernel

Currently we cannot pass zero offset (implicit cast) or non-zero offset
pointers to KF_ACQUIRE kfuncs. This is because KF_ACQUIRE kfuncs
requires strict type matching, but zero offset or non-zero offset does
not change the type of pointer, which causes the ebpf program to be
rejected by the verifier.

This can cause some problems, one example is that bpf_skb_peek_tail
kfunc [0] cannot be implemented by just passing in non-zero offset
pointers. We cannot pass pointers like &sk->sk_write_queue (non-zero
offset) or &sk->__sk_common (zero offset) to KF_ACQUIRE kfuncs.

This patch makes KF_ACQUIRE kfuncs not require strict type matching.

[0]: https://lore.kernel.org/bpf/AM6PR03MB5848CA39CB4B7A4397D380B099B12@AM6PR03MB5848.eurprd03.prod.outlook.com/

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
---
v1 -> v2: Completely remove strict type matching for KF_ACQUIRE kfuncs

 kernel/bpf/verifier.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5437dca56159..0f3b6fa3db39 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -11497,8 +11497,7 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env,
 	 * btf_struct_ids_match() to walk the struct at the 0th offset, and
 	 * resolve types.
 	 */
-	if (is_kfunc_acquire(meta) ||
-	    (is_kfunc_release(meta) && reg->ref_obj_id) ||
+	if ((is_kfunc_release(meta) && reg->ref_obj_id) ||
 	    btf_type_ids_nocast_alias(&env->log, reg_btf, reg_ref_id, meta->btf, ref_id))
 		strict_type_match = true;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-29  0:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28 19:48 [PATCH bpf-next v2 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint Juntong Deng
2024-08-28 19:51 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add test for zero offset or non-zero offset pointers as KF_ACQUIRE kfuncs argument Juntong Deng
2024-08-29  0:20 ` [PATCH bpf-next v2 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox