* [PATCH nf-next] netfilter: nft_numgen: fix race between num generate and store it
@ 2016-09-12 14:21 Liping Zhang
2016-09-12 17:58 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Liping Zhang @ 2016-09-12 14:21 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, nevola, Liping Zhang
From: Liping Zhang <liping.zhang@spreadtrum.com>
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>
---
net/netfilter/nft_numgen.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/netfilter/nft_numgen.c b/net/netfilter/nft_numgen.c
index f51a3ed..f173ebe 100644
--- a/net/netfilter/nft_numgen.c
+++ b/net/netfilter/nft_numgen.c
@@ -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(®s->data[priv->dreg], &priv->counter, sizeof(u32));
+ regs->data[priv->dreg] = nval;
}
static const struct nla_policy nft_ng_policy[NFTA_NG_MAX + 1] = {
--
2.5.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH nf-next] netfilter: nft_numgen: fix race between num generate and store it
2016-09-12 14:21 [PATCH nf-next] netfilter: nft_numgen: fix race between num generate and store it Liping Zhang
@ 2016-09-12 17:58 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-09-12 17:58 UTC (permalink / raw)
To: Liping Zhang; +Cc: netfilter-devel, nevola, Liping Zhang
i
On Mon, Sep 12, 2016 at 10:21:36PM +0800, Liping Zhang wrote:
> From: Liping Zhang <liping.zhang@spreadtrum.com>
>
> 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.
Applied, thanks Liping.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-12 17:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-12 14:21 [PATCH nf-next] netfilter: nft_numgen: fix race between num generate and store it Liping Zhang
2016-09-12 17:58 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).