All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: PROBLEM: Injected conntrack lost helper
       [not found]   ` <0f4edf58-7b4e-05e8-3f13-d34819b8d5db@gmail.com>
@ 2022-01-31 11:20     ` Florian Westphal
  2022-01-31 13:47       ` Pham Thanh Tuyen
  2022-02-01  3:08       ` Pham Thanh Tuyen
  0 siblings, 2 replies; 10+ messages in thread
From: Florian Westphal @ 2022-01-31 11:20 UTC (permalink / raw)
  To: Pham Thanh Tuyen; +Cc: netfilter-devel

Pham Thanh Tuyen <phamtyn@gmail.com> wrote:

[ moving to netfilter-devel ]

> > > 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-01-31 11:20     ` PROBLEM: Injected conntrack lost helper Florian Westphal
@ 2022-01-31 13:47       ` Pham Thanh Tuyen
  2022-01-31 13:55         ` Pham Thanh Tuyen
  2022-02-01  3:08       ` Pham Thanh Tuyen
  1 sibling, 1 reply; 10+ messages in thread
From: Pham Thanh Tuyen @ 2022-01-31 13:47 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

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).


On 1/31/22 18:20, Florian Westphal wrote:
> Pham Thanh Tuyen <phamtyn@gmail.com> wrote:
>
> [ moving to netfilter-devel ]
>
>>>> 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-01-31 13:47       ` Pham Thanh Tuyen
@ 2022-01-31 13:55         ` Pham Thanh Tuyen
  0 siblings, 0 replies; 10+ messages in thread
From: Pham Thanh Tuyen @ 2022-01-31 13:55 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

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).

On 1/31/22 20:47, Pham Thanh Tuyen wrote:
> 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).
>
>
> On 1/31/22 18:20, Florian Westphal wrote:
>> Pham Thanh Tuyen <phamtyn@gmail.com> wrote:
>>
>> [ moving to netfilter-devel ]
>>
>>>>> 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-01-31 11:20     ` PROBLEM: Injected conntrack lost helper Florian Westphal
  2022-01-31 13:47       ` Pham Thanh Tuyen
@ 2022-02-01  3:08       ` Pham Thanh Tuyen
  2022-02-01 10:29         ` Pablo Neira Ayuso
  1 sibling, 1 reply; 10+ messages in thread
From: Pham Thanh Tuyen @ 2022-02-01  3:08 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

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.

On 1/31/22 18:20, Florian Westphal wrote:
> Pham Thanh Tuyen <phamtyn@gmail.com> wrote:
>
> [ moving to netfilter-devel ]
>
>>>> 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01  3:08       ` Pham Thanh Tuyen
@ 2022-02-01 10:29         ` Pablo Neira Ayuso
  2022-02-01 12:04           ` Florian Westphal
  0 siblings, 1 reply; 10+ messages in thread
From: Pablo Neira Ayuso @ 2022-02-01 10:29 UTC (permalink / raw)
  To: Pham Thanh Tuyen; +Cc: Florian Westphal, netfilter-devel

On Tue, Feb 01, 2022 at 10:08:55AM +0700, Pham Thanh Tuyen wrote:
> 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.

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01 10:29         ` Pablo Neira Ayuso
@ 2022-02-01 12:04           ` Florian Westphal
  2022-02-01 13:32             ` Pham Thanh Tuyen
  2022-02-02 11:48             ` Pablo Neira Ayuso
  0 siblings, 2 replies; 10+ messages in thread
From: Florian Westphal @ 2022-02-01 12:04 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Pham Thanh Tuyen, Florian Westphal, netfilter-devel

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Tue, Feb 01, 2022 at 10:08:55AM +0700, Pham Thanh Tuyen wrote:
> > 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'.

diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -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 */

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01 12:04           ` Florian Westphal
@ 2022-02-01 13:32             ` Pham Thanh Tuyen
  2022-02-01 14:14               ` Florian Westphal
  2022-02-02 11:48             ` Pablo Neira Ayuso
  1 sibling, 1 reply; 10+ messages in thread
From: Pham Thanh Tuyen @ 2022-02-01 13:32 UTC (permalink / raw)
  To: Florian Westphal, Pablo Neira Ayuso; +Cc: netfilter-devel

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.

On 2/1/22 19:04, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>> On Tue, Feb 01, 2022 at 10:08:55AM +0700, Pham Thanh Tuyen wrote:
>>> 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'.
>
> diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
> --- a/net/netfilter/nf_conntrack_netlink.c
> +++ b/net/netfilter/nf_conntrack_netlink.c
> @@ -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 */

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01 13:32             ` Pham Thanh Tuyen
@ 2022-02-01 14:14               ` Florian Westphal
  2022-02-02  1:43                 ` Pham Thanh Tuyen
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Westphal @ 2022-02-01 14:14 UTC (permalink / raw)
  To: Pham Thanh Tuyen; +Cc: Florian Westphal, Pablo Neira Ayuso, netfilter-devel

Pham Thanh Tuyen <phamtyn@gmail.com> wrote:
> 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01 14:14               ` Florian Westphal
@ 2022-02-02  1:43                 ` Pham Thanh Tuyen
  0 siblings, 0 replies; 10+ messages in thread
From: Pham Thanh Tuyen @ 2022-02-02  1:43 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pablo Neira Ayuso, netfilter-devel

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

On 2/1/22 21:14, Florian Westphal wrote:
> Pham Thanh Tuyen <phamtyn@gmail.com> wrote:
>> 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?

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

* Re: PROBLEM: Injected conntrack lost helper
  2022-02-01 12:04           ` Florian Westphal
  2022-02-01 13:32             ` Pham Thanh Tuyen
@ 2022-02-02 11:48             ` Pablo Neira Ayuso
  1 sibling, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2022-02-02 11:48 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pham Thanh Tuyen, netfilter-devel

On Tue, Feb 01, 2022 at 01:04:54PM +0100, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Tue, Feb 01, 2022 at 10:08:55AM +0700, Pham Thanh Tuyen wrote:
> > > 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'.
> 
> diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
> --- a/net/netfilter/nf_conntrack_netlink.c
> +++ b/net/netfilter/nf_conntrack_netlink.c
> @@ -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

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

end of thread, other threads:[~2022-02-02 11:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <f9fb5616-0b37-d76b-74e5-53751d473432@gmail.com>
     [not found] ` <3f416429-b1be-b51a-c4ef-6274def33258@iogearbox.net>
     [not found]   ` <0f4edf58-7b4e-05e8-3f13-d34819b8d5db@gmail.com>
2022-01-31 11:20     ` PROBLEM: Injected conntrack lost helper Florian Westphal
2022-01-31 13:47       ` Pham Thanh Tuyen
2022-01-31 13:55         ` Pham Thanh Tuyen
2022-02-01  3:08       ` Pham Thanh Tuyen
2022-02-01 10:29         ` Pablo Neira Ayuso
2022-02-01 12:04           ` Florian Westphal
2022-02-01 13:32             ` Pham Thanh Tuyen
2022-02-01 14:14               ` Florian Westphal
2022-02-02  1:43                 ` Pham Thanh Tuyen
2022-02-02 11:48             ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.