From: Jiri Olsa <olsajiri@gmail.com>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: bpf@vger.kernel.org, andrii@kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: Re: [PATCH bpf-next] libbpf: Error out when binary_path is NULL for uprobe and USDT
Date: Tue, 12 Jul 2022 09:58:24 +0200 [thread overview]
Message-ID: <Ys0poNMCnkNUQ1VE@krava> (raw)
In-Reply-To: <20220712025745.2703995-1-hengqi.chen@gmail.com>
On Tue, Jul 12, 2022 at 10:57:45AM +0800, Hengqi Chen wrote:
> binary_path is a required non-null parameter for bpf_program__attach_usdt
> and bpf_program__attach_uprobe_opts. Check it against NULL to prevent
> coredump on strchr.
binary_path seems to be mandatory so LGTM, cc-ing Alan to be sure ;-)
thanks,
jirka
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
> tools/lib/bpf/libbpf.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index cb49408eb298..72548798126b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -10545,7 +10545,10 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,
> ref_ctr_off = OPTS_GET(opts, ref_ctr_offset, 0);
> pe_opts.bpf_cookie = OPTS_GET(opts, bpf_cookie, 0);
>
> - if (binary_path && !strchr(binary_path, '/')) {
> + if (!binary_path)
> + return libbpf_err_ptr(-EINVAL);
> +
> + if (!strchr(binary_path, '/')) {
> err = resolve_full_path(binary_path, full_binary_path,
> sizeof(full_binary_path));
> if (err) {
> @@ -10559,11 +10562,6 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,
> if (func_name) {
> long sym_off;
>
> - if (!binary_path) {
> - pr_warn("prog '%s': name-based attach requires binary_path\n",
> - prog->name);
> - return libbpf_err_ptr(-EINVAL);
> - }
> sym_off = elf_find_func_offset(binary_path, func_name);
> if (sym_off < 0)
> return libbpf_err_ptr(sym_off);
> @@ -10711,6 +10709,9 @@ struct bpf_link *bpf_program__attach_usdt(const struct bpf_program *prog,
> return libbpf_err_ptr(-EINVAL);
> }
>
> + if (!binary_path)
> + return libbpf_err_ptr(-EINVAL);
> +
> if (!strchr(binary_path, '/')) {
> err = resolve_full_path(binary_path, resolved_path, sizeof(resolved_path));
> if (err) {
> --
> 2.30.2
next prev parent reply other threads:[~2022-07-12 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 2:57 [PATCH bpf-next] libbpf: Error out when binary_path is NULL for uprobe and USDT Hengqi Chen
2022-07-12 7:58 ` Jiri Olsa [this message]
2022-07-13 18:59 ` Andrii Nakryiko
2022-07-13 19:10 ` patchwork-bot+netdevbpf
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=Ys0poNMCnkNUQ1VE@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hengqi.chen@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 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.