From: sashiko-bot@kernel.org
To: chenyuan_fl@163.com
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure
Date: Mon, 10 Aug 2026 14:04:28 +0000 [thread overview]
Message-ID: <20260810140429.531211F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810134800.2875487-2-chenyuan_fl@163.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] range_tree_set() modifies the interval tree before attempting a fallible allocation, leaving the tree in a corrupted state on OOM, similar to the bug fixed in range_tree_clear().
- [High] Transient NOWAIT allocation failure in range_tree_clear() causes arena_vm_fault() to trigger a fatal SIGSEGV.
--
--- Patch [1]: [PATCH bpf-next v3 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure ---
commit 944fb15c800d7e3cba4552c75753fe7038ce96ab
Author: Yuan Chen <chenyuan@kylinos.cn>
bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure
range_tree_clear() pre-allocates the right-half node before modifying
the tree, so an allocation failure returns -ENOMEM without altering the
range tree.
> diff --git a/kernel/bpf/range_tree.c b/kernel/bpf/range_tree.c
> index 2f28886f3ff75..15b588377a769 100644
> --- a/kernel/bpf/range_tree.c
> +++ b/kernel/bpf/range_tree.c
> @@ -143,16 +143,22 @@ int range_tree_clear(struct range_tree *rt, u32 start, u32 len)
> if (rn->rn_start < start && rn->rn_last > last) {
> u32 old_last = rn->rn_last;
>
> + /*
> + * Pre-allocate the right-half node before modifying
> + * the tree. If allocation fails we return -ENOMEM
> + * without altering the range tree.
> + */
> + new_rn = kmalloc_nolock(sizeof(struct range_node),
> + __GFP_ACCOUNT, NUMA_NO_NODE);
> + if (!new_rn)
> + return -ENOMEM;
[Severity: High]
This isn't a bug introduced by this patch, but does range_tree_set() suffer
from this exact same problem?
Looking at range_tree_set() in kernel/bpf/range_tree.c:
range_tree_clear(rt, start, len);
...
left = kmalloc_nolock(sizeof(struct range_node),
__GFP_ACCOUNT, NUMA_NO_NODE);
if (!left)
return -ENOMEM;
It modifies the tree by calling range_tree_clear() first, and then can fail
its allocation. If arena_free_pages() calls range_tree_set() to return slots
and it fails here, the slots seem to be silently and permanently leaked since
the return value is ignored.
Could we apply this same pre-allocation pattern to range_tree_set() as well?
[Severity: High]
This is another pre-existing issue, but does returning -ENOMEM from here
cause unexpected crashes in user space?
Looking at arena_vm_fault() in kernel/bpf/arena.c:
ret = range_tree_clear(&arena->rt, vmf->pgoff, 1);
if (ret)
goto out_sigsegv_memcg;
Since arena_vm_fault() handles page faults under a raw spinlock with IRQs
disabled, this kmalloc_nolock() acts as a GFP_NOWAIT allocation. If it fails
under memory pressure, it returns -ENOMEM, which arena_vm_fault() then
translates into VM_FAULT_SIGSEGV.
This causes the faulting user application to be randomly killed with a
segmentation fault rather than retrying or returning OOM.
Could this error handling be improved to avoid crashing the task?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810134800.2875487-1-chenyuan_fl@163.com?part=1
next prev parent reply other threads:[~2026-08-10 14:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 13:47 [PATCH bpf-next v3 0/3] bpf, arena: fix range_tree consistency on allocation failure chenyuan_fl
2026-08-10 13:47 ` [PATCH bpf-next v3 1/3] bpf, arena: fix range_tree_clear inconsistency on kmalloc_nolock failure chenyuan_fl
2026-08-10 14:04 ` sashiko-bot [this message]
2026-08-10 13:47 ` [PATCH bpf-next v3 2/3] bpf, arena: fix range_tree_set " chenyuan_fl
2026-08-10 15:10 ` bot+bpf-ci
2026-08-10 13:48 ` [PATCH bpf-next v3 3/3] bpf, arena: check range_tree_set return in arena_free_pages and arena_free_worker chenyuan_fl
2026-08-10 14:08 ` sashiko-bot
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=20260810140429.531211F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan_fl@163.com \
--cc=sashiko-reviews@lists.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