From: Eduard Zingerman <eddyz87@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>,
acme@kernel.org, jolsa@kernel.org, quentin@isovalent.com,
alan.maguire@oracle.com
Cc: andrii.nakryiko@gmail.com, ast@kernel.org, daniel@iogearbox.net,
bpf@vger.kernel.org
Subject: Re: [PATCH dwarves v8 3/3] pahole: Inject kfunc decl tags into BTF
Date: Fri, 26 Apr 2024 16:47:53 -0700 [thread overview]
Message-ID: <40cce745854cf1fd0ea63b2e636828c87442a21d.camel@gmail.com> (raw)
In-Reply-To: <1f82795e9ae651a3d303d498e2ce71540170b781.1714091281.git.dxu@dxuuu.xyz>
On Thu, 2024-04-25 at 18:28 -0600, Daniel Xu wrote:
> This commit teaches pahole to parse symbols in .BTF_ids section in
> vmlinux and discover exported kfuncs. Pahole then takes the list of
> kfuncs and injects a BTF_KIND_DECL_TAG for each kfunc.
>
> Example of encoding:
>
> $ bpftool btf dump file .tmp_vmlinux.btf | rg "DECL_TAG 'bpf_kfunc'" | wc -l
> 121
>
> $ bpftool btf dump file .tmp_vmlinux.btf | rg 56337
> [56337] FUNC 'bpf_ct_change_timeout' type_id=56336 linkage=static
> [127861] DECL_TAG 'bpf_kfunc' type_id=56337 component_idx=-1
>
> This enables downstream users and tools to dynamically discover which
> kfuncs are available on a system by parsing vmlinux or module BTF, both
> available in /sys/kernel/btf.
>
> This feature is enabled with --btf_features=decl_tag,decl_tag_kfuncs.
>
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> Tested-by: Jiri Olsa <jolsa@kernel.org>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> Tested-by: Alan Maguire <alan.maguire@oracle.com>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
I tested this patch-set on current master with Makefile.btf modified
to have --btf_features=+decl_tag_kfuncs, the tests are passing.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
(But please fix get_func_name...)
[...]
> +static char *get_func_name(const char *sym)
> +{
> + char *func, *end;
> +
> + /* Example input: __BTF_ID__func__vfs_close__1
> + *
> + * The goal is to strip the prefix and suffix such that we only
> + * return vfs_close.
> + */
> +
> + if (!strstarts(sym, BTF_ID_FUNC_PFX))
> + return NULL;
> +
> + /* Strip prefix and handle malformed input such as __BTF_ID__func___ */
> + func = strdup(sym + sizeof(BTF_ID_FUNC_PFX) - 1);
> + if (strlen(func) < 2) {
> + free(func);
> + return NULL;
> + }
> +
> + /* Strip suffix */
> + end = strrchr(func, '_');
> + if (!end || *(end - 1) != '_') {
Sorry, I'm complaining about this silly function again...
This will do an invalid read for input like "__BTF_ID__func___a":
- 'func' would be a result of strdup("_a");
- 'end' would point to the first character of 'func';
- 'end - 1' would point outside of 'func'.
Here is a repro with valgrind report:
https://gist.github.com/eddyz87/dfd653ada6584b7b7563fbfe66355eae
> + free(func);
> + return NULL;
> + }
> + *(end - 1) = '\0';
> +
> + return func;
> +}
[...]
next prev parent reply other threads:[~2024-04-26 23:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 0:28 [PATCH dwarves v8 0/3] pahole: Inject kfunc decl tags into BTF Daniel Xu
2024-04-26 0:28 ` [PATCH dwarves v8 1/3] pahole: Save input filename separate from output Daniel Xu
2024-04-26 0:28 ` [PATCH dwarves v8 2/3] pahole: Add --btf_feature=decl_tag_kfuncs feature Daniel Xu
2024-04-26 0:28 ` [PATCH dwarves v8 3/3] pahole: Inject kfunc decl tags into BTF Daniel Xu
2024-04-26 19:47 ` Eduard Zingerman
2024-04-26 20:55 ` Eduard Zingerman
2024-04-26 23:47 ` Eduard Zingerman [this message]
2024-04-29 22:38 ` Daniel Xu
2024-04-26 9:08 ` [PATCH dwarves v8 0/3] " Jiri Olsa
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=40cce745854cf1fd0ea63b2e636828c87442a21d.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=jolsa@kernel.org \
--cc=quentin@isovalent.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;
as well as URLs for NNTP newsgroup(s).