From: sashiko-bot@kernel.org
To: "Zhen Ni" <zhen.ni@easystack.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6/6] selftests/bpf: add tests for the page_owner bpf_iter target
Date: Fri, 09 Oct 2026 12:50:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-165565@kernel.org> (raw)
In-Reply-To: <20261009112308.240769-7-zhen.ni@easystack.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: missing __sz suffix in kfunc buffer size parameters bypasses verifier bounds check
--
commit 40eb734de063d435912cf0b8932fbb912e64be44
Author: Zhen Ni <zhen.ni@easystack.cn>
selftests/bpf: add tests for the page_owner bpf_iter target
This commit adds a sleepable BPF program and a userspace runner to test the
page_owner BPF iterator. It exercises the seq_file and open-coded iterator
paths and verifies the contracts of the get_nid, stack_snprint, and
get_memcg_info kfuncs.
> diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_page_owner.c b/tools/testing/selftests/bpf/progs/bpf_iter_page_owner.c
> new file mode 100644
> index 0000000000000..fada6a314a157
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/bpf_iter_page_owner.c
[ ... ]
> +extern int bpf_iter_page_owner_new(struct bpf_iter_page_owner *it) __ksym;
> +extern struct page_owner_scan *
> +bpf_iter_page_owner_next(struct bpf_iter_page_owner *it) __ksym;
> +extern void bpf_iter_page_owner_destroy(struct bpf_iter_page_owner *it) __ksym;
> +extern int bpf_page_owner_stack_snprint(depot_stack_handle_t handle,
> + char *buf, u32 buf_size) __ksym;
> +extern int bpf_page_owner_get_nid(struct page_owner_scan *scan) __ksym;
> +extern int bpf_page_owner_get_memcg_info(struct page_owner_scan *scan,
> + struct memcg_info *info,
> + char *buf, u32 size) __ksym;
[Severity: High]
Does the kfunc ABI exercised here bypass verifier memory bounds checking?
The BPF verifier requires size parameters for memory buffers in kfuncs to be
explicitly annotated with a __sz or __szk suffix (e.g., buf__sz). Without this
suffix, the verifier treats the size parameter as an independent scalar and
enforces no relationship between it and the buffer pointer.
In mm/page_owner_iter.c (which this newly added test relies upon), the kfuncs
bpf_page_owner_stack_snprint and bpf_page_owner_get_memcg_info define
buffer size arguments as u32 buf_size and u32 size, respectively, omitting
the required suffix:
mm/page_owner_iter.c:bpf_page_owner_stack_snprint()
__bpf_kfunc int bpf_page_owner_stack_snprint(depot_stack_handle_t handle,
char *buf, u32 buf_size)
mm/page_owner_iter.c:bpf_page_owner_get_memcg_info()
__bpf_kfunc int bpf_page_owner_get_memcg_info(struct page_owner_scan *scan,
struct memcg_info *info,
char *buf, u32 size)
Consequently, the verifier only validates that buf points to a 1-byte valid
memory region (based on the char type) while allowing arbitrarily large scalar
values to be passed as the size.
A BPF program could exploit this by providing a small buffer alongside a large
size argument, causing the underlying kernel functions (stack_depot_snprint
and get_page_memcg_info) to write past the bounds of the provided buffer,
potentially leading to kernel memory corruption.
Could these kfunc size arguments in the kernel be renamed to include the __sz
suffix to ensure proper verifier bounds checking?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009112308.240769-1-zhen.ni@easystack.cn?part=6
next prev parent reply other threads:[~2026-10-09 12:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 11:23 [PATCH 0/6] mm/page_owner: add bpf_iter and kfuncs Zhen Ni
2026-10-09 11:23 ` [PATCH 2/6] mm/page_owner: add bpf_iter target "page_owner" Zhen Ni
2026-10-09 11:50 ` sashiko-bot
2026-10-12 6:28 ` zhen.ni
2026-10-09 11:23 ` [PATCH 3/6] mm/page_owner: add open-coded page_owner iterator Zhen Ni
2026-10-09 12:00 ` sashiko-bot
2026-10-12 6:41 ` zhen.ni
2026-10-09 11:23 ` [PATCH 4/6] mm/page_owner: add bpf_page_owner_get_nid() kfunc Zhen Ni
2026-10-09 12:20 ` sashiko-bot
2026-10-12 7:01 ` zhen.ni
2026-10-09 11:23 ` [PATCH 5/6] mm/page_owner: add bpf_page_owner_get_memcg_info() kfunc Zhen Ni
2026-10-09 12:43 ` sashiko-bot
2026-10-12 7:09 ` zhen.ni
2026-10-09 11:23 ` [PATCH 6/6] selftests/bpf: add tests for the page_owner bpf_iter target Zhen Ni
2026-10-09 12:50 ` sashiko-bot [this message]
2026-10-12 7:15 ` zhen.ni
2026-10-09 13:48 ` bot+bpf-ci
[not found] ` <20261009112308.240769-2-zhen.ni@easystack.cn>
2026-10-09 11:35 ` [PATCH 1/6] mm/page_owner: extract page_owner_next_eligible() from read loop sashiko-bot
2026-10-10 9:40 ` zhen.ni
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=sashiko-outbox-165565@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhen.ni@easystack.cn \
/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