Skip to content

Commit 79e09ef

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: nft_hash: do not dump the auto generated seed
This can prevent the nft utility from printing out the auto generated seed to the user, which is unnecessary and confusing. Fixes: cb1b69b ("netfilter: nf_tables: add hash expression") Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 7cddd96 commit 79e09ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/netfilter/nft_hash.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct nft_hash {
2121
enum nft_registers sreg:8;
2222
enum nft_registers dreg:8;
2323
u8 len;
24+
bool autogen_seed:1;
2425
u32 modulus;
2526
u32 seed;
2627
u32 offset;
@@ -82,10 +83,12 @@ static int nft_hash_init(const struct nft_ctx *ctx,
8283
if (priv->offset + priv->modulus - 1 < priv->offset)
8384
return -EOVERFLOW;
8485

85-
if (tb[NFTA_HASH_SEED])
86+
if (tb[NFTA_HASH_SEED]) {
8687
priv->seed = ntohl(nla_get_be32(tb[NFTA_HASH_SEED]));
87-
else
88+
} else {
89+
priv->autogen_seed = true;
8890
get_random_bytes(&priv->seed, sizeof(priv->seed));
91+
}
8992

9093
return nft_validate_register_load(priv->sreg, len) &&
9194
nft_validate_register_store(ctx, priv->dreg, NULL,
@@ -105,7 +108,8 @@ static int nft_hash_dump(struct sk_buff *skb,
105108
goto nla_put_failure;
106109
if (nla_put_be32(skb, NFTA_HASH_MODULUS, htonl(priv->modulus)))
107110
goto nla_put_failure;
108-
if (nla_put_be32(skb, NFTA_HASH_SEED, htonl(priv->seed)))
111+
if (!priv->autogen_seed &&
112+
nla_put_be32(skb, NFTA_HASH_SEED, htonl(priv->seed)))
109113
goto nla_put_failure;
110114
if (priv->offset != 0)
111115
if (nla_put_be32(skb, NFTA_HASH_OFFSET, htonl(priv->offset)))

0 commit comments

Comments
 (0)