netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT
@ 2017-05-21 14:38 Liping Zhang
  2017-05-21 15:45 ` Florian Westphal
  2017-05-23 21:28 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Liping Zhang @ 2017-05-21 14:38 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, fw, Liping Zhang

From: Liping Zhang <zlpnobody@gmail.com>

We need to clear the IPS_SRC_NAT_DONE_BIT to indicate that the ct has
been removed from nat_bysource table. But unfortunately, we use the
non-atomic bit operation: "ct->status &= ~IPS_NAT_DONE_MASK". So
there's a race condition that we may clear the _DYING_BIT set by
another CPU unexpectedly.

Since we don't care about the IPS_DST_NAT_DONE_BIT, so just using
clear_bit to clear the IPS_SRC_NAT_DONE_BIT is enough.

Also note, this is the last user which use the non-atomic bit operation
to update the confirmed ct->status.

Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
---
 net/netfilter/nf_nat_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index ef0be32..6c72922 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -566,7 +566,7 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)
 	 * Else, when the conntrack is destoyed, nf_nat_cleanup_conntrack()
 	 * will delete entry from already-freed table.
 	 */
-	ct->status &= ~IPS_NAT_DONE_MASK;
+	clear_bit(IPS_SRC_NAT_DONE_BIT, &ct->status);
 	rhltable_remove(&nf_nat_bysource_table, &ct->nat_bysource,
 			nf_nat_bysource_params);
 
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT
  2017-05-21 14:38 [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT Liping Zhang
@ 2017-05-21 15:45 ` Florian Westphal
  2017-05-23 21:28 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2017-05-21 15:45 UTC (permalink / raw)
  To: Liping Zhang; +Cc: pablo, netfilter-devel, fw, Liping Zhang

Liping Zhang <zlpnobody@163.com> wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
> 
> We need to clear the IPS_SRC_NAT_DONE_BIT to indicate that the ct has
> been removed from nat_bysource table. But unfortunately, we use the
> non-atomic bit operation: "ct->status &= ~IPS_NAT_DONE_MASK". So
> there's a race condition that we may clear the _DYING_BIT set by
> another CPU unexpectedly.
> 
> Since we don't care about the IPS_DST_NAT_DONE_BIT, so just using
> clear_bit to clear the IPS_SRC_NAT_DONE_BIT is enough.
> 
> Also note, this is the last user which use the non-atomic bit operation
> to update the confirmed ct->status.

Looks good, thanks Liping.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT
  2017-05-21 14:38 [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT Liping Zhang
  2017-05-21 15:45 ` Florian Westphal
@ 2017-05-23 21:28 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-23 21:28 UTC (permalink / raw)
  To: Liping Zhang; +Cc: netfilter-devel, fw, Liping Zhang

On Sun, May 21, 2017 at 10:38:11PM +0800, Liping Zhang wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
> 
> We need to clear the IPS_SRC_NAT_DONE_BIT to indicate that the ct has
> been removed from nat_bysource table. But unfortunately, we use the
> non-atomic bit operation: "ct->status &= ~IPS_NAT_DONE_MASK". So
> there's a race condition that we may clear the _DYING_BIT set by
> another CPU unexpectedly.
> 
> Since we don't care about the IPS_DST_NAT_DONE_BIT, so just using
> clear_bit to clear the IPS_SRC_NAT_DONE_BIT is enough.
> 
> Also note, this is the last user which use the non-atomic bit operation
> to update the confirmed ct->status.

Applied to nf, thanks.

Does your patchset for nf-next depend on this in any way? If so, you
will have to wait until this propagates to nf-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-23 21:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-21 14:38 [PATCH nf] netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT Liping Zhang
2017-05-21 15:45 ` Florian Westphal
2017-05-23 21:28 ` 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).