BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Hou Tao <houtao@huaweicloud.com>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <martin.lau@linux.dev>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Hao Luo <haoluo@google.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	Daniel Borkmann <daniel@iogearbox.net>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Amery Hung <amery.hung@bytedance.com>,
	Dave Marchevsky <davemarchevsky@fb.com>,
	houtao1@huawei.com, xukuohai@huawei.com
Subject: Re: [PATCH bpf-next 2/2] bpf: Call the missed kfree() when there is no special field in btf
Date: Thu, 12 Sep 2024 09:53:20 +0200	[thread overview]
Message-ID: <ZuKd8B6NTFVBsxDM@krava> (raw)
In-Reply-To: <20240912012845.3458483-3-houtao@huaweicloud.com>

On Thu, Sep 12, 2024 at 09:28:45AM +0800, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
> 
> Call the missed kfree() in btf_parse_struct_metas() when there is no
> special field in btf, otherwise will get the following kmemleak report:
> 
> unreferenced object 0xffff888101033620 (size 8):
>   comm "test_progs", pid 604, jiffies 4295127011
>   ......
>   backtrace (crc e77dc444):
>     [<00000000186f90f3>] kmemleak_alloc+0x4b/0x80
>     [<00000000ac8e9c4d>] __kmalloc_cache_noprof+0x2a1/0x310
>     [<00000000d99d68d6>] btf_new_fd+0x72d/0xe90
>     [<00000000f010b7f8>] __sys_bpf+0xec3/0x2410
>     [<00000000e077ed6f>] __x64_sys_bpf+0x1f/0x30
>     [<00000000a12f9e55>] x64_sys_call+0x199/0x9f0
>     [<00000000f3029ea6>] do_syscall_64+0x3b/0xc0
>     [<000000005640913a>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
> 
> Fixes: 7a851ecb1806 ("bpf: Search for kptrs in prog BTF structs")
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  kernel/bpf/btf.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 59b4f7265761..31eae516f701 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -5572,8 +5572,10 @@ btf_parse_struct_metas(struct bpf_verifier_log *log, struct btf *btf)
>  		aof->ids[aof->cnt++] = i;
>  	}

I was wondering we could get away without the initial kmalloc and
let the first krealoc do the first allocation, but it might need
some other extra checks, so not sure it's worth it

in any case this lgtm

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

>  
> -	if (!aof->cnt)
> +	if (!aof->cnt) {
> +		kfree(aof);
>  		return NULL;
> +	}
>  	sort(&aof->ids, aof->cnt, sizeof(aof->ids[0]), btf_id_cmp_func, NULL);
>  
>  	for (i = 1; i < n; i++) {
> -- 
> 2.29.2
> 

  reply	other threads:[~2024-09-12  7:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12  1:28 [PATCH bpf-next 0/2] Two tiny fixes for btf record Hou Tao
2024-09-12  1:28 ` [PATCH bpf-next 1/2] bpf: Call the missed btf_record_free() when map creation fails Hou Tao
2024-09-12  7:55   ` Jiri Olsa
2024-09-12  1:28 ` [PATCH bpf-next 2/2] bpf: Call the missed kfree() when there is no special field in btf Hou Tao
2024-09-12  7:53   ` Jiri Olsa [this message]
2024-09-14  0:00 ` [PATCH bpf-next 0/2] Two tiny fixes for btf record 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=ZuKd8B6NTFVBsxDM@krava \
    --to=olsajiri@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=amery.hung@bytedance.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=houtao1@huawei.com \
    --cc=houtao@huaweicloud.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=xukuohai@huawei.com \
    --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