The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Ma Ke <make24@iscas.ac.cn>,
	andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org,
	daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, delyank@fb.com
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] libbpf: check the btf_type kind to prevent error
Date: Tue, 6 Aug 2024 10:38:14 -0700	[thread overview]
Message-ID: <57d88cd3-3cbc-4d30-be82-92990a7a50fd@linux.dev> (raw)
In-Reply-To: <20240806105142.2420140-1-make24@iscas.ac.cn>


On 8/6/24 3:51 AM, Ma Ke wrote:
> To prevent potential error return values, it is necessary to check the
> return value of btf__type_by_id. We can add a kind checking to fix the
> issue.
>
> Cc: stable@vger.kernel.org
> Fixes: 430025e5dca5 ("libbpf: Add subskeleton scaffolding")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>   tools/lib/bpf/libbpf.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index a3be6f8fac09..d1eb45d16054 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -13850,6 +13850,9 @@ int bpf_object__open_subskeleton(struct bpf_object_subskeleton *s)
>   		var = btf_var_secinfos(map_type);
>   		for (i = 0; i < len; i++, var++) {
>   			var_type = btf__type_by_id(btf, var->type);
> +			if (!var_type)
> +				return libbpf_err(-ENOENT);

Could you give a detailed example when this error could be triggered?

> +
>   			var_name = btf__name_by_offset(btf, var_type->name_off);
>   			if (strcmp(var_name, var_skel->name) == 0) {
>   				*var_skel->addr = map->mmaped + var->offset;

  parent reply	other threads:[~2024-08-06 17:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 10:51 [PATCH] libbpf: check the btf_type kind to prevent error Ma Ke
2024-08-06 11:24 ` Jiri Olsa
2024-08-06 17:38 ` Yonghong Song [this message]
2024-08-06 19:46   ` Eduard Zingerman

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=57d88cd3-3cbc-4d30-be82-92990a7a50fd@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=delyank@fb.com \
    --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=make24@iscas.ac.cn \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    /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