From: sashiko-bot@kernel.org
To: "Hui Zhu" <hui.zhu@linux.dev>
Cc: tj@kernel.org, bpf@vger.kernel.org, mkoutny@suse.com, hannes@cmpxchg.org
Subject: Re: [RFC PATCH bpf-next v7 03/11] libbpf: fix return value on memory allocation failure
Date: Tue, 26 May 2026 02:41:44 +0000 [thread overview]
Message-ID: <20260526024145.5309F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <8bfb7027abcc02c21db565cf52d6af78a6ce5b7d.1779760876.git.zhuhui@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] bpf_map__attach_struct_ops() and bpf_map__init_kern_struct_ops() can dereference a NULL map->st_ops pointer if the map type is manually set to BPF_MAP_TYPE_STRUCT_OPS or maliciously defined in an ELF file.
--
commit c643fee98cc31443df8f0acc1fcfd6c87f93a4f8
Author: Roman Gushchin <roman.gushchin@linux.dev>
libbpf: fix return value on memory allocation failure
This commit fixes the return value of bpf_map__attach_struct_ops() to
correctly return -ENOMEM instead of -EINVAL when memory allocation for
the link structure fails.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -13701,7 +13701,7 @@ struct bpf_link *bpf_map__attach_struct_ops(const struct bpf_map *map)
>
> link = calloc(1, sizeof(*link));
> if (!link)
> - return libbpf_err_ptr(-EINVAL);
> + return libbpf_err_ptr(-ENOMEM);
>
> /* kern_vdata should be prepared during the loading phase. */
> err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0);
[Severity: High]
This is a pre-existing issue, but can this dereference a NULL map->st_ops
pointer?
If a user manually changes a map's type to BPF_MAP_TYPE_STRUCT_OPS using
bpf_map__set_type(), or if a malformed BPF object file defines a map in the
.maps section with this type, map->st_ops is never allocated.
The bpf_object_init_struct_ops() function only allocates st_ops for maps
found in the .struct_ops and .struct_ops.link sections.
Because bpf_map__is_struct_ops() only checks map->def.type, could a missing
NULL check on map->st_ops here and in bpf_map__init_kern_struct_ops() lead
to a crash when privileged daemons parse untrusted BPF ELF files?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1779760876.git.zhuhui@kylinos.cn?part=3
next prev parent reply other threads:[~2026-05-26 2:41 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 2:20 [RFC PATCH bpf-next v7 00/11] mm: BPF struct_ops for dynamic memory protection and async reclaim Hui Zhu
2026-05-26 2:20 ` [RFC PATCH bpf-next v7 01/11] bpf: move bpf_struct_ops_link into bpf.h Hui Zhu
2026-05-26 2:20 ` [RFC PATCH bpf-next v7 02/11] bpf: allow attaching struct_ops to cgroups Hui Zhu
2026-05-26 3:00 ` sashiko-bot
2026-05-26 3:19 ` bot+bpf-ci
2026-05-26 2:20 ` [RFC PATCH bpf-next v7 03/11] libbpf: fix return value on memory allocation failure Hui Zhu
2026-05-26 2:41 ` sashiko-bot [this message]
2026-05-26 3:06 ` bot+bpf-ci
2026-05-26 2:20 ` [RFC PATCH bpf-next v7 04/11] libbpf: introduce bpf_map__attach_struct_ops_opts() Hui Zhu
2026-05-26 2:58 ` sashiko-bot
2026-05-26 3:06 ` bot+bpf-ci
2026-05-27 15:43 ` Yonghong Song
2026-05-28 5:53 ` Leon Hwang
2026-05-26 2:20 ` [RFC PATCH bpf-next v7 05/11] bpf: Pass flags in bpf_link_create for struct_ops Hui Zhu
2026-05-26 3:04 ` sashiko-bot
2026-05-26 2:24 ` [RFC PATCH bpf-next v7 06/11] mm: memcontrol: Add BPF struct_ops for memory controller Hui Zhu
2026-05-26 3:04 ` sashiko-bot
2026-05-26 3:19 ` bot+bpf-ci
2026-05-26 2:24 ` [RFC PATCH bpf-next v7 07/11] mm/bpf: Add bpf_try_to_free_mem_cgroup_pages kfunc Hui Zhu
2026-05-26 2:52 ` sashiko-bot
2026-05-26 3:06 ` bot+bpf-ci
2026-05-26 2:24 ` [RFC PATCH bpf-next v7 08/11] selftests/bpf: Add tests for memcg_bpf_ops Hui Zhu
2026-05-26 2:50 ` sashiko-bot
2026-05-26 2:27 ` [RFC PATCH bpf-next v7 09/11] selftests/bpf: Add test for memcg_bpf_ops hierarchies Hui Zhu
2026-05-26 2:52 ` sashiko-bot
2026-05-26 2:27 ` [RFC PATCH bpf-next v7 10/11] selftests/bpf: Add selftest for memcg async reclaim via BPF Hui Zhu
2026-05-26 3:06 ` sashiko-bot
2026-05-26 3:06 ` bot+bpf-ci
2026-05-26 2:27 ` [RFC PATCH bpf-next v7 11/11] samples/bpf: Add memcg priority control and async reclaim example Hui Zhu
2026-05-26 3:10 ` sashiko-bot
2026-05-26 13:41 ` [RFC PATCH bpf-next v7 00/11] mm: BPF struct_ops for dynamic memory protection and async reclaim Usama Arif
2026-05-27 9:31 ` teawater
2026-05-27 8:47 ` Michal Hocko
2026-05-28 8:27 ` teawater
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=20260526024145.5309F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hui.zhu@linux.dev \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@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