Skip to content

Commit 2e917d6

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: nft_numgen: fix race between num generate and store it
After we generate a new number, we still use the priv->counter and store it to the dreg. This is not correct, another cpu may already change it to a new number. So we must use the generated number, not the priv->counter itself. Fixes: 91dbc6b ("netfilter: nf_tables: add number generator expression") Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 8e8118f commit 2e917d6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/netfilter/nft_numgen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void nft_ng_inc_eval(const struct nft_expr *expr,
3737
nval = (oval + 1 < priv->modulus) ? oval + 1 : 0;
3838
} while (atomic_cmpxchg(&priv->counter, oval, nval) != oval);
3939

40-
memcpy(&regs->data[priv->dreg], &priv->counter, sizeof(u32));
40+
regs->data[priv->dreg] = nval;
4141
}
4242

4343
static const struct nla_policy nft_ng_policy[NFTA_NG_MAX + 1] = {

0 commit comments

Comments
 (0)