* [PATCH] bpf: Bound the resizable hashtab batch buffers by max_entries
@ 2026-12-02 5:37 Peng Hao
2026-12-02 5:43 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Peng Hao @ 2026-12-02 5:37 UTC (permalink / raw)
To: ast, andrii; +Cc: bpf
__rhtab_map_lookup_and_delete_batch() allocates the key, value and
element pointer buffers for attr->batch.count entries before it looks at
the map. count comes straight from userspace and is not limited by the
size of the map, so a lookup batch on a one-element map with a 4K value
and count = 65536 has the kernel allocate about 257 MB, and
count = 1048576 asks for about 4 GB and fails with -ENOMEM instead of
returning the element.
A batch never returns more than max_entries elements, so clamp the
buffer size to that. The regular hash map sizes its buffers by bucket
size instead, so it doesn't have this problem.
Fixes: 16b4d3e2fb24 ("bpf: Implement resizable hashmap basic functions")
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
kernel/bpf/hashtab.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 6cdd8e1dc2bd..278718d1948b 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -3503,6 +3503,9 @@ static int __rhtab_map_lookup_and_delete_batch(struct bpf_map *map,
if (put_user(0, &uattr->batch.count))
return -EFAULT;
+ /* A batch can't return more elements than the map can hold. */
+ max_count = min(max_count, map->max_entries);
+
key_size = map->key_size;
value_size = map->value_size;
--
2.43.7
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] bpf: Bound the resizable hashtab batch buffers by max_entries
2026-12-02 5:37 [PATCH] bpf: Bound the resizable hashtab batch buffers by max_entries Peng Hao
@ 2026-12-02 5:43 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 5:43 UTC (permalink / raw)
To: Peng Hao; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] bpf: incorrect Fixes tag for
__rhtab_map_lookup_and_delete_batch()
--
commit 9770249174f01abb3a3d1236fe3c14f234ab367c
Author: Peng Hao <flyingpenghao@gmail.com>
> bpf: Bound the resizable hashtab batch buffers by max_entries
>
> __rhtab_map_lookup_and_delete_batch() allocates the key, value and
> element pointer buffers for attr->batch.count entries before it looks at
> the map. count comes straight from userspace and is not limited by the
> size of the map, so a lookup batch on a one-element map with a 4K value
> and count = 65536 has the kernel allocate about 257 MB, and
> count = 1048576 asks for about 4 GB and fails with -ENOMEM instead of
> returning the element.
>
> A batch never returns more than max_entries elements, so clamp the
> buffer size to that. The regular hash map sizes its buffers by bucket
> size instead, so it doesn't have this problem.
>
> Fixes: 16b4d3e2fb24 ("bpf: Implement resizable hashmap basic functions")
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>
[Severity: Low]
__rhtab_map_lookup_and_delete_batch() was introduced in 818e00848227
("bpf: Implement iteration ops for resizable hashtab") rather than
16b4d3e2fb24 ("bpf: Implement resizable hashmap basic functions"). Should
the Fixes tag be updated to:
Fixes: 818e00848227 ("bpf: Implement iteration ops for resizable hashtab")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202053720.92474-1-flyingpeng@tencent.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 5:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 5:37 [PATCH] bpf: Bound the resizable hashtab batch buffers by max_entries Peng Hao
2026-12-02 5:43 ` sashiko-bot
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.