From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Soma Nakata <soma.nakata01@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] libbpf: Initialize st_ops->tname with strdup()
Date: Wed, 21 Aug 2024 09:20:04 +0200 [thread overview]
Message-ID: <66d4df96-3493-4b12-8bd8-e26c42cd342d@wanadoo.fr> (raw)
In-Reply-To: <20240821064632.38716-3-soma.nakata01@gmail.com>
Le 21/08/2024 à 08:46, Soma Nakata a écrit :
> `tname` is returned by `btf__name_by_offset()` as well as `var_name`,
> and these addresses point to strings in the btf. Since their locations
> may change while loading the bpf program, using `strdup()` ensures
> `tname` is safely stored.
>
> Signed-off-by: Soma Nakata <soma.nakata01@gmail.com>
> ---
> tools/lib/bpf/libbpf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index a3be6f8fac09..ece1f1af2cd4 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1423,7 +1423,7 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
> memcpy(st_ops->data,
> data->d_buf + vsi->offset,
> type->size);
> - st_ops->tname = tname;
> + st_ops->tname = strdup(tname);
Hi,
Should a NULL check be added (as done a few lines above for the
[cm]alloc()) and bpf_map__destroy() updated with a
zfree(&map->st_ops->tname) ?
CJ
> st_ops->type = type;
> st_ops->type_id = type_id;
>
next prev parent reply other threads:[~2024-08-21 7:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 6:46 Soma Nakata
2024-08-21 7:20 ` Christophe JAILLET [this message]
2024-08-21 9:04 ` Soma Nakata
2024-08-21 10:53 ` Soma Nakata
2024-08-21 16:48 ` Andrii Nakryiko
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=66d4df96-3493-4b12-8bd8-e26c42cd342d@wanadoo.fr \
--to=christophe.jaillet@wanadoo.fr \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=soma.nakata01@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®