* [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id
@ 2022-08-03 16:32 Stanislav Fomichev
2022-08-03 16:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf Stanislav Fomichev
0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2022-08-03 16:32 UTC (permalink / raw)
To: bpf
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, Martin KaFai Lau
When attaching to program, the program itself might not be attached
to anything (and, hence, might not have attach_btf), so we can't
unconditionally use 'prog->aux->dst_prog->aux->attach_btf'.
Instead, use bpf_prog_get_target_btf to pick proper target btf:
* when attached to dst_prog, use dst_prog->aux->btf
* when attached to kernel btf, use prog->aux->attach_btf
Fixes: b79c9fc9551b ("bpf: implement BPF_PROG_QUERY for BPF_LSM_CGROUP")
Acked-by: Hao Luo <haoluo@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
kernel/bpf/syscall.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 83c7136c5788..7dc3f8003631 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3886,6 +3886,7 @@ static int bpf_prog_get_info_by_fd(struct file *file,
union bpf_attr __user *uattr)
{
struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info);
+ struct btf *attach_btf = bpf_prog_get_target_btf(prog);
struct bpf_prog_info info;
u32 info_len = attr->info.info_len;
struct bpf_prog_kstats stats;
@@ -4088,10 +4089,8 @@ static int bpf_prog_get_info_by_fd(struct file *file,
if (prog->aux->btf)
info.btf_id = btf_obj_id(prog->aux->btf);
info.attach_btf_id = prog->aux->attach_btf_id;
- if (prog->aux->attach_btf)
- info.attach_btf_obj_id = btf_obj_id(prog->aux->attach_btf);
- else if (prog->aux->dst_prog)
- info.attach_btf_obj_id = btf_obj_id(prog->aux->dst_prog->aux->attach_btf);
+ if (attach_btf)
+ info.attach_btf_obj_id = btf_obj_id(attach_btf);
ulen = info.nr_func_info;
info.nr_func_info = prog->aux->func_info_cnt;
--
2.37.1.455.g008518b4e5-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf
2022-08-03 16:32 [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id Stanislav Fomichev
@ 2022-08-03 16:32 ` Stanislav Fomichev
2022-08-03 16:51 ` Martin KaFai Lau
0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2022-08-03 16:32 UTC (permalink / raw)
To: bpf
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa
Apparently, no existing selftest covers it. Add a new one where
we load cgroup/bind4 program and attach fentry to it.
Calling bpf_obj_get_info_by_fd on the fentry program
should return non-zero btf_id/btf_obj_id instead of crashing the kernel.
v3:
- move into fexit_bpf2bpf.c (Martin)
- assert on skel->links.bind_v4_prog (Andrii)
- do no close(-1) unconditionally (Andrii)
v2:
- use ret instead of err in find_prog_btf_id (Hao)
- remove verifier log (Hao)
- drop if conditional from ASSERT_OK(bpf_obj_get_info_by_fd(...)) (Hao)
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
.../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 95 +++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
index 02bb8cbf9194..fb62cef35e42 100644
--- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
@@ -3,6 +3,7 @@
#include <test_progs.h>
#include <network_helpers.h>
#include <bpf/btf.h>
+#include "bind4_prog.skel.h"
typedef int (*test_cb)(struct bpf_object *obj);
@@ -407,6 +408,98 @@ static void test_func_replace_global_func(void)
prog_name, false, NULL);
}
+static int find_prog_btf_id(const char *name, __u32 attach_prog_fd)
+{
+ struct bpf_prog_info info = {};
+ __u32 info_len = sizeof(info);
+ struct btf *btf;
+ int ret;
+
+ ret = bpf_obj_get_info_by_fd(attach_prog_fd, &info, &info_len);
+ if (ret)
+ return ret;
+
+ if (!info.btf_id)
+ return -EINVAL;
+
+ btf = btf__load_from_kernel_by_id(info.btf_id);
+ ret = libbpf_get_error(btf);
+ if (ret)
+ return ret;
+
+ ret = btf__find_by_name_kind(btf, name, BTF_KIND_FUNC);
+ btf__free(btf);
+ return ret;
+}
+
+static int load_fentry(int attach_prog_fd, int attach_btf_id)
+{
+ LIBBPF_OPTS(bpf_prog_load_opts, opts,
+ .expected_attach_type = BPF_TRACE_FENTRY,
+ .attach_prog_fd = attach_prog_fd,
+ .attach_btf_id = attach_btf_id,
+ );
+ struct bpf_insn insns[] = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ };
+
+ return bpf_prog_load(BPF_PROG_TYPE_TRACING,
+ "bind4_fentry",
+ "GPL",
+ insns,
+ ARRAY_SIZE(insns),
+ &opts);
+}
+
+static void test_fentry_to_cgroup_bpf(void)
+{
+ struct bind4_prog *skel = NULL;
+ struct bpf_prog_info info = {};
+ __u32 info_len = sizeof(info);
+ int cgroup_fd = -1;
+ int fentry_fd = -1;
+ int btf_id;
+
+ cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
+ if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
+ return;
+
+ skel = bind4_prog__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "skel"))
+ goto cleanup;
+
+ skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
+ if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
+ goto cleanup;
+
+ btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
+ if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
+ goto cleanup;
+
+ fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
+ if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
+ goto cleanup;
+
+ /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
+ * to another BPF program.
+ */
+
+ ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
+ "bpf_obj_get_info_by_fd");
+
+ ASSERT_EQ(info.btf_id, 0, "info.btf_id");
+ ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
+ ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
+
+cleanup:
+ if (cgroup_fd >= 0)
+ close(cgroup_fd);
+ if (fentry_fd >= 0)
+ close(fentry_fd);
+ bind4_prog__destroy(skel);
+}
+
/* NOTE: affect other tests, must run in serial mode */
void serial_test_fexit_bpf2bpf(void)
{
@@ -430,4 +523,6 @@ void serial_test_fexit_bpf2bpf(void)
test_fmod_ret_freplace();
if (test__start_subtest("func_replace_global_func"))
test_func_replace_global_func();
+ if (test__start_subtest("fentry_to_cgroup_bpf"))
+ test_fentry_to_cgroup_bpf();
}
--
2.37.1.455.g008518b4e5-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf
2022-08-03 16:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf Stanislav Fomichev
@ 2022-08-03 16:51 ` Martin KaFai Lau
2022-08-03 17:10 ` Stanislav Fomichev
0 siblings, 1 reply; 7+ messages in thread
From: Martin KaFai Lau @ 2022-08-03 16:51 UTC (permalink / raw)
To: Stanislav Fomichev
Cc: bpf, ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, haoluo, jolsa
On Wed, Aug 03, 2022 at 09:32:23AM -0700, Stanislav Fomichev wrote:
> +static void test_fentry_to_cgroup_bpf(void)
> +{
> + struct bind4_prog *skel = NULL;
> + struct bpf_prog_info info = {};
> + __u32 info_len = sizeof(info);
> + int cgroup_fd = -1;
> + int fentry_fd = -1;
> + int btf_id;
> +
> + cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
> + if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
> + return;
> +
> + skel = bind4_prog__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel"))
> + goto cleanup;
> +
> + skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
> + if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
> + goto cleanup;
> +
> + btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
> + if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
> + goto cleanup;
> +
> + fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
> + if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
> + goto cleanup;
> +
> + /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
> + * to another BPF program.
> + */
> +
> + ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
> + "bpf_obj_get_info_by_fd");
> +
> + ASSERT_EQ(info.btf_id, 0, "info.btf_id");
> + ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
> + ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
nit. This can check against btf_id.
Overall lgtm. Thanks.
Acked-by: Martin KaFai Lau <kafai@fb.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf
2022-08-03 16:51 ` Martin KaFai Lau
@ 2022-08-03 17:10 ` Stanislav Fomichev
2022-08-03 17:19 ` Martin KaFai Lau
0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2022-08-03 17:10 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: bpf, ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, haoluo, jolsa
On Wed, Aug 3, 2022 at 9:51 AM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Wed, Aug 03, 2022 at 09:32:23AM -0700, Stanislav Fomichev wrote:
> > +static void test_fentry_to_cgroup_bpf(void)
> > +{
> > + struct bind4_prog *skel = NULL;
> > + struct bpf_prog_info info = {};
> > + __u32 info_len = sizeof(info);
> > + int cgroup_fd = -1;
> > + int fentry_fd = -1;
> > + int btf_id;
> > +
> > + cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
> > + if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
> > + return;
> > +
> > + skel = bind4_prog__open_and_load();
> > + if (!ASSERT_OK_PTR(skel, "skel"))
> > + goto cleanup;
> > +
> > + skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
> > + if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
> > + goto cleanup;
> > +
> > + btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
> > + if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
> > + goto cleanup;
> > +
> > + fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
> > + if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
> > + goto cleanup;
> > +
> > + /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
> > + * to another BPF program.
> > + */
> > +
> > + ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
> > + "bpf_obj_get_info_by_fd");
> > +
> > + ASSERT_EQ(info.btf_id, 0, "info.btf_id");
> > + ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
> > + ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
> nit. This can check against btf_id.
As in ASSERT_NEQ(info.attach_btf_obj_id, info.btf_id,
"info.attach_btf_obj_id") ?
> Overall lgtm. Thanks.
>
> Acked-by: Martin KaFai Lau <kafai@fb.com>
Thank you for the review!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf
2022-08-03 17:10 ` Stanislav Fomichev
@ 2022-08-03 17:19 ` Martin KaFai Lau
2022-08-03 18:27 ` Stanislav Fomichev
0 siblings, 1 reply; 7+ messages in thread
From: Martin KaFai Lau @ 2022-08-03 17:19 UTC (permalink / raw)
To: Stanislav Fomichev
Cc: bpf, ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, haoluo, jolsa
On Wed, Aug 03, 2022 at 10:10:33AM -0700, Stanislav Fomichev wrote:
> On Wed, Aug 3, 2022 at 9:51 AM Martin KaFai Lau <kafai@fb.com> wrote:
> >
> > On Wed, Aug 03, 2022 at 09:32:23AM -0700, Stanislav Fomichev wrote:
> > > +static void test_fentry_to_cgroup_bpf(void)
> > > +{
> > > + struct bind4_prog *skel = NULL;
> > > + struct bpf_prog_info info = {};
> > > + __u32 info_len = sizeof(info);
> > > + int cgroup_fd = -1;
> > > + int fentry_fd = -1;
> > > + int btf_id;
> > > +
> > > + cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
> > > + if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
> > > + return;
> > > +
> > > + skel = bind4_prog__open_and_load();
> > > + if (!ASSERT_OK_PTR(skel, "skel"))
> > > + goto cleanup;
> > > +
> > > + skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
> > > + if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
> > > + goto cleanup;
> > > +
> > > + btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
> > > + if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
> > > + goto cleanup;
> > > +
> > > + fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
> > > + if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
> > > + goto cleanup;
> > > +
> > > + /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
> > > + * to another BPF program.
> > > + */
> > > +
> > > + ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
> > > + "bpf_obj_get_info_by_fd");
> > > +
> > > + ASSERT_EQ(info.btf_id, 0, "info.btf_id");
> > > + ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
> > > + ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
> > nit. This can check against btf_id.
>
> As in ASSERT_NEQ(info.attach_btf_obj_id, info.btf_id,
> "info.attach_btf_obj_id") ?
Ah, my bad on one line off. I meant the previous line.
ASSERT_NEQ(info.attach_btf_id, btf_id, "info.attach_btf_id");
The bind_v4_prog's btf_obj_id is lost. Otherwise, it could also do
ASSERT_NEQ(info.attach_btf_obj_id, bind_v4_prog_btf_id, "info.attach_btf_obj_id");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf
2022-08-03 17:19 ` Martin KaFai Lau
@ 2022-08-03 18:27 ` Stanislav Fomichev
0 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2022-08-03 18:27 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: bpf, ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, haoluo, jolsa
On Wed, Aug 3, 2022 at 10:19 AM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Wed, Aug 03, 2022 at 10:10:33AM -0700, Stanislav Fomichev wrote:
> > On Wed, Aug 3, 2022 at 9:51 AM Martin KaFai Lau <kafai@fb.com> wrote:
> > >
> > > On Wed, Aug 03, 2022 at 09:32:23AM -0700, Stanislav Fomichev wrote:
> > > > +static void test_fentry_to_cgroup_bpf(void)
> > > > +{
> > > > + struct bind4_prog *skel = NULL;
> > > > + struct bpf_prog_info info = {};
> > > > + __u32 info_len = sizeof(info);
> > > > + int cgroup_fd = -1;
> > > > + int fentry_fd = -1;
> > > > + int btf_id;
> > > > +
> > > > + cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
> > > > + if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
> > > > + return;
> > > > +
> > > > + skel = bind4_prog__open_and_load();
> > > > + if (!ASSERT_OK_PTR(skel, "skel"))
> > > > + goto cleanup;
> > > > +
> > > > + skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
> > > > + if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
> > > > + goto cleanup;
> > > > +
> > > > + btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
> > > > + if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
> > > > + goto cleanup;
> > > > +
> > > > + fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
> > > > + if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
> > > > + goto cleanup;
> > > > +
> > > > + /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
> > > > + * to another BPF program.
> > > > + */
> > > > +
> > > > + ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
> > > > + "bpf_obj_get_info_by_fd");
> > > > +
> > > > + ASSERT_EQ(info.btf_id, 0, "info.btf_id");
> > > > + ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
> > > > + ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
> > > nit. This can check against btf_id.
> >
> > As in ASSERT_NEQ(info.attach_btf_obj_id, info.btf_id,
> > "info.attach_btf_obj_id") ?
> Ah, my bad on one line off. I meant the previous line.
>
> ASSERT_NEQ(info.attach_btf_id, btf_id, "info.attach_btf_id");
Thanks! I'm assuming that I also confused you with that ASSERT_NEQ and
you really meant:
ASSERT_EQ(info.attach_btf_id, btf_id, "info.attach_btf_id");
Will wait for more potential feedback from Hao/Andrii and will try to
respin tomorrow with your suggestion applied.
> The bind_v4_prog's btf_obj_id is lost. Otherwise, it could also do
> ASSERT_NEQ(info.attach_btf_obj_id, bind_v4_prog_btf_id, "info.attach_btf_obj_id");
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id
@ 2022-08-01 17:39 Stanislav Fomichev
0 siblings, 0 replies; 7+ messages in thread
From: Stanislav Fomichev @ 2022-08-01 17:39 UTC (permalink / raw)
To: bpf
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, Martin KaFai Lau
When attaching to program, the program itself might not be attached
to anything (and, hence, might not have attach_btf), so we can't
unconditionally use 'prog->aux->dst_prog->aux->attach_btf'.
Instead, use bpf_prog_get_target_btf to pick proper target btf:
* when attached to dst_prog, use dst_prog->aux->btf
* when attached to kernel btf, use prog->aux->attach_btf
Fixes: b79c9fc9551b ("bpf: implement BPF_PROG_QUERY for BPF_LSM_CGROUP")
Acked-by: Hao Luo <haoluo@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
kernel/bpf/syscall.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 83c7136c5788..7dc3f8003631 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3886,6 +3886,7 @@ static int bpf_prog_get_info_by_fd(struct file *file,
union bpf_attr __user *uattr)
{
struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info);
+ struct btf *attach_btf = bpf_prog_get_target_btf(prog);
struct bpf_prog_info info;
u32 info_len = attr->info.info_len;
struct bpf_prog_kstats stats;
@@ -4088,10 +4089,8 @@ static int bpf_prog_get_info_by_fd(struct file *file,
if (prog->aux->btf)
info.btf_id = btf_obj_id(prog->aux->btf);
info.attach_btf_id = prog->aux->attach_btf_id;
- if (prog->aux->attach_btf)
- info.attach_btf_obj_id = btf_obj_id(prog->aux->attach_btf);
- else if (prog->aux->dst_prog)
- info.attach_btf_obj_id = btf_obj_id(prog->aux->dst_prog->aux->attach_btf);
+ if (attach_btf)
+ info.attach_btf_obj_id = btf_obj_id(attach_btf);
ulen = info.nr_func_info;
info.nr_func_info = prog->aux->func_info_cnt;
--
2.37.1.455.g008518b4e5-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-08-03 18:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 16:32 [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id Stanislav Fomichev
2022-08-03 16:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf Stanislav Fomichev
2022-08-03 16:51 ` Martin KaFai Lau
2022-08-03 17:10 ` Stanislav Fomichev
2022-08-03 17:19 ` Martin KaFai Lau
2022-08-03 18:27 ` Stanislav Fomichev
-- strict thread matches above, loose matches on Subject: below --
2022-08-01 17:39 [PATCH bpf-next v2 1/2] bpf: use proper target btf when exporting attach_btf_obj_id Stanislav Fomichev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.