From: sashiko-bot@kernel.org
To: "Hui Su" <sh_def@163.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf: bound resizable hash map iteration
Date: Fri, 28 Aug 2026 18:46:35 +0000 [thread overview]
Message-ID: <20260828184636.1C6F21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828183326.3330530-1-sh_def@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The iteration budget `map->max_entries` is insufficient to prevent severe RCU stalls because RHASH maps decouple `max_entries` from memory constraints.
--
commit e7196eb4e04d6b29df6a798ca5bcbe264c41d6e2
Author: Hui Su <sh_def@163.com>
bpf: bound resizable hash map iteration
This patch attempts to fix an unbounded iteration loop in bpf_each_rhash_elem
by using map->max_entries as an iteration budget. Duplicate visits consume the
budget to ensure termination under concurrent mutations.
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index d40cb5dd446ca..3772e63f2f12f 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
[ ... ]
> @@ -3212,7 +3212,8 @@ static long bpf_each_rhash_elem(struct bpf_map *map, bpf_callback_t callback_fn,
> * elements are deleted/inserted, there may be missed or duplicate
> * elements visited.
> */
> - while ((elem = rhashtable_next_key(&rhtab->ht, prev_key))) {
> + while (num_elems < map->max_entries &&
> + (elem = rhashtable_next_key(&rhtab->ht, prev_key))) {
[Severity: High]
This is a pre-existing issue, but will this bound be sufficient to prevent
RCU stalls if max_entries is set to its maximum limit?
For a BPF_MAP_TYPE_RHASH map, max_entries can be up to 1UL << 31
(2.14 billion) because the map requires BPF_F_NO_PREALLOC. This decouples
max_entries from memory constraints, meaning a user can instantly create a
map with the maximum limit using negligible memory.
If a user invokes the bpf_for_each_map_elem helper on this map while
concurrently mutating it from user space, the loop could repeatedly yield
duplicate elements.
Executing this callback 2.14 billion times inside an rcu_read_lock section
without cond_resched() will still take dozens of seconds. This easily
eclipses the standard 21-second RCU stall or 20-second soft lockup
thresholds, allowing a Denial of Service.
Could a smaller, fixed iteration limit or a time-based check be used here
instead to ensure the loop terminates before a stall occurs?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828183326.3330530-1-sh_def@163.com?part=1
prev parent reply other threads:[~2026-08-28 18:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 18:33 [PATCH bpf 1/2] bpf: bound resizable hash map iteration Hui Su
2026-08-28 18:33 ` [PATCH bpf 2/2] selftests/bpf: add RHASH iteration stress test Hui Su
2026-08-28 19:20 ` bot+bpf-ci
2026-08-28 18:46 ` sashiko-bot [this message]
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=20260828184636.1C6F21F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sh_def@163.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.