Skip to content

Commit

Permalink
netfilter: nft_numgen: fix race between num generate and store it
Browse files Browse the repository at this point in the history
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 <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Sep 12, 2016
1 parent 8e8118f commit 2e917d6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/netfilter/nft_numgen.c
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ static void nft_ng_inc_eval(const struct nft_expr *expr,
nval = (oval + 1 < priv->modulus) ? oval + 1 : 0;
} while (atomic_cmpxchg(&priv->counter, oval, nval) != oval);

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

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

0 comments on commit 2e917d6

Please sign in to comment.