netfilter: nft_numgen: fix race between num generate and store it
authorLiping Zhang <liping.zhang@spreadtrum.com>
Mon, 12 Sep 2016 14:21:36 +0000 (22:21 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 12 Sep 2016 18:00:23 +0000 (20:00 +0200)
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: 91dbc6be0a62 ("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>
net/netfilter/nft_numgen.c

index f51a3ed..f173ebe 100644 (file)
@@ -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] = {