Skip to contentSkip to conversation

openvswitch: Fix conntrack cache with timeout

PATCH In review Yi-Hung Wei 3 participants 5 messages Aug 22, 2019 – Aug 25, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 openvswitch: Fix conntrack cache with timeout

This patch addresses a conntrack cache issue with timeout policy. Currently, we do not check if the timeout extension is set properly in the cached conntrack entry. Thus, after packet recirculate from conntrack action, the timeout policy is not applied properly. This patch fixes the aforementioned issue.

Fixes 06bd2bdf19d2 ("openvswitch: Add timeout support to ct action")

---
v1->v2: Fix rcu dereference issue reported by kbuild test robot.

---
 net/openvswitch/conntrack.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
net/openvswitch/conntrack.c +13 -0
index 848c6eb55064..4d7896135e73 100644
@@ -67,6 +67,7 @@ struct ovs_conntrack_info {
 	struct md_mark mark;
 	struct md_labels labels;
 	char timeout[CTNL_TIMEOUT_NAME_MAX];
+	struct nf_ct_timeout *nf_ct_timeout;
 #if IS_ENABLED(CONFIG_NF_NAT)
 	struct nf_nat_range2 range;  /* Only present for SRC NAT and DST NAT. */
 #endif
@@ -697,6 +698,14 @@ static bool skb_nfct_cached(struct net *net,
 		if (help && rcu_access_pointer(help->helper) != info->helper)
 			return false;
 	}
+	if (info->nf_ct_timeout) {
+		struct nf_conn_timeout *timeout_ext;
+
+		timeout_ext = nf_ct_timeout_find(ct);
+		if (!timeout_ext || info->nf_ct_timeout !=
+		    rcu_dereference(timeout_ext->timeout))
+			return false;
+	}
 	/* Force conntrack entry direction to the current packet? */
 	if (info->force && CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) {
 		/* Delete the conntrack entry if confirmed, else just release
@@ -1657,6 +1666,10 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
 				      ct_info.timeout))
 			pr_info_ratelimited("Failed to associated timeout "
 					    "policy `%s'\n", ct_info.timeout);
+		else
+			ct_info.nf_ct_timeout = rcu_dereference(
+				nf_ct_timeout_find(ct_info.ct)->timeout);
+
 	}
 
 	if (helper) {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 44 lines · Yi-Hung Wei

This patch addresses a conntrack cache issue with timeout policy. Currently, we do not check if the timeout extension is set properly in the cached conntrack entry. Thus, after packet recirculate from conntrack action, the timeout policy is not applied properly. This patch fixes the aforementioned issue.

Fixes 06bd2bdf19d2 ("openvswitch: Add timeout support to ct action")

---
v1->v2: Fix rcu dereference issue reported by kbuild test robot.

---
 net/openvswitch/conntrack.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
net/openvswitch/conntrack.c +9 -0
index 848c6eb55064..4d7896135e73 100644
@@ -67,6 +67,7 @@ struct ovs_conntrack_info {
        struct md_mark mark;
        struct md_labels labels;
        char timeout[CTNL_TIMEOUT_NAME_MAX];
+       struct nf_ct_timeout *nf_ct_timeout;
 #if IS_ENABLED(CONFIG_NF_NAT)
        struct nf_nat_range2 range;  /* Only present for SRC NAT and DST NAT. */
 #endif
@@ -697,6 +698,14 @@ static bool skb_nfct_cached(struct net *net,
                if (help && rcu_access_pointer(help->helper) != info->helper)
                        return false;
        }
+       if (info->nf_ct_timeout) {
+               struct nf_conn_timeout *timeout_ext;
+
+               timeout_ext = nf_ct_timeout_find(ct);
+               if (!timeout_ext || info->nf_ct_timeout !=
+                   rcu_dereference(timeout_ext->timeout))
+                       return false;
+       }
        /* Force conntrack entry direction to the current packet? */
        if (info->force && CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) {
                /* Delete the conntrack entry if confirmed, else just release

net/openvswitch/conntrack.c int ovs_ct_copy_action(struct net *net, const struct nlattr *attr, · line 1671

Quoted 6 lines
net/openvswitch/conntrack.c +3 -0
@@ -1657,6 +1666,10 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
                                      ct_info.timeout))
                        pr_info_ratelimited("Failed to associated timeout "
                                            "policy `%s'\n", ct_info.timeout);
+               else
+                       ct_info.nf_ct_timeout = rcu_dereference(
+                               nf_ct_timeout_find(ct_info.ct)->timeout);

Is this dereference safe from NULL pointer?

#2 lore raw
Quoted 18 lines · Pravin Shelar
Quoted 16 lines · Yi-Hung Wei

This patch addresses a conntrack cache issue with timeout policy. Currently, we do not check if the timeout extension is set properly in the cached conntrack entry. Thus, after packet recirculate from conntrack action, the timeout policy is not applied properly. This patch fixes the aforementioned issue.

Fixes 06bd2bdf19d2 ("openvswitch: Add timeout support to ct action")

---
v1->v2: Fix rcu dereference issue reported by kbuild test robot.

---
 net/openvswitch/conntrack.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 12 lines

net/openvswitch/conntrack.c int ovs_ct_copy_action(struct net *net, const struct nlattr *attr, · line 1671

Quoted 11 lines
net/openvswitch/conntrack.c +3 -0
index 848c6eb55064..4d7896135e73 100644
@@ -1657,6 +1666,10 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
                                      ct_info.timeout))
                        pr_info_ratelimited("Failed to associated timeout "
                                            "policy `%s'\n", ct_info.timeout);
+               else
+                       ct_info.nf_ct_timeout = rcu_dereference(
+                               nf_ct_timeout_find(ct_info.ct)->timeout);

Is this dereference safe from NULL pointer?

Hi Pravin,

Thanks for your review. I am not sure if nf_ct_timeout_find(ct_info.ct) will return NULL in this case.

We only run into this statement when ct_info.timeout[0] is set, and it is only set in parse_ct() when CONFIG_NF_CONNTRACK_TIMEOUT is configured. Also, in this else condition the timeout extension is supposed to be set properly by nf_ct_set_timeout().

Am I missing something?

Thanks,

-Yi-Hung

Acked-by
#3 lore raw
Quoted 35 lines · Yi-Hung Wei
Quoted 18 lines · Pravin Shelar
Quoted 16 lines · Yi-Hung Wei

This patch addresses a conntrack cache issue with timeout policy. Currently, we do not check if the timeout extension is set properly in the cached conntrack entry. Thus, after packet recirculate from conntrack action, the timeout policy is not applied properly. This patch fixes the aforementioned issue.

Fixes 06bd2bdf19d2 ("openvswitch: Add timeout support to ct action")

---
v1->v2: Fix rcu dereference issue reported by kbuild test robot.

---
 net/openvswitch/conntrack.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 12 lines

net/openvswitch/conntrack.c int ovs_ct_copy_action(struct net *net, const struct nlattr *attr, · line 1671

Quoted 11 lines
net/openvswitch/conntrack.c +3 -0
index 848c6eb55064..4d7896135e73 100644
@@ -1657,6 +1666,10 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
                                      ct_info.timeout))
                        pr_info_ratelimited("Failed to associated timeout "
                                            "policy `%s'\n", ct_info.timeout);
+               else
+                       ct_info.nf_ct_timeout = rcu_dereference(
+                               nf_ct_timeout_find(ct_info.ct)->timeout);

Is this dereference safe from NULL pointer?

Hi Pravin,

Quoted 8 lines

Thanks for your review. I am not sure if nf_ct_timeout_find(ct_info.ct) will return NULL in this case.

We only run into this statement when ct_info.timeout[0] is set, and it is only set in parse_ct() when CONFIG_NF_CONNTRACK_TIMEOUT is configured. Also, in this else condition the timeout extension is supposed to be set properly by nf_ct_set_timeout().

Sounds good.

Thanks,
Pravin.

maintainer
#4 lore raw
In reply to Yi-Hung Wei

From: Yi-Hung Wei <[email protected]>
Date: Thu, 22 Aug 2019 13:17:50 -0700

Quoted 9 lines

This patch addresses a conntrack cache issue with timeout policy. Currently, we do not check if the timeout extension is set properly in the cached conntrack entry. Thus, after packet recirculate from conntrack action, the timeout policy is not applied properly. This patch fixes the aforementioned issue.

Fixes 06bd2bdf19d2 ("openvswitch: Add timeout support to ct action")

Applied and queued up for -stable, thanks.