From: sashiko-bot@kernel.org
To: "Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v7 07/12] bpf: Optimize word-sized keys for resizable hashtable
Date: Fri, 05 Jun 2026 11:54:36 +0000 [thread overview]
Message-ID: <20260605115436.C55991F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605-rhash-v7-7-5b8e05f8630d@meta.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The custom hash function `rhtab_hashfn_long` is vulnerable to Hash Denial of Service (HashDoS) because it fails to mix the random seed non-linearly.
- [High] Directly dereferencing potentially unaligned BPF map key pointers causes unaligned memory access faults.
--
commit 376379c40761f9d44cd7e1638b3ca3a7cb1e989b
Author: Mykyta Yatsenko <yatsenko@meta.com>
bpf: Optimize word-sized keys for resizable hashtable
This commit specializes the lookup, update, and delete paths for BPF resizable
hashtables when the key size matches sizeof(long). It introduces a custom
inline hash and compare function to avoid indirect jhash dispatch.
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 7b9408b8320c9..b4366cad3cfa5 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -2763,6 +2763,31 @@ static inline void *rhtab_elem_value(struct rhtab_elem *l, u32 key_size)
> return l->data + round_up(key_size, 8);
> }
>
> +/* Specialize hash function and objcmp for long sized key */
> +static __always_inline int rhtab_key_cmp_long(struct rhashtable_compare_arg *arg,
> + const void *ptr)
> +{
> + const unsigned long key1 = *(const unsigned long *)arg->key;
[Severity: High]
Can this direct pointer dereference cause unaligned access faults on
architectures without hardware support for unaligned loads?
The BPF verifier ensures memory bounds checking for map keys, but does not
enforce that the key pointer is naturally aligned (e.g., keys from packed
structs or packet buffers).
Should this use get_unaligned() to safely read arg->key?
> + const struct rhtab_elem *key2 = ptr;
> +
> + return key1 != *(const unsigned long *)key2->data;
> +}
> +
> +static __always_inline u32 rhtab_hashfn_long(const void *data, u32 len, u32 seed)
> +{
> + u64 k = *(const unsigned long *)data;
[Severity: High]
Can this dereference of the data pointer also cause unaligned access faults,
similar to the key comparison function above?
> +
> + return (u32)(k ^ (k >> 32)) ^ seed;
[Severity: High]
Does this custom hash function bypass the rhashtable HashDoS mitigation?
Because the random seed is applied via a final linear XOR, the collision
condition for two keys reduces to `(H(k1) & (S - 1)) == (H(k2) & (S - 1))`.
This mathematically makes collisions completely independent of the seed.
If rhashtable's bucket chain length limit is exceeded and it attempts to
rehash with a new random seed, will all colliding keys still map to the exact
same new bucket, causing an infinite rehash loop?
> +}
> +
> +static const struct rhashtable_params rhtab_params_long = {
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605-rhash-v7-0-5b8e05f8630d@meta.com?part=7
next prev parent reply other threads:[~2026-06-05 11:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 11:41 [PATCH bpf-next v7 00/12] bpf: Introduce resizable hash map Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 01/12] rhashtable: Add rhashtable_next_key() API Mykyta Yatsenko
2026-06-05 11:43 ` Herbert Xu
2026-06-05 11:41 ` [PATCH bpf-next v7 02/12] rhashtable: Add selftest for rhashtable_next_key() Mykyta Yatsenko
2026-06-05 11:43 ` Herbert Xu
2026-06-05 11:41 ` [PATCH bpf-next v7 03/12] rhashtable: Use irq work for shrinking Mykyta Yatsenko
2026-06-05 12:40 ` bot+bpf-ci
2026-06-05 11:41 ` [PATCH bpf-next v7 04/12] bpf: Implement resizable hashmap basic functions Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 05/12] bpf: Implement iteration ops for resizable hashtab Mykyta Yatsenko
2026-06-05 11:56 ` sashiko-bot
2026-06-05 12:40 ` bot+bpf-ci
2026-06-05 11:41 ` [PATCH bpf-next v7 06/12] bpf: Allow special fields in " Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 07/12] bpf: Optimize word-sized keys for resizable hashtable Mykyta Yatsenko
2026-06-05 11:54 ` sashiko-bot [this message]
2026-06-05 12:22 ` bot+bpf-ci
2026-06-05 11:41 ` [PATCH bpf-next v7 08/12] libbpf: Support " Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 09/12] selftests/bpf: Add basic tests for resizable hash map Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 10/12] selftests/bpf: Add BPF iterator " Mykyta Yatsenko
2026-06-05 11:56 ` sashiko-bot
2026-06-05 11:41 ` [PATCH bpf-next v7 11/12] bpftool: Add rhash map documentation Mykyta Yatsenko
2026-06-05 11:41 ` [PATCH bpf-next v7 12/12] selftests/bpf: Add resizable hashmap to benchmarks Mykyta Yatsenko
2026-06-05 12:03 ` sashiko-bot
2026-06-05 15:10 ` [PATCH bpf-next v7 00/12] bpf: Introduce resizable hash map patchwork-bot+netdevbpf
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=20260605115436.C55991F00893@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.