Skip to contentSkip to conversation

PROBLEM: Injected conntrack lost helper

DISCUSSION Florian Westphal 3 participants 10 messages Jan 31, 2022 – Feb 2, 2022 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Florian Westphal

author maintainer
#3 lore raw

Pham Thanh Tuyen <[email protected]> wrote:

[ moving to netfilter-devel ]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

My name is Pham Thanh Tuyen. I found a bug related to the ctnetlink and conntrack subsystems. Details are as follows:

1. Summary: Injected conntrack lost helper

2. Description: When a conntrack whose helper is injected from userspace, the ctnetlink creates helper for it but NAT then loses the helper in case the user defined helper explicitly with CT target.

Hmm. If you insert a conntrack entry from userspace, it will already be confirmed, so nat rules will have no effect, and template CT rules are irrelevant wrt. to the helper, as extension can only be created if the conntrack is not in the hash yet.

Can you describe the steps to reproduce this bug?

#4 lore raw

1. Make sure to disable automatic helper assignment using the command 'sudo sysctl net.netfilter.nf_conntrack_helper=0'
2. Use NAT
3. Set up a fault tolerant firewall system and then make the active firewall machine to fail. The backup firewall machine will recover the connection but lose the helper. (Simpler way is to use conntrack -I to inject the conntrack).

Quoted 19 lines · Florian Westphal

Pham Thanh Tuyen <[email protected]> wrote:

[ moving to netfilter-devel ]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

My name is Pham Thanh Tuyen. I found a bug related to the ctnetlink and conntrack subsystems. Details are as follows:

1. Summary: Injected conntrack lost helper

2. Description: When a conntrack whose helper is injected from userspace, the ctnetlink creates helper for it but NAT then loses the helper in case the user defined helper explicitly with CT target.

Hmm. If you insert a conntrack entry from userspace, it will already be confirmed, so nat rules will have no effect, and template CT rules are irrelevant wrt. to the helper, as extension can only be created if the conntrack is not in the hash yet.

Can you describe the steps to reproduce this bug?

#5 lore raw

1. Make sure to disable automatic helper assignment using the command 'sudo sysctl -w net.netfilter.nf_conntrack_helper=0'
2. Use NAT
3. Set up a fault tolerant firewall system and then make the active firewall machine to fail. The backup firewall machine will recover the connection but lose the helper. (Simpler way is to use conntrack -I to inject the conntrack).

Quoted 25 lines · Pham Thanh Tuyen

1. Make sure to disable automatic helper assignment using the command 'sudo sysctl net.netfilter.nf_conntrack_helper=0'
2. Use NAT
3. Set up a fault tolerant firewall system and then make the active firewall machine to fail. The backup firewall machine will recover the connection but lose the helper. (Simpler way is to use conntrack -I to inject the conntrack).

Quoted 19 lines · Florian Westphal

Pham Thanh Tuyen <[email protected]> wrote:

[ moving to netfilter-devel ]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

My name is Pham Thanh Tuyen. I found a bug related to the ctnetlink and conntrack subsystems. Details are as follows:

1. Summary: Injected conntrack lost helper

2. Description: When a conntrack whose helper is injected from userspace, the ctnetlink creates helper for it but NAT then loses the helper in case the user defined helper explicitly with CT target.

Hmm.  If you insert a conntrack entry from userspace, it will already be confirmed, so nat rules will have no effect, and template CT rules are irrelevant wrt. to the helper, as extension can only be created if the conntrack is not in the hash yet.

Can you describe the steps to reproduce this bug?

#6 lore raw
In reply to Florian Westphal

When the conntrack is created, the extension is created before the conntrack is assigned confirmed and inserted into the hash table. But the function ctnetlink_setup_nat() causes loss of helper in the mentioned situation. I mention the template because it's seamless in the __nf_ct_try_assign_helper() function. Please double check.

Quoted 19 lines · Florian Westphal

Pham Thanh Tuyen <[email protected]> wrote:

[ moving to netfilter-devel ]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

My name is Pham Thanh Tuyen. I found a bug related to the ctnetlink and conntrack subsystems. Details are as follows:

1. Summary: Injected conntrack lost helper

2. Description: When a conntrack whose helper is injected from userspace, the ctnetlink creates helper for it but NAT then loses the helper in case the user defined helper explicitly with CT target.

Hmm. If you insert a conntrack entry from userspace, it will already be confirmed, so nat rules will have no effect, and template CT rules are irrelevant wrt. to the helper, as extension can only be created if the conntrack is not in the hash yet.

Can you describe the steps to reproduce this bug?

#7 lore raw
Quoted 5 lines · Pham Thanh Tuyen

When the conntrack is created, the extension is created before the conntrack is assigned confirmed and inserted into the hash table. But the function ctnetlink_setup_nat() causes loss of helper in the mentioned situation. I mention the template because it's seamless in the __nf_ct_try_assign_helper() function. Please double check.

Conntrack entries that are created via ctnetlink as IPS_CONFIRMED always set on.

The helper code is only exercised from the packet path for conntrack entries that are newly created.

author maintainer
#8 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 5 lines · Pham Thanh Tuyen

When the conntrack is created, the extension is created before the conntrack is assigned confirmed and inserted into the hash table. But the function ctnetlink_setup_nat() causes loss of helper in the mentioned situation. I mention the template because it's seamless in the __nf_ct_try_assign_helper() function. Please double check.

Quoted 5 lines

Conntrack entries that are created via ctnetlink as IPS_CONFIRMED always set on.

The helper code is only exercised from the packet path for conntrack entries that are newly created.

I suspect this is the most simple fix, might make sense to also update the comment of IPS_HELPER to say that it means 'explicitly attached via ctnetlink or ruleset'.

net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -2313,6 +2313,9 @@ ctnetlink_create_conntrack(struct net *net,
 
 			/* not in hash table yet so not strictly necessary */
 			RCU_INIT_POINTER(help->helper, helper);
+
+			/* explicitly attached from userspace */
+			ct->status |= IPS_HELPER;
 		}
 	} else {
 		/* try an implicit helper assignation */
#9 lore raw

Previously I also thought ct->status |= IPS_HELPER; is ok, but after internal pointer assigning with RCU_INIT_POINTER() need external pointer assigning with rcu_assign_pointer() in __nf_ct_try_assign_helper() function.

Quoted 29 lines · Florian Westphal
Quoted 11 lines · Pablo Neira Ayuso
Quoted 5 lines · Pham Thanh Tuyen

When the conntrack is created, the extension is created before the conntrack is assigned confirmed and inserted into the hash table. But the function ctnetlink_setup_nat() causes loss of helper in the mentioned situation. I mention the template because it's seamless in the __nf_ct_try_assign_helper() function. Please double check.

Conntrack entries that are created via ctnetlink as IPS_CONFIRMED always set on.

The helper code is only exercised from the packet path for conntrack entries that are newly created.

I suspect this is the most simple fix, might make sense to also update the comment of IPS_HELPER to say that it means 'explicitly attached via ctnetlink or ruleset'.

net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -2313,6 +2313,9 @@ ctnetlink_create_conntrack(struct net *net,
 
  			/* not in hash table yet so not strictly necessary */
  			RCU_INIT_POINTER(help->helper, helper);
+
+			/* explicitly attached from userspace */
+			ct->status |= IPS_HELPER;
  		}
  	} else {
  		/* try an implicit helper assignation */
author maintainer
#10 lore raw
Quoted 3 lines · Pham Thanh Tuyen

Previously I also thought ct->status |= IPS_HELPER; is ok, but after internal pointer assigning with RCU_INIT_POINTER() need external pointer assigning with rcu_assign_pointer() in __nf_ct_try_assign_helper() function.

I'm not following.

__nf_ct_try_assign_helper() doesn't do anything once that flag is set, so how could the helper get lost later?

#11 lore raw

That's okay, so fix it like you ct->status |= IPS_HELPER;

Quoted 8 lines · Florian Westphal
Quoted 3 lines · Pham Thanh Tuyen

Previously I also thought ct->status |= IPS_HELPER; is ok, but after internal pointer assigning with RCU_INIT_POINTER() need external pointer assigning with rcu_assign_pointer() in __nf_ct_try_assign_helper() function.

I'm not following.

__nf_ct_try_assign_helper() doesn't do anything once that flag is set, so how could the helper get lost later?

#12 lore raw
In reply to Florian Westphal
Quoted 22 lines · Florian Westphal
Quoted 7 lines · Pablo Neira Ayuso
Quoted 5 lines · Pham Thanh Tuyen

When the conntrack is created, the extension is created before the conntrack is assigned confirmed and inserted into the hash table. But the function ctnetlink_setup_nat() causes loss of helper in the mentioned situation. I mention the template because it's seamless in the __nf_ct_try_assign_helper() function. Please double check.

Quoted 5 lines

Conntrack entries that are created via ctnetlink as IPS_CONFIRMED always set on.

The helper code is only exercised from the packet path for conntrack entries that are newly created.

I suspect this is the most simple fix, might make sense to also update the comment of IPS_HELPER to say that it means 'explicitly attached via ctnetlink or ruleset'.

net/netfilter/nf_conntrack_netlink.c ctnetlink_create_conntrack(struct net *net, · line 2321

Quoted 9 lines
net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -2313,6 +2313,9 @@ ctnetlink_create_conntrack(struct net *net,
 
 			/* not in hash table yet so not strictly necessary */
 			RCU_INIT_POINTER(help->helper, helper);
+
+			/* explicitly attached from userspace */
+			ct->status |= IPS_HELPER;
 		}
 	} else {
 		/* try an implicit helper assignation */

This also LGTM.

I'd suggest you update the .h file to describe that ctnetlink also sets on this bit.

Thanks