From: sashiko-bot@kernel.org
To: "Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next v2 08/18] bpf: Implement iterator APIs for resizable hashtab
Date: Thu, 13 Aug 2026 23:59:51 +0000 [thread overview]
Message-ID: <20260813235957.0AC751F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260408-rhash-v2-8-3b3675da1f6e@meta.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Uninitialized memory read in `last_key` when `seq_show` overflows.
- [High] `rhashtable_walk_enter_from` resets iterator on deleted cursor key, causing O(N^2) complexity and infinite loops.
- [Medium] Missing __GFP_NOWARN flag in user-controlled kmalloc for map->key_size can lead to OOM splats.
--
--- Patch [8]: [PATCH RFC bpf-next v2 08/18] bpf: Implement iterator APIs for resizable hashtab ---
commit 226ce1988038cf4876ff0a72b5ae8e5ebc263151
Author: Mykyta Yatsenko <yatsenko@meta.com>
bpf: Implement iterator APIs for resizable hashtab
Wire up seq_file BPF iterator for BPF_MAP_TYPE_RHASH so that
bpf_iter and bpftool map dump work with resizable hash maps.
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 4611671bf8e74..5ca4d26e70178 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
[ ... ]
> @@ -3205,36 +3218,113 @@ struct bpf_iter_seq_rhash_map_info {
> struct bpf_map *map;
> struct bpf_rhtab *rhtab;
> struct rhashtable_iter iter;
> - u32 skip_elems;
> + void *last_key;
> bool iter_active;
> };
>
> static void *bpf_rhash_map_seq_start(struct seq_file *seq, loff_t *pos)
> {
> - return NULL;
> + struct bpf_iter_seq_rhash_map_info *info = seq->private;
> + struct rhtab_elem *elem;
> + void *key = *pos > 0 ? info->last_key : NULL;
> +
> + scoped_guard(rcu) {
> + rhashtable_walk_enter_from(&info->rhtab->ht, &info->iter,
> + key, info->rhtab->params);
[Severity: High]
Will this silently restart iteration from bucket 0 if the cursor key is deleted?
rhashtable_walk_enter_from() looks up the provided cursor key to resume
iteration. If the key is missing, it returns early and leaves the iterator at
bucket 0 (iter->slot = 0).
In __rhtab_map_lookup_and_delete_batch(), the batch operation deletes elements
and returns the last deleted key to userspace. On the next batch syscall, the
user passes this deleted key back as the cursor. Since the key no longer
exists, rhashtable_walk_enter_from() resets the iterator to 0.
The inner loop then executes while (total < max_count) holding rcu_read_lock(),
rescanning all previously emptied buckets from the beginning of the table.
For lookup_batch and seq_file iterators, does this yield massive duplicate
outputs to userspace and enormous RCU stall times?
> + rhashtable_walk_start(&info->iter);
> + }
> + info->iter_active = true;
> +
> + elem = rhtab_iter_next(&info->iter);
> + if (!elem)
> + return NULL;
> + /*
> + * if *pos is not 0, previously iteration failed on this elem,
> + * so we are restarting it. That's why no need to increment *pos.
> + */
> + if (*pos == 0)
> + ++*pos;
[Severity: High]
Does this pass uninitialized memory as a hash key if seq_show() output
overflows?
When reading a BPF iterator, seq_read_iter() calls bpf_rhash_map_seq_start(),
which increments *pos from 0 to 1 and returns the first element.
If the output of seq_show() for this element exceeds the initial seq_file
buffer, the buffer overflows. The sequence machinery reallocates a larger
buffer and calls seq_start() again.
Since *pos is now 1, the code executes key = info->last_key. However, last_key
is only populated in seq_next(), which hasn't been called yet. Thus, last_key
remains uninitialized from its kmalloc(..., GFP_USER) allocation.
> + return elem;
> }
[ ... ]
> static int bpf_iter_init_rhash_map(void *priv_data, struct bpf_iter_aux_info *aux)
> {
> + struct bpf_iter_seq_rhash_map_info *info = priv_data;
> + struct bpf_map *map = aux->map;
> +
> + info->last_key = kmalloc(map->key_size, GFP_USER);
[Severity: Medium]
Does this need __GFP_NOWARN?
Since BPF hash map key sizes can be extremely large, requesting large
contiguous memory blocks without __GFP_NOWARN can fail loudly under memory
fragmentation and trigger high-order page allocation warnings.
> + if (!info->last_key)
> + return -ENOMEM;
> +
> + bpf_map_inc_with_uref(map);
> + info->map = map;
> + info->rhtab = container_of(map, struct bpf_rhtab, map);
> + info->iter_active = false;
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260408-rhash-v2-0-3b3675da1f6e@meta.com?part=8
next prev parent reply other threads:[~2026-08-13 23:59 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 15:10 [PATCH RFC bpf-next v2 00/18] bpf: Introduce resizable hash map Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 01/18] bpf: Register rhash map Mykyta Yatsenko
2026-04-10 22:31 ` Emil Tsalapatis
2026-04-13 8:10 ` Mykyta Yatsenko
2026-04-14 17:50 ` Emil Tsalapatis
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 02/18] bpf: Add resizable hashtab skeleton Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 03/18] bpf: Implement lookup, delete, update for resizable hashtab Mykyta Yatsenko
2026-04-12 23:10 ` Alexei Starovoitov
2026-04-13 10:52 ` Mykyta Yatsenko
2026-04-13 16:24 ` Alexei Starovoitov
2026-04-13 16:27 ` Daniel Borkmann
2026-04-13 19:43 ` Mykyta Yatsenko
2026-04-13 20:37 ` Emil Tsalapatis
2026-04-14 8:34 ` Mykyta Yatsenko
2026-04-14 10:25 ` Leon Hwang
2026-04-14 10:28 ` Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 04/18] rhashtable: Add rhashtable_walk_enter_from() Mykyta Yatsenko
2026-04-12 23:13 ` Alexei Starovoitov
2026-04-13 12:22 ` Mykyta Yatsenko
2026-04-13 22:22 ` Emil Tsalapatis
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 05/18] bpf: Implement get_next_key and free_internal_structs for resizable hashtab Mykyta Yatsenko
2026-04-13 22:44 ` Emil Tsalapatis
2026-04-14 8:11 ` Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 06/18] bpf: Implement bpf_each_rhash_elem() using walk API Mykyta Yatsenko
2026-04-13 23:02 ` Emil Tsalapatis
2026-04-24 15:16 ` Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 07/18] bpf: Implement batch ops for resizable hashtab Mykyta Yatsenko
2026-04-13 23:25 ` Emil Tsalapatis
2026-04-14 8:08 ` Mykyta Yatsenko
2026-04-14 17:47 ` Emil Tsalapatis
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 08/18] bpf: Implement iterator APIs " Mykyta Yatsenko
2026-04-14 17:49 ` Emil Tsalapatis
2026-04-15 11:15 ` Mykyta Yatsenko
2026-08-13 23:59 ` sashiko-bot [this message]
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 09/18] bpf: Implement alloc and free " Mykyta Yatsenko
2026-04-12 23:15 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 10/18] bpf: Allow timers, workqueues and task_work in " Mykyta Yatsenko
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 11/18] libbpf: Support resizable hashtable Mykyta Yatsenko
2026-04-14 17:46 ` Emil Tsalapatis
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 12/18] selftests/bpf: Add basic tests for resizable hash map Mykyta Yatsenko
2026-04-12 23:16 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 13/18] selftests/bpf: Support resizable hashtab in test_maps Mykyta Yatsenko
2026-04-12 23:17 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 14/18] selftests/bpf: Resizable hashtab BPF_F_LOCK tests Mykyta Yatsenko
2026-04-12 23:18 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 15/18] selftests/bpf: Add stress tests for resizable hash get_next_key Mykyta Yatsenko
2026-04-12 23:19 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 16/18] selftests/bpf: Add BPF iterator tests for resizable hash map Mykyta Yatsenko
2026-04-12 23:20 ` Alexei Starovoitov
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 17/18] bpftool: Add rhash map documentation Mykyta Yatsenko
2026-04-14 17:51 ` Emil Tsalapatis
2026-04-08 15:10 ` [PATCH RFC bpf-next v2 18/18] selftests/bpf: Add resizable hashmap to benchmarks Mykyta Yatsenko
2026-04-12 23:25 ` Alexei Starovoitov
2026-04-12 23:11 ` [PATCH RFC bpf-next v2 00/18] bpf: Introduce resizable hash map Alexei Starovoitov
2026-04-13 8:28 ` Mykyta Yatsenko
2026-04-15 3:27 ` Herbert Xu
2026-04-15 5:13 ` Alexei Starovoitov
2026-04-16 5:18 ` Herbert Xu
2026-04-16 14:11 ` Alexei Starovoitov
2026-04-16 15:10 ` Mykyta Yatsenko
2026-04-16 15:36 ` Alexei Starovoitov
2026-04-16 16:30 ` Mykyta Yatsenko
2026-04-17 6:54 ` Herbert Xu
2026-04-17 15:16 ` Mykyta Yatsenko
2026-04-18 0:43 ` Herbert Xu
2026-04-20 11:45 ` Mykyta Yatsenko
2026-04-20 15:41 ` Alexei Starovoitov
2026-04-20 15:50 ` Mykyta Yatsenko
2026-04-20 16:06 ` Alexei Starovoitov
2026-04-20 16:37 ` Mykyta Yatsenko
2026-04-20 18:00 ` Alexei Starovoitov
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=20260813235957.0AC751F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=mykyta.yatsenko5@gmail.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 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.