Skip to contentSkip to conversation

openvswitch: Fix conntrack cache with timeout

PATCH Superseded Yi-Hung Wei 2 participants 3 messages Aug 22, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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")
---
 net/openvswitch/conntrack.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
net/openvswitch/conntrack.c +13 -0
index 848c6eb55064..45498fcf540d 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 != 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 =
+				nf_ct_timeout_find(ct_info.ct)->timeout;
+
 	}
 
 	if (helper) {
Signature · 1 line
2.7.4
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Yi-Hung,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]

url: https://github.com/0day-ci/linux/commits/Yi-Hung-Wei/openvswitch-Fix-conntrack-cache-with-timeout/20190822-212539
reproduce:

        # apt-get install sparse
        # sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag

sparse warnings: (new ones prefixed by >>)

include/linux/sched.h:609:43: sparse: sparse: bad integer constant expression include/linux/sched.h:609:73: sparse: sparse: invalid named zero-width bitfield value' include/linux/sched.h:610:43: sparse: sparse: bad integer constant expression include/linux/sched.h:610:67: sparse: sparse: invalid named zero-width bitfield bucket_id'

>> net/openvswitch/conntrack.c:706:41: sparse: sparse: incompatible types in comparison expression (different address spaces):
>> net/openvswitch/conntrack.c:706:41: sparse:    struct nf_ct_timeout *
>> net/openvswitch/conntrack.c:706:41: sparse:    struct nf_ct_timeout [noderef] <asn:4> *

vim +706 net/openvswitch/conntrack.c

670
671 /* Determine whether skb->_nfct is equal to the result of conntrack lookup. */
672 static bool skb_nfct_cached(struct net *net,

   673				    const struct sw_flow_key *key,
   674				    const struct ovs_conntrack_info *info,
   675				    struct sk_buff *skb)
   676	{
   677		enum ip_conntrack_info ctinfo;
   678		struct nf_conn *ct;
   679		bool ct_executed = true;
   680	
   681		ct = nf_ct_get(skb, &ctinfo);
   682		if (!ct)
   683			ct = ovs_ct_executed(net, key, info, skb, &ct_executed);
   684	
   685		if (ct)
   686			nf_ct_get(skb, &ctinfo);
   687		else
   688			return false;
   689	
   690		if (!net_eq(net, read_pnet(&ct->ct_net)))
   691			return false;
   692		if (!nf_ct_zone_equal_any(info->ct, nf_ct_zone(ct)))
   693			return false;
   694		if (info->helper) {
   695			struct nf_conn_help *help;
   696	
   697			help = nf_ct_ext_find(ct, NF_CT_EXT_HELPER);
   698			if (help && rcu_access_pointer(help->helper) != info->helper)
   699				return false;
   700		}
   701		if (info->nf_ct_timeout) {
   702			struct nf_conn_timeout *timeout_ext;
   703	
   704			timeout_ext = nf_ct_timeout_find(ct);
   705			if (!timeout_ext ||
 > 706			    info->nf_ct_timeout != timeout_ext->timeout)

707 return false;
708 }
709 /* Force conntrack entry direction to the current packet? */
710 if (info->force && CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) {
711 /* Delete the conntrack entry if confirmed, else just release
712 * the reference.
713 */
714 if (nf_ct_is_confirmed(ct))
715 nf_ct_delete(ct, 0, 0);
716
717 nf_conntrack_put(&ct->ct_general);
718 nf_ct_set(skb, NULL, 0);
719 return false;
720 }
721
722 return ct_executed;
723 }
724

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
Quoted 18 lines · kbuild test robot

Hi Yi-Hung,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]

url: https://github.com/0day-ci/linux/commits/Yi-Hung-Wei/openvswitch-Fix-conntrack-cache-with-timeout/20190822-212539
reproduce:

        # apt-get install sparse
        # sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag

Quoted 9 lines

sparse warnings: (new ones prefixed by >>)

include/linux/sched.h:609:43: sparse: sparse: bad integer constant expression include/linux/sched.h:609:73: sparse: sparse: invalid named zero-width bitfield value' include/linux/sched.h:610:43: sparse: sparse: bad integer constant expression include/linux/sched.h:610:67: sparse: sparse: invalid named zero-width bitfield bucket_id'

Quoted 3 lines
Quoted 3 lines

net/openvswitch/conntrack.c:706:41: sparse: sparse: incompatible types in comparison expression (different address spaces):
net/openvswitch/conntrack.c:706:41: sparse: struct nf_ct_timeout *
net/openvswitch/conntrack.c:706:41: sparse: struct nf_ct_timeout [noderef] <asn:4> *

My v1 does not take care of the rcu pointer properly. I will fix the reported issue and send v2.

Thanks,

-Yi-Hung