Skip to contentSkip to conversation

userspace conntrack helper and confirming the master conntrack

PATCH Superseded Michal Kubecek 4 participants 11 messages Jul 18, 2019 – May 15, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

Hello,

to clean up some skeletons in the closet of our distribution kernels, I'm trying to add a userspace conntrack helper for SLP into conntrackd.

A helper is needed to handle SLP queries which are sent as multicast UDP packets but replied to with unicast packets so that reply's source address does not much request's destination. This is exactly the same problem as for mDNS so that I started by copying existing mdns helper in conntrackd and changing the default timeout. But I found that it does not work with 5.2 kernel.

The setup looks like this (omitting some log rules):

  nfct helper add slp inet udp
  iptables -t raw -A OUTPUT -m addrtype --dst-type MULTICAST \
      -p udp --dport 427 -j CT --helper slp
  iptables -t raw -A OUTPUT -m addrtype --dst-type BROADCAST
      -p udp --dport 427 -j CT --helper slp
  iptables -A INPUT -i lo -j ACCEPT
  iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
  iptables -A INPUT -m conntrack --ctstate RELATED -j ACCEPT
  iptables -P INPUT DROP
  iptables -P OUTPUT ACCEPT

The helper rules apply, outgoing multicast packet is sent away but the unicast reply is not recognized as related and rejected. Monitring with "conntrack -E expect" shows that an expectation is created but it is immediately destroyed and "conntrack -E" does not show the conntrack for the original multicast packet (which is created when I omit the helper rules in raw table). Kernel side tracing confirms that the conntrack is never confirmed and inserted into the hash table so that the expectation is destroyed once the request packet is sent out (and skb_consume()-ed).

I added some more tracing and this is what seems to happen:

- ipv4_confirm() is called for the conntrack from ip_output() via hook
- nf_confirm() calls attached helper and calls its help() function

    which is nfnl_userspace_cthelper(), that returns 0x78003

- nf_confirm() returns that without calling nf_confirm_conntrack()
- verdict 0x78003 is returned to nf_hook_slow() which therefore calls nf_queue() to pass this to userspace helper on queue 7
- nf_queue() returns 0 which is also returned by nf_hook_slow()
- the packet reappears in nf_reinject() where it passes through nf_reroute() and nf_iterate() to the main switch statement
- it takes NF_ACCEPT branch to call okfn which is ip_finish_output()
- unless I missed something, there is nothing that could confirm the conntrack after that

Did I forget to do something in the helper (essentially a copy of existing mdns helper which is supposed to work) or in the setup above (which is based on the documentation)? Or is this a problem on kernel side? Should the conntrack be confirmed while processing the original packet (which ends up queued) or the reinjected one? And where should it happen?

Thanks in advance,
Michal Kubecek

maintainer
#1 lore raw
Quoted 40 lines · Michal Kubecek

Hello,

to clean up some skeletons in the closet of our distribution kernels, I'm trying to add a userspace conntrack helper for SLP into conntrackd.

A helper is needed to handle SLP queries which are sent as multicast UDP packets but replied to with unicast packets so that reply's source address does not much request's destination. This is exactly the same problem as for mDNS so that I started by copying existing mdns helper in conntrackd and changing the default timeout. But I found that it does not work with 5.2 kernel.

The setup looks like this (omitting some log rules):

  nfct helper add slp inet udp
  iptables -t raw -A OUTPUT -m addrtype --dst-type MULTICAST \
      -p udp --dport 427 -j CT --helper slp
  iptables -t raw -A OUTPUT -m addrtype --dst-type BROADCAST
      -p udp --dport 427 -j CT --helper slp
  iptables -A INPUT -i lo -j ACCEPT
  iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
  iptables -A INPUT -m conntrack --ctstate RELATED -j ACCEPT
  iptables -P INPUT DROP
  iptables -P OUTPUT ACCEPT

The helper rules apply, outgoing multicast packet is sent away but the unicast reply is not recognized as related and rejected. Monitring with "conntrack -E expect" shows that an expectation is created but it is immediately destroyed and "conntrack -E" does not show the conntrack for the original multicast packet (which is created when I omit the helper rules in raw table). Kernel side tracing confirms that the conntrack is never confirmed and inserted into the hash table so that the expectation is destroyed once the request packet is sent out (and skb_consume()-ed).

I added some more tracing and this is what seems to happen:

- ipv4_confirm() is called for the conntrack from ip_output() via hook
- nf_confirm() calls attached helper and calls its help() function

    which is nfnl_userspace_cthelper(), that returns 0x78003
Quoted 9 lines

- nf_confirm() returns that without calling nf_confirm_conntrack()
- verdict 0x78003 is returned to nf_hook_slow() which therefore calls nf_queue() to pass this to userspace helper on queue 7
- nf_queue() returns 0 which is also returned by nf_hook_slow()
- the packet reappears in nf_reinject() where it passes through nf_reroute() and nf_iterate() to the main switch statement
- it takes NF_ACCEPT branch to call okfn which is ip_finish_output()
- unless I missed something, there is nothing that could confirm the conntrack after that

I broke this with
commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad ("netfilter: conntrack: remove helper hook again").

Seems we have to revert, i see no other solution at this time.

#2 lore raw
Quoted 15 lines · Florian Westphal
Quoted 5 lines

I added some more tracing and this is what seems to happen:

- ipv4_confirm() is called for the conntrack from ip_output() via hook
- nf_confirm() calls attached helper and calls its help() function

    which is nfnl_userspace_cthelper(), that returns 0x78003
Quoted 9 lines

- nf_confirm() returns that without calling nf_confirm_conntrack()
- verdict 0x78003 is returned to nf_hook_slow() which therefore calls nf_queue() to pass this to userspace helper on queue 7
- nf_queue() returns 0 which is also returned by nf_hook_slow()
- the packet reappears in nf_reinject() where it passes through nf_reroute() and nf_iterate() to the main switch statement
- it takes NF_ACCEPT branch to call okfn which is ip_finish_output()
- unless I missed something, there is nothing that could confirm the conntrack after that

Quoted 5 lines

I broke this with
commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad ("netfilter: conntrack: remove helper hook again").

Seems we have to revert, i see no other solution at this time.

Thanks for the quick reply. I can confirm that with commit 827318feb69c reverted, the helper works as expected.

Michal

#3 lore raw
Quoted 16 lines · Michal Kubecek
Quoted 15 lines · Florian Westphal
Quoted 14 lines

I added some more tracing and this is what seems to happen:

- ipv4_confirm() is called for the conntrack from ip_output() via hook
- nf_confirm() calls attached helper and calls its help() function

    which is nfnl_userspace_cthelper(), that returns 0x78003

- nf_confirm() returns that without calling nf_confirm_conntrack()
- verdict 0x78003 is returned to nf_hook_slow() which therefore calls nf_queue() to pass this to userspace helper on queue 7
- nf_queue() returns 0 which is also returned by nf_hook_slow()
- the packet reappears in nf_reinject() where it passes through nf_reroute() and nf_iterate() to the main switch statement
- it takes NF_ACCEPT branch to call okfn which is ip_finish_output()
- unless I missed something, there is nothing that could confirm the conntrack after that

Quoted 8 lines
Quoted 5 lines

I broke this with
commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad ("netfilter: conntrack: remove helper hook again").

Seems we have to revert, i see no other solution at this time.

Thanks for the quick reply. I can confirm that with commit 827318feb69c reverted, the helper works as expected.

I'll schedule a revert in the next net batch.

#4 lore raw
Quoted 21 lines · Pablo Neira Ayuso
Quoted 20 lines · Michal Kubecek
Quoted 19 lines · Florian Westphal
Quoted 5 lines

I added some more tracing and this is what seems to happen:

- ipv4_confirm() is called for the conntrack from ip_output() via hook
- nf_confirm() calls attached helper and calls its help() function

    which is nfnl_userspace_cthelper(), that returns 0x78003
Quoted 9 lines

- nf_confirm() returns that without calling nf_confirm_conntrack()
- verdict 0x78003 is returned to nf_hook_slow() which therefore calls nf_queue() to pass this to userspace helper on queue 7
- nf_queue() returns 0 which is also returned by nf_hook_slow()
- the packet reappears in nf_reinject() where it passes through nf_reroute() and nf_iterate() to the main switch statement
- it takes NF_ACCEPT branch to call okfn which is ip_finish_output()
- unless I missed something, there is nothing that could confirm the conntrack after that

I broke this with
commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad ("netfilter: conntrack: remove helper hook again").

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Seems we have to revert, i see no other solution at this time.

Thanks for the quick reply. I can confirm that with commit 827318feb69c reverted, the helper works as expected.

I'll schedule a revert in the next net batch.

This seems to have fallen through the cracks. I tried to do the revert but it's not completely straightforward as bridge conntrack has been introduced in between and I'm not sure I got the bridge part right. Could someone more familiar with the code take a look?

Michal

---
 include/net/netfilter/nf_conntrack_core.h  |   3 -
 net/bridge/netfilter/nf_conntrack_bridge.c |  89 ++++++++++---
 net/netfilter/nf_conntrack_proto.c         | 141 ++++++++++++++++-----
 3 files changed, 178 insertions(+), 55 deletions(-)
include/net/netfilter/nf_conntrack_core.h +0 -3
index de10faf2ce91..ae41e92251dd 100644
@@ -64,9 +64,6 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
 	return ret;
 }
 
-unsigned int nf_confirm(struct sk_buff *skb, unsigned int protoff,
-			struct nf_conn *ct, enum ip_conntrack_info ctinfo);
-
 void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
 		 const struct nf_conntrack_l4proto *proto);
 
net/bridge/netfilter/nf_conntrack_bridge.c +72 -17

122 lines not on this page · raw message

net/netfilter/nf_conntrack_proto.c +106 -35

211 lines not on this page · raw message

Signature · 1 line
2.23.0
#5 lore raw

Hi Michal,

Quoted 4 lines · Michal Kubecek

This seems to have fallen through the cracks. I tried to do the revert but it's not completely straightforward as bridge conntrack has been introduced in between and I'm not sure I got the bridge part right. Could someone more familiar with the code take a look?

I'm exploring a different path, see attached patch (still untested).

I'm trying to avoid this large revert from Florian. The idea with this patch is to invoke the conntrack confirmation path from the nf_reinject() path, which is what it is missing.

I'm at a conference right now, I'll try scratch time to sort out this asap. Most likely we'll have to request a patch to be included in -stable in the next release I'm afraid.

I'm very sorry this has taken a bit to be sorted out.

include/linux/netfilter.h +1 -0
index 049aeb40fa35..e4047aae0da7 100644
@@ -448,6 +448,7 @@ struct nf_ct_hook {
 	void (*destroy)(struct nf_conntrack *);
 	bool (*get_tuple_skb)(struct nf_conntrack_tuple *,
 			      const struct sk_buff *);
+	unsigned int (*confirm)(struct sk_buff *);
 };
 extern struct nf_ct_hook __rcu *nf_ct_hook;
 
include/net/netfilter/nf_conntrack_core.h +1 -0
index de10faf2ce91..42407086484f 100644
@@ -66,6 +66,7 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
 
 unsigned int nf_confirm(struct sk_buff *skb, unsigned int protoff,
 			struct nf_conn *ct, enum ip_conntrack_info ctinfo);
+unsigned int nf_confirm_queue(struct sk_buff *skb);
 
 void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
 		 const struct nf_conntrack_l4proto *proto);
include/net/netfilter/nf_queue.h +4 -0
index 3cb6dcf53a4e..46bbd2389ffc 100644
@@ -6,12 +6,16 @@
 #include <linux/ipv6.h>
 #include <linux/jhash.h>
 
+/* extra verdict flags have mask 0x0000ff00, see uapi/linux/netfilter.h */
+#define __NF_VERDICT_FLAG_USERSPACE_CT_HELPER	0x00004000
+
 /* Each queued (to userspace) skbuff has one of these. */
 struct nf_queue_entry {
 	struct list_head	list;
 	struct sk_buff		*skb;
 	unsigned int		id;
 	unsigned int		hook_index;	/* index in hook_entries->hook[] */
+	unsigned int		queue_flags;
 
 	struct nf_hook_state	state;
 	u16			size; /* sizeof(entry) + saved route keys */
net/netfilter/nf_conntrack_core.c +1 -0
index 81a8ef42b88d..5238dc014156 100644
@@ -2487,6 +2487,7 @@ static struct nf_ct_hook nf_conntrack_hook = {
 	.update		= nf_conntrack_update,
 	.destroy	= destroy_conntrack,
 	.get_tuple_skb  = nf_conntrack_get_tuple_skb,
+	.confirm	= nf_confirm_queue,
 };
 
 void nf_conntrack_init_end(void)
net/netfilter/nf_conntrack_proto.c +48 -10

70 lines not on this page · raw message

net/netfilter/nf_queue.c +13 -2
index a2b58de82600..85ff51cadd2a 100644
@@ -156,7 +156,8 @@ static void nf_ip6_saveroute(const struct sk_buff *skb,
 }
 
 static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
-		      unsigned int index, unsigned int queuenum)
+		      unsigned int index, unsigned int queuenum,
+		      unsigned int queue_flags)
 {
 	int status = -ENOENT;
 	struct nf_queue_entry *entry = NULL;
@@ -198,6 +199,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
 		.skb	= skb,
 		.state	= *state,
 		.hook_index = index,
+		.queue_flags = queue_flags,
 		.size	= sizeof(*entry) + route_key_size,
 	};
 
@@ -232,7 +234,8 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
 {
 	int ret;
 
-	ret = __nf_queue(skb, state, index, verdict >> NF_VERDICT_QBITS);
+	ret = __nf_queue(skb, state, index, verdict >> NF_VERDICT_QBITS,
+			 verdict & __NF_VERDICT_FLAG_USERSPACE_CT_HELPER);
 	if (ret < 0) {
 		if (ret == -ESRCH &&
 		    (verdict & NF_VERDICT_FLAG_QUEUE_BYPASS))
@@ -324,6 +327,14 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 			verdict = NF_DROP;
 	}
 
+	if (verdict == NF_ACCEPT &&
+	    entry->queue_flags & __NF_VERDICT_FLAG_USERSPACE_CT_HELPER) {
+		struct nf_ct_hook *ct_hook = rcu_dereference(nf_ct_hook);
+
+		if (ct_hook)
+			verdict = nf_ct_hook->confirm(skb);
+	}
+
 	if (verdict == NF_ACCEPT) {
 next_hook:
 		++i;
net/netfilter/nfnetlink_cthelper.c +3 -2
index 7525063c25f5..2bf3b7c3ab9e 100644
@@ -21,7 +21,7 @@
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_conntrack_expect.h>
 #include <net/netfilter/nf_conntrack_ecache.h>
-
+#include <net/netfilter/nf_queue.h>
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nfnetlink_conntrack.h>
 #include <linux/netfilter/nfnetlink_cthelper.h>
@@ -60,7 +60,8 @@ nfnl_userspace_cthelper(struct sk_buff *skb, unsigned int protoff,
 		return NF_ACCEPT;
 
 	/* If the user-space helper is not available, don't block traffic. */
-	return NF_QUEUE_NR(helper->queue_num) | NF_VERDICT_FLAG_QUEUE_BYPASS;
+	return NF_QUEUE_NR(helper->queue_num) | NF_VERDICT_FLAG_QUEUE_BYPASS |
+		__NF_VERDICT_FLAG_USERSPACE_CT_HELPER;
 }
 
 static const struct nla_policy nfnl_cthelper_tuple_pol[NFCTH_TUPLE_MAX+1] = {
#6 lore raw
Quoted 8 lines · Pablo Neira Ayuso

Hi Michal,

Quoted 4 lines · Michal Kubecek

This seems to have fallen through the cracks. I tried to do the revert but it's not completely straightforward as bridge conntrack has been introduced in between and I'm not sure I got the bridge part right. Could someone more familiar with the code take a look?

Quoted 5 lines

I'm exploring a different path, see attached patch (still untested).

I'm trying to avoid this large revert from Florian. The idea with this patch is to invoke the conntrack confirmation path from the nf_reinject() path, which is what it is missing.

Thank you for looking into it. I'll take a look at your patch.

Quoted 3 lines

I'm at a conference right now, I'll try scratch time to sort out this asap. Most likely we'll have to request a patch to be included in -stable in the next release I'm afraid.

As the regression didn't happen in this cycle but in 5.1-rc1, there are already two releases affected so that it's IMHO more important to get it right than to catch 5.3 at any cost.

Michal

#7 lore raw

From: Jacob Rasmussen <[email protected]>

Hello everyone,

I'm encountering a bug on Chrome OS that I believe to be caused by commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad and I was wondering if there was any update on a fix/revert landing for this. If a fix has already landed would anyone mind pointing me to the specific commit because I haven't been able to find it on my own.

Thanks,
Jacob

maintainer
#8 lore raw
Quoted 2 lines · Jacob Rasmussen

I'm encountering a bug on Chrome OS that I believe to be caused by commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad and I was wondering if there was any update on a fix/revert landing for this. If a fix has already landed would anyone mind pointing me to the specific commit because I haven't been able to find it on my own.

Right, sorry about this.
Its most definitely caused by 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad.

Unfortunately I have no easy way to validate the fix.
If you could help speeding this up it would be great if you could test the candidate fix which I will send in a minute.

I've checked that it doesn't break conntrack in obvious ways and that nft_queue.sh self test still passes.

maintainer
#9 lore raw

PATCH 1/1 netfilter: make conntrack userspace helpers work again

conntrackd has support for userspace-based connection tracking helpers, to move parsing of control packets to userspace.

It works by registering a userspace helper using 'nfct' tool with the kernel, e.g.

nfct add helper rpc inet udp

Then, you need to set up iptables' rules to assign the new userspace helper:

iptables -I OUTPUT -t raw -p udp --dport 111 -j CT --helper rpc

or, use nft:

ct helper rpchelper {
    type "rpc" protocol udp;
    l3proto inet
}

udp dport 111 ct helper set "rpchelper"

After rules are in place to assign the helper to the connection, conntrackd is configured:

Helper {

  Type rpc inet udp {
     QueueNum 1
     QueueLen 1024
     Policy rpc {
         ExpectMax 1
         ExpectTimeout 300
         }
    }
}

Conntrack then tells the kernel to queue packets from the generic 'userspace' conntrack helper to userspace using the given queue number.

Just like with normal 'nfqueue' use, skbs leave the netfilter hook context. When userspace (conntrackd) sends back the accept verdict, the skb gets reinjected into the netfilter machinery.

Problem is that after the helper hook was merged back into the confirm one, the queueing itself occurs from the confirm hook, i.e. we queue from the last netfilter callback in the hook-list.

Therefore, on return, the packet bypasses the confirm action and the connection is never committed to the main conntrack table.

To fix this there are several ways:
1. revert the 'Fixes' commit and have a extra helper hook again. Works, but has the drawback of adding another indirect call for everyone.

2. Special case this: split the hooks only when userspace helper gets added, so queueing occurs at a lower priority again, and normal nqueue reinject would eventually call the last hook.

3. Extend the existing nf_queue ct update hook to allow a forced confirmation (plus run the seqadj code).

This goes for 3).

Based on an earlier patch from Pablo Neira Ayuso. Compile tested only, nft_queue.sh test still passes.

Fixes 827318feb69cb ("netfilter: conntrack: remove helper hook again")
---
 include/linux/netfilter.h          |  3 +-
 include/net/netfilter/nf_queue.h   |  3 +-
 include/uapi/linux/netfilter.h     |  3 +-
 net/netfilter/nf_conntrack_core.c  | 67 +++++++++++++++++++++++++-----
 net/netfilter/nf_queue.c           |  7 +++-
 net/netfilter/nfnetlink_cthelper.c |  4 +-
 net/netfilter/nfnetlink_queue.c    | 26 ++++++++----
 7 files changed, 89 insertions(+), 24 deletions(-)
include/linux/netfilter.h +2 -1
index eb312e7ca36e..727705f71828 100644
@@ -465,7 +465,8 @@ struct nf_conn;
 enum ip_conntrack_info;
 
 struct nf_ct_hook {
-	int (*update)(struct net *net, struct sk_buff *skb);
+	int (*update)(struct net *net, struct sk_buff *skb,
+		      u16 queue_flags);
 	void (*destroy)(struct nf_conntrack *);
 	bool (*get_tuple_skb)(struct nf_conntrack_tuple *,
 			      const struct sk_buff *);
include/net/netfilter/nf_queue.h +2 -1
index e770bba00066..c8ddbdfa54d3 100644
@@ -13,7 +13,8 @@ struct nf_queue_entry {
 	struct list_head	list;
 	struct sk_buff		*skb;
 	unsigned int		id;
-	unsigned int		hook_index;	/* index in hook_entries->hook[] */
+	u16			hook_index;	/* index in hook_entries->hook[] */
+	u16			queue_flags;	/* extra skb flags passed at NF_QUEUE time */
 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
 	struct net_device	*physin;
 	struct net_device	*physout;
include/uapi/linux/netfilter.h +2 -1
index ca9e63d6e0e4..aaca2c2e1b87 100644
@@ -22,7 +22,8 @@
 #define NF_VERDICT_MASK 0x000000ff
 
 /* extra verdict flags have mask 0x0000ff00 */
-#define NF_VERDICT_FLAG_QUEUE_BYPASS	0x00008000
+#define NF_VERDICT_FLAG_USERSPACE_CT_HELPER	0x00004000
+#define NF_VERDICT_FLAG_QUEUE_BYPASS		0x00008000
 
 /* queue number (NF_QUEUE) or errno (NF_DROP) */
 #define NF_VERDICT_QMASK 0xffff0000
net/netfilter/nf_conntrack_core.c +57 -10

108 lines not on this page · raw message

net/netfilter/nf_queue.c +5 -2
index bbd1209694b8..722846821e10 100644
@@ -153,7 +153,7 @@ static void nf_ip6_saveroute(const struct sk_buff *skb,
 }
 
 static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
-		      unsigned int index, unsigned int queuenum)
+		      u16 index, u16 queue_flags, unsigned int queuenum)
 {
 	struct nf_queue_entry *entry = NULL;
 	const struct nf_queue_handler *qh;
@@ -191,6 +191,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
 		.skb	= skb,
 		.state	= *state,
 		.hook_index = index,
+		.queue_flags = queue_flags,
 		.size	= sizeof(*entry) + route_key_size,
 	};
 
@@ -222,7 +223,9 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
 {
 	int ret;
 
-	ret = __nf_queue(skb, state, index, verdict >> NF_VERDICT_QBITS);
+	ret = __nf_queue(skb, state, index,
+			 verdict & NF_VERDICT_FLAG_USERSPACE_CT_HELPER,
+			 verdict >> NF_VERDICT_QBITS);
 	if (ret < 0) {
 		if (ret == -ESRCH &&
 		    (verdict & NF_VERDICT_FLAG_QUEUE_BYPASS))
net/netfilter/nfnetlink_cthelper.c +3 -1
index a5f294aa8e4c..55aa5bacc603 100644
@@ -60,7 +60,9 @@ nfnl_userspace_cthelper(struct sk_buff *skb, unsigned int protoff,
 		return NF_ACCEPT;
 
 	/* If the user-space helper is not available, don't block traffic. */
-	return NF_QUEUE_NR(helper->queue_num) | NF_VERDICT_FLAG_QUEUE_BYPASS;
+	return NF_QUEUE_NR(helper->queue_num) |
+	       NF_VERDICT_FLAG_QUEUE_BYPASS |
+	       NF_VERDICT_FLAG_USERSPACE_CT_HELPER;
 }
 
 static const struct nla_policy nfnl_cthelper_tuple_pol[NFCTH_TUPLE_MAX+1] = {
net/netfilter/nfnetlink_queue.c +18 -8
index 3243a31f6e82..ddb4a32f6ba5 100644
@@ -223,22 +223,32 @@ find_dequeue_entry(struct nfqnl_instance *queue, unsigned int id)
 	return entry;
 }
 
+static bool nfqnl_skb_needs_ct_update(struct sk_buff *skb)
+{
+	enum ip_conntrack_info ctinfo;
+	const struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
+
+	return ct && !nf_ct_is_confirmed(ct);
+}
+
 static void nfqnl_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 {
 	struct nf_ct_hook *ct_hook;
-	int err;
 
 	if (verdict == NF_ACCEPT ||
 	    verdict == NF_REPEAT ||
 	    verdict == NF_STOP) {
-		rcu_read_lock();
+		bool nf_ct_helper = false;
+
 		ct_hook = rcu_dereference(nf_ct_hook);
-		if (ct_hook) {
-			err = ct_hook->update(entry->state.net, entry->skb);
-			if (err < 0)
-				verdict = NF_DROP;
-		}
-		rcu_read_unlock();
+		if (!ct_hook)
+			return nf_reinject(entry, verdict);
+
+		nf_ct_helper = entry->queue_flags & NF_VERDICT_FLAG_USERSPACE_CT_HELPER;
+
+		if (nfqnl_skb_needs_ct_update(entry->skb) || nf_ct_helper)
+			verdict = ct_hook->update(entry->state.net, entry->skb,
+						  entry->queue_flags);
 	}
 	nf_reinject(entry, verdict);
 }
Signature · 1 line
2.26.2
#10 lore raw
In reply to Florian Westphal
Quoted 7 lines · Florian Westphal
Quoted 2 lines · Jacob Rasmussen

I'm encountering a bug on Chrome OS that I believe to be caused by commit 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad and I was wondering if there was any update on a fix/revert landing for this. If a fix has already landed would anyone mind pointing me to the specific commit because I haven't been able to find it on my own.

Right, sorry about this.
Its most definitely caused by 827318feb69cb07ed58bb9b9dd6c2eaa81a116ad.

Quoted 6 lines

Unfortunately I have no easy way to validate the fix.
If you could help speeding this up it would be great if you could test the candidate fix which I will send in a minute.

I've checked that it doesn't break conntrack in obvious ways and that nft_queue.sh self test still passes.

Ah, my fault, I completely forgot this. Hopefully I'll be able to test the fix this weekend.

Michal