Skip to contentSkip to conversation

bpf: Fix tracing of kfuncs with implicit args

PATCH Superseded Ihor Solodrai 3 participants 8 messages Jul 10

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ihor Solodrai

author reviewer
#0 lore raw

PATCH 1/2 bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype [1].

fentry/fexit/fmod_ret/fsession programs may attach to the kernel functions, including those with implicit args. However bpf_check_attach_target() and bpf_check_attach_btf_id_multi() extract the struct btf_func_model from the wrong BTF prototype of the kfunc. The btf_func_model is later read to construct the trampoline, which then causes the injected implicit argument to be clobbered and the kfunc dereferencing garbage [2].

Add btf_attach_func_proto() to resolve the real ABI prototype of the kfunc the way the call site does: by looking up the _impl prototype for a KF_IMPLICIT_ARGS kfunc. Use it at both attach-target model construction sites.

To enable this, make two supporting changes:
* pass bpf_verifier_log instead of bpf_verifier_env to find_kfunc_impl_proto(), so it can be reused from the attach path
* introduce btf_kfunc_accumulated_flags() helper to read a kfunc's flags across all hooks, because a program attaching to a kfunc is not in the kfunc's call-set

The remaining call sites of btf_distill_func_proto() are safe as is. The BPF_TRACE_ITER case distills a registered iterator's prototype, and bpf_struct_ops_desc_init() distills the function-pointer members of a struct_ops type. Neither is a kfunc, and so can't have implicit arguments.

[1] https://lore.kernel.org/all/[email protected]/

Fixes 64e1360524b9 ("bpf: Verifier support for KF_IMPLICIT_ARGS")

---

This should probably be backported to 7.1

---
 include/linux/btf.h   |  1 +
 kernel/bpf/btf.c      | 20 +++++++++++++++++
 kernel/bpf/verifier.c | 51 ++++++++++++++++++++++++++++++++-----------
 3 files changed, 59 insertions(+), 13 deletions(-)
include/linux/btf.h +1 -0
index 240401d9b25b..c52245ae0df5 100644
@@ -578,6 +578,7 @@ const char *btf_str_by_offset(const struct btf *btf, u32 offset);
 struct btf *btf_parse_vmlinux(void);
 struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog);
 u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_prog *prog);
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id);
 bool btf_kfunc_is_allowed(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_prog *prog);
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog);
kernel/bpf/btf.c +20 -0
index 64572f85edc8..20aeca6b4f95 100644
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +38 -13

91 lines not on this page · raw message

Signature · 1 line
2.55.0
author reviewer
#1 lore raw

PATCH 2/2 selftests/bpf: Cover tracing implicit kfunc args

From: Kumar Kartikeya Dwivedi <[email protected]>

KF_IMPLICIT_ARGS kfuncs have a BPF-call prototype and a real kernel target prototype. Add a tracing selftest that attaches fentry and fexit programs to bpf_kfunc_implicit_arg(), runs a syscall BPF program that calls it, and checks that the tracing context exposes both the explicit argument and the implicit prog aux pointer.

---
 .../prog_tests/kfunc_implicit_args_tracing.c  | 36 +++++++++
 .../bpf/progs/kfunc_implicit_args_tracing.c   | 77 +++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args_tracing.c
 create mode 100644 tools/testing/selftests/bpf/progs/kfunc_implicit_args_tracing.c
tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args_tracing.c new file +36 -0
new file mode 100644
index 000000000000..61cc5aaba025
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <test_progs.h>
+#include "kfunc_implicit_args_tracing.skel.h"
+
+void test_kfunc_implicit_args_tracing(void)
+{
+	struct kfunc_implicit_args_tracing *skel;
+	LIBBPF_OPTS(bpf_test_run_opts, topts);
+	int err, fd;
+
+	skel = kfunc_implicit_args_tracing__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		return;
+
+	err = kfunc_implicit_args_tracing__attach(skel);
+	if (!ASSERT_OK(err, "attach"))
+		goto cleanup;
+
+	fd = bpf_program__fd(skel->progs.trigger_implicit_arg);
+	err = bpf_prog_test_run_opts(fd, &topts);
+	if (!ASSERT_OK(err, "test_run"))
+		goto cleanup;
+
+	ASSERT_EQ(topts.retval, 5, "kfunc_retval");
+	ASSERT_EQ(skel->bss->fentry_arg_cnt, 2, "fentry_arg_cnt");
+	ASSERT_NEQ(skel->bss->fentry_aux_arg, 0, "fentry_aux_arg");
+	ASSERT_EQ(skel->bss->fentry_result, 1, "fentry_result");
+	ASSERT_EQ(skel->bss->fexit_arg_cnt, 2, "fexit_arg_cnt");
+	ASSERT_NEQ(skel->bss->fexit_aux_arg, 0, "fexit_aux_arg");
+	ASSERT_EQ(skel->bss->fexit_result, 1, "fexit_result");
+
+cleanup:
+	kfunc_implicit_args_tracing__destroy(skel);
+}
tools/testing/selftests/bpf/progs/kfunc_implicit_args_tracing.c new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw
In reply to Ihor Solodrai
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Accessing `btf->kfunc_set_tab` without holding a module reference causes a use-after-free…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Accessing btf->kfunc_set_tab without holding a module reference causes a use-after-free vulnerability. --

--- Patch [1]: [PATCH bpf v1 1/2] bpf: Fix tracing of kfuncs with implicit args --- commit 13df91bf669b3a55c459c1663fbf726f9f52bc5c
Author: Ihor Solodrai <[email protected]>

bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype.

Quoted 4 lines
kernel/bpf/btf.c +0 -0
index 64572f85edc83..20aeca6b4f95c 100644

[ ... ]

Quoted 31 lines
kernel/bpf/btf.c +20 -0
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +0 -0
index 6515d4d3c0032..fde11a2f6869a 100644

[ ... ]

kernel/bpf/verifier.c int bpf_check_attach_target(struct bpf_verifier_log *log, · line 19151

Quoted 9 lines
kernel/bpf/verifier.c +2 -2
@@ -19121,8 +19146,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		if (prog_extension &&
 		    btf_check_type_match(log, prog, btf, t))
 			return -EINVAL;
-		t = btf_type_by_id(btf, t->type);
-		if (!btf_type_is_func_proto(t))
+		t = btf_attach_func_proto(log, btf, btf_id);
+		if (!t || !btf_type_is_func_proto(t))
 			return -EINVAL;

[Severity: High]
Does this introduce a use-after-free race condition during module load?

The new btf_attach_func_proto() call executes before the module reference is safely acquired via btf_try_get_module() later in bpf_check_attach_target():

bpf_check_attach_target()
btf_attach_func_proto()

    btf_kfunc_accumulated_flags()
      btf_kfunc_id_set_contains()
        // Accesses btf->kfunc_set_tab->sets[hook]

If a module is just loading (in MODULE_STATE_COMING) and its BTF is already visible, a concurrent BPF_PROG_LOAD could trigger this path. Meanwhile, the module's init function might call register_btf_kfunc_id_set(), which uses krealloc() on the same array.

Could the sets array be freed by krealloc() while the verifier is performing a binary search on it here?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#3 lore raw
Quoted 76 lines · On 7/9/26 6:21 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Accessing btf->kfunc_set_tab without holding a module reference causes a use-after-free vulnerability. --

--- Patch [1]: [PATCH bpf v1 1/2] bpf: Fix tracing of kfuncs with implicit args --- commit 13df91bf669b3a55c459c1663fbf726f9f52bc5c
Author: Ihor Solodrai <[email protected]>

bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype.

Quoted 4 lines
kernel/bpf/btf.c +0 -0
index 64572f85edc83..20aeca6b4f95c 100644

[ ... ]

Quoted 31 lines
kernel/bpf/btf.c +20 -0
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +0 -0
index 6515d4d3c0032..fde11a2f6869a 100644

[ ... ]

kernel/bpf/verifier.c int bpf_check_attach_target(struct bpf_verifier_log *log, · line 19151

Quoted 9 lines
kernel/bpf/verifier.c +2 -2
@@ -19121,8 +19146,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		if (prog_extension &&
 		    btf_check_type_match(log, prog, btf, t))
 			return -EINVAL;
-		t = btf_type_by_id(btf, t->type);
-		if (!btf_type_is_func_proto(t))
+		t = btf_attach_func_proto(log, btf, btf_id);
+		if (!t || !btf_type_is_func_proto(t))
 			return -EINVAL;

[Severity: High]
Does this introduce a use-after-free race condition during module load?

The new btf_attach_func_proto() call executes before the module reference is safely acquired via btf_try_get_module() later in bpf_check_attach_target():

bpf_check_attach_target()
btf_attach_func_proto()

    btf_kfunc_accumulated_flags()
      btf_kfunc_id_set_contains()
        // Accesses btf->kfunc_set_tab->sets[hook]
Quoted 7 lines

If a module is just loading (in MODULE_STATE_COMING) and its BTF is already visible, a concurrent BPF_PROG_LOAD could trigger this path. Meanwhile, the module's init function might call register_btf_kfunc_id_set(), which uses krealloc() on the same array.

Could the sets array be freed by krealloc() while the verifier is performing a binary search on it here?

Not for a module. A module registers each hook set exactly once. btf_populate_kfunc_set() rejects a second registration with WARN_ON_ONCE(set && !vmlinux_set), so it's always krealloc(NULL, ...)

And vmlinux sets are all built before BPF_PROG_LOAD can ever run.

That said, the change does violate "call btf_try_get_module() before using module's btf" expectation. I'll fix this in v2.

Quoted 1 line
#4 lore raw
Quoted 55 lines · Ihor Solodrai
Quoted 54 lines · On 7/9/26 6:21 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Accessing btf->kfunc_set_tab without holding a module reference causes a use-after-free vulnerability. --

--- Patch [1]: [PATCH bpf v1 1/2] bpf: Fix tracing of kfuncs with implicit args --- commit 13df91bf669b3a55c459c1663fbf726f9f52bc5c
Author: Ihor Solodrai <[email protected]>

bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype.

Quoted 4 lines
kernel/bpf/btf.c +0 -0
index 64572f85edc83..20aeca6b4f95c 100644

[ ... ]

Quoted 31 lines
kernel/bpf/btf.c +20 -0
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +0 -0
index 6515d4d3c0032..fde11a2f6869a 100644

[ ... ]

Quoted 10 lines
Quoted 10 lines

kernel/bpf/verifier.c int bpf_check_attach_target(struct bpf_verifier_log *log, · line 19151

Quoted 9 lines
kernel/bpf/verifier.c +2 -2
@@ -19121,8 +19146,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		if (prog_extension &&
 		    btf_check_type_match(log, prog, btf, t))
 			return -EINVAL;
-		t = btf_type_by_id(btf, t->type);
-		if (!btf_type_is_func_proto(t))
+		t = btf_attach_func_proto(log, btf, btf_id);
+		if (!t || !btf_type_is_func_proto(t))
 			return -EINVAL;

Also, why not do it for BPF_TRACE_ITER case as well? I just feel keeping it consistent may outweigh figuring out whether it's necessary in that case or not, etc.

Please supply a cover letter in the next version too since you're sending multiple patches.

Thanks

author reviewer
#5 lore raw
Quoted 67 lines · Kumar Kartikeya Dwivedi
Quoted 55 lines · Ihor Solodrai
Quoted 54 lines · On 7/9/26 6:21 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Accessing btf->kfunc_set_tab without holding a module reference causes a use-after-free vulnerability. --

--- Patch [1]: [PATCH bpf v1 1/2] bpf: Fix tracing of kfuncs with implicit args --- commit 13df91bf669b3a55c459c1663fbf726f9f52bc5c
Author: Ihor Solodrai <[email protected]>

bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype.

Quoted 4 lines
kernel/bpf/btf.c +0 -0
index 64572f85edc83..20aeca6b4f95c 100644

[ ... ]

Quoted 31 lines
kernel/bpf/btf.c +20 -0
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +0 -0
index 6515d4d3c0032..fde11a2f6869a 100644

[ ... ]

Quoted 10 lines
Quoted 10 lines

kernel/bpf/verifier.c int bpf_check_attach_target(struct bpf_verifier_log *log, · line 19151

Quoted 9 lines
kernel/bpf/verifier.c +2 -2
@@ -19121,8 +19146,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		if (prog_extension &&
 		    btf_check_type_match(log, prog, btf, t))
 			return -EINVAL;
-		t = btf_type_by_id(btf, t->type);
-		if (!btf_type_is_func_proto(t))
+		t = btf_attach_func_proto(log, btf, btf_id);
+		if (!t || !btf_type_is_func_proto(t))
 			return -EINVAL;
Quoted 3 lines

Also, why not do it for BPF_TRACE_ITER case as well? I just feel keeping it consistent may outweigh figuring out whether it's necessary in that case or not, etc.

I mentioned this in the patch description:

The BPF_TRACE_ITER case distills a registered iterator's prototype, and bpf_struct_ops_desc_init() distills the function-pointer members of a struct_ops type. Neither is a kfunc, and so can't have implicit arguments.

Quoted 3 lines

Please supply a cover letter in the next version too since you're sending multiple patches.

I used the first patch's message as a cover letter, since it's just a fix + selftest pair.

The series could be split further into refactoring changes, but I thought it'll be easier to backport if the fix is in a single self-contained patch.

I think we want the fix to get into 7.2, and backport it to 7.1.

If it's ok to carry separate refactoring patches there, then I'll split. Kartikeya, wdyt?

Quoted 2 lines

Thanks

#6 lore raw
Quoted 73 lines · Ihor Solodrai
Quoted 67 lines · Kumar Kartikeya Dwivedi
Quoted 55 lines · Ihor Solodrai
Quoted 54 lines · On 7/9/26 6:21 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Accessing btf->kfunc_set_tab without holding a module reference causes a use-after-free vulnerability. --

--- Patch [1]: [PATCH bpf v1 1/2] bpf: Fix tracing of kfuncs with implicit args --- commit 13df91bf669b3a55c459c1663fbf726f9f52bc5c
Author: Ihor Solodrai <[email protected]>

bpf: Fix tracing of kfuncs with implicit args

A kfunc marked with KF_IMPLICIT_ARGS flag takes implicit arguments (such as bpf_prog_aux) that the verifier injects at load time. resolve_btfids strips those from the kfunc's BTF-visible prototype and keeps the real kernel ABI in a counterpart _impl prototype.

Quoted 4 lines
kernel/bpf/btf.c +0 -0
index 64572f85edc83..20aeca6b4f95c 100644

[ ... ]

Quoted 31 lines
kernel/bpf/btf.c +20 -0
@@ -9114,6 +9114,26 @@ u32 *btf_kfunc_flags(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_p
 	return btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
 }
 
+/*
+ * Return the union of a kfunc's flags across all hooks.
+ * Unlike btf_kfunc_flags(), not restricted to a calling
+ * program's hook. Used when attaching to a kfunc for tracing.
+ */
+u32 btf_kfunc_accumulated_flags(const struct btf *btf, u32 kfunc_btf_id)
+{
+	enum btf_kfunc_hook hook;
+	u32 *hook_flags;
+	u32 flags = 0;
+
+	for (hook = 0; hook < BTF_KFUNC_HOOK_MAX; hook++) {
+		hook_flags = btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id);
+		if (hook_flags)
+			flags |= *hook_flags;
+	}
+
+	return flags;
+}
+
 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
 				const struct bpf_prog *prog)
 {
kernel/bpf/verifier.c +0 -0
index 6515d4d3c0032..fde11a2f6869a 100644

[ ... ]

Quoted 10 lines
Quoted 10 lines

kernel/bpf/verifier.c int bpf_check_attach_target(struct bpf_verifier_log *log, · line 19151

Quoted 9 lines
kernel/bpf/verifier.c +2 -2
@@ -19121,8 +19146,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		if (prog_extension &&
 		    btf_check_type_match(log, prog, btf, t))
 			return -EINVAL;
-		t = btf_type_by_id(btf, t->type);
-		if (!btf_type_is_func_proto(t))
+		t = btf_attach_func_proto(log, btf, btf_id);
+		if (!t || !btf_type_is_func_proto(t))
 			return -EINVAL;
Quoted 3 lines

Also, why not do it for BPF_TRACE_ITER case as well? I just feel keeping it consistent may outweigh figuring out whether it's necessary in that case or not, etc.

Quoted 7 lines

I mentioned this in the patch description:

The BPF_TRACE_ITER case distills a registered iterator's prototype, and bpf_struct_ops_desc_init() distills the function-pointer members of a struct_ops type. Neither is a kfunc, and so can't have implicit arguments.

Yeah, I saw that, but abstracting that inside the function and not having to think from the caller about those details would be better. That said, I don't have any strong preference, it is obviously correct as it is.

Quoted 8 lines
Quoted 4 lines

Please supply a cover letter in the next version too since you're sending multiple patches.

I used the first patch's message as a cover letter, since it's just a fix + selftest pair.

Quoted 8 lines

The series could be split further into refactoring changes, but I thought it'll be easier to backport if the fix is in a single self-contained patch.

I think we want the fix to get into 7.2, and backport it to 7.1.

If it's ok to carry separate refactoring patches there, then I'll split. Kartikeya, wdyt?

You can still keep the patches as is, but just add a cover letter, it will not affect backporting. The cover letter is just to summarize the series and the fix in the merge commit. Also, my understanding is that with the Fixes: tag, it should automatically be picked up for stable kernels.

author reviewer
#7 lore raw
Quoted 17 lines · Kumar Kartikeya Dwivedi
Quoted 8 lines · Ihor Solodrai
Quoted 5 lines · Kumar Kartikeya Dwivedi

[...]

Also, why not do it for BPF_TRACE_ITER case as well? I just feel keeping it consistent may outweigh figuring out whether it's necessary in that case or not, etc.

Quoted 7 lines

I mentioned this in the patch description:

The BPF_TRACE_ITER case distills a registered iterator's prototype, and bpf_struct_ops_desc_init() distills the function-pointer members of a struct_ops type. Neither is a kfunc, and so can't have implicit arguments.

Quoted 3 lines

Yeah, I saw that, but abstracting that inside the function and not having to think from the caller about those details would be better. That said, I don't have any strong preference, it is obviously correct as it is.

Let's keep the fix patch minimal. I think we can do a more thoughtful refactoring as a follow up for bpf-next. Hopefully I'll find time for this in not so distant future.

Just sent a v2 with a module ref fix and a brief cover.

Quoted 22 lines
Quoted 9 lines
Quoted 5 lines

Please supply a cover letter in the next version too since you're sending multiple patches.

I used the first patch's message as a cover letter, since it's just a fix + selftest pair.

Quoted 8 lines

The series could be split further into refactoring changes, but I thought it'll be easier to backport if the fix is in a single self-contained patch.

I think we want the fix to get into 7.2, and backport it to 7.1.

If it's ok to carry separate refactoring patches there, then I'll split. Kartikeya, wdyt?

You can still keep the patches as is, but just add a cover letter, it will not affect backporting. The cover letter is just to summarize the series and the fix in the merge commit. Also, my understanding is that with the Fixes: tag, it should automatically be picked up for stable kernels.