Skip to content
/ linux Public

Commit cfe35cb

Browse files
Florian WestphalSasha Levin
authored andcommitted
netfilter: nft_set_hash: fix get operation on big endian
[ Upstream commit 2f635ad ] tests/shell/testcases/packetpath/set_match_nomatch_hash_fast fails on big endian with: Error: Could not process rule: No such file or directory reset element ip test s { 244.147.90.126 } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fatal: Cannot fetch element "244.147.90.126" ... because the wrong bucket is searched, jhash() and jhash1_word are not interchangeable on big endian. Fixes: 3b02b0a ("netfilter: nft_set_hash: fix lookups with fixed size hash on big endian") Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 77eef9f commit cfe35cb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

net/netfilter/nft_set_hash.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,20 @@ bool nft_hash_lookup(const struct net *net, const struct nft_set *set,
525525
static void *nft_hash_get(const struct net *net, const struct nft_set *set,
526526
const struct nft_set_elem *elem, unsigned int flags)
527527
{
528+
const u32 *key = (const u32 *)&elem->key.val;
528529
struct nft_hash *priv = nft_set_priv(set);
529530
u8 genmask = nft_genmask_cur(net);
530531
struct nft_hash_elem *he;
531532
u32 hash;
532533

533-
hash = jhash(elem->key.val.data, set->klen, priv->seed);
534+
if (set->klen == 4)
535+
hash = jhash_1word(*key, priv->seed);
536+
else
537+
hash = jhash(key, set->klen, priv->seed);
538+
534539
hash = reciprocal_scale(hash, priv->buckets);
535540
hlist_for_each_entry_rcu(he, &priv->table[hash], node) {
536-
if (!memcmp(nft_set_ext_key(&he->ext), elem->key.val.data, set->klen) &&
541+
if (!memcmp(nft_set_ext_key(&he->ext), key, set->klen) &&
537542
nft_set_elem_active(&he->ext, genmask))
538543
return he;
539544
}

0 commit comments

Comments
 (0)