net/openvswitch: Delete conntrack entry clashing with an expectation.
Subsystems (3)
PATCH v3 1/1 net/openvswitch: Delete conntrack entry clashing with an expectation.
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also, nf_conntrack_in() will check expectations (via init_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.
It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following nf_conntrack_in() call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.
---
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
net/openvswitch/conntrack.c +30 -1
@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb) { struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); + +if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing +* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the +* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ + + h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general); + } + } + +return exp; }/* This replicates logic from nf_conntrack_core.c that is not exported. */
Signature · 1 line
2.1.4
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.
Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 12 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +0
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb)
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 10 lines
net/openvswitch/conntrack.c +4
-1{struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +
Extraneous whitespace^
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the +* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +
Extraneous whitespace^
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 545
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);
Do we need the extra nf_conntrack_put() here? If nf_conntrack_find_get() returns an entry, we'll call nf_ct_delete() which releases a reference on the CT entry.
Quoted 49 lines · Joe Stringer
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 16 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +1
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb) { struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;
Quoted 9 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 6 lines
net/openvswitch/conntrack.c +3
-1if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +Extraneous whitespace^
You mean the empty line?
Quoted 26 lines
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the +* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +Extraneous whitespace^
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 545
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);
Quoted 3 lines
Do we need the extra
nf_conntrack_put()here? Ifnf_conntrack_find_get()returns an entry, we'll callnf_ct_delete()which releases a reference on the CT entry.
There is one reference held by the table, but nf_conntrack_find_get() takes another. nf_ct_delete() releases the reference held by the table as the entry is removed, but we need to explicitly release the reference taken by nf_conntrack_find_get().
Jarno
Joe Stringer
Acked-byQuoted 59 lines · Jarno Rajahalme
Quoted 49 lines · Joe Stringer
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 16 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +1
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb) { struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;Quoted 9 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 6 lines
net/openvswitch/conntrack.c +3
-1if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +Extraneous whitespace^
Quoted 1 line
You mean the empty line?
Yeah.
Quoted 26 lines
Quoted 26 lines
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the +* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +Extraneous whitespace^
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);
Quoted 5 lines
Quoted 3 lines
Do we need the extra
nf_conntrack_put()here? Ifnf_conntrack_find_get()returns an entry, we'll callnf_ct_delete()which releases a reference on the CT entry.There is one reference held by the table, but
nf_conntrack_find_get()takes another.nf_ct_delete()releases the reference held by the table as the entry is removed, but we need to explicitly release the reference taken bynf_conntrack_find_get().
Ah, makes sense.
Did you intend for Pablo to take this? Pablo, is this fine or should Jarno resubmit against net?
Pablo Neira Ayuso
maintainerQuoted 60 lines · Joe Stringer
Quoted 59 lines · Jarno Rajahalme
Quoted 58 lines · Joe Stringer
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 12 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +0
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb)net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 10 lines
net/openvswitch/conntrack.c +4
-1{struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +Extraneous whitespace^
Quoted 3 lines
Quoted 1 line
You mean the empty line?
Yeah.
I can remove this here before applying if that is fine to you, so you don't need to resubmit.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing +* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +Extraneous whitespace^
We're converging to netdev comment style, ie.
* ...
* established packets.
*/
I know we have a bunch of comments in netfilter ending like the one above, but ideally it would be good to use this comment style.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 545
Quoted 7 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);Do we need the extra
nf_conntrack_put()here? Ifnf_conntrack_find_get()returns an entry, we'll callnf_ct_delete()which releases a reference on the CT entry.
Quoted 8 lines
Quoted 1 line
There is one reference held by the table, but
nf_conntrack_find_get()takes another.nf_ct_delete()releases the reference held by the table as the entry is removed, but we need to explicitly release the reference taken bynf_conntrack_find_get().Ah, makes sense.
Acked-by Joe Stringer <[email protected]>Did you intend for Pablo to take this? Pablo, is this fine or should Jarno resubmit against net?
I can take this, yes.
Quoted 64 lines · Pablo Neira Ayuso
Quoted 60 lines · Joe Stringer
Quoted 59 lines · Jarno Rajahalme
Quoted 58 lines · Joe Stringer
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 12 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +0
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb)net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 10 lines
net/openvswitch/conntrack.c +4
-1{struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +Extraneous whitespace^
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
You mean the empty line?
Yeah.
I can remove this here before applying if that is fine to you, so you don't need to resubmit.
Yes, fine by me! Thank you!
Jarno
Quoted 50 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing +* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +Extraneous whitespace^
We're converging to netdev comment style, ie.
* ...
* established packets.
*/I know we have a bunch of comments in netfilter ending like the one above, but ideally it would be good to use this comment style.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 545
Quoted 7 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);Do we need the extra
nf_conntrack_put()here? Ifnf_conntrack_find_get()returns an entry, we'll callnf_ct_delete()which releases a reference on the CT entry.Quoted 8 lines
Quoted 1 line
There is one reference held by the table, but
nf_conntrack_find_get()takes another.nf_ct_delete()releases the reference held by the table as the entry is removed, but we need to explicitly release the reference taken bynf_conntrack_find_get().Ah, makes sense.
Acked-by Joe Stringer <[email protected]>Did you intend for Pablo to take this? Pablo, is this fine or should Jarno resubmit against net?
I can take this, yes.
Pablo,
Were you waiting for a v4 or are you ready to take this as-is?
Jarno
Quoted 128 lines · Jarno Rajahalme
Quoted 65 lines · Pablo Neira Ayuso
Quoted 60 lines · Joe Stringer
Quoted 59 lines · Jarno Rajahalme
Quoted 58 lines · Joe Stringer
Quoted 22 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.Quoted 4 lines
Fixes 7f8a436eaa2c ("openvswitch: Add conntrack action")Reported-by Yang Song <[email protected]>Signed-off-by Jarno Rajahalme <[email protected]>---
Hi Jarno,
Quoted 12 lines
v3: Removed unnecessary if statement.
v2: Fixed commit title.
net/openvswitch/conntrack.c| 31 ++++++++++++++++++++++++++++++-1 file changed, 30 insertions(+), 1 deletion(-)net/openvswitch/conntrack.c +0
-0@@ -514,10 +514,39 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, u16 proto, const struct sk_buff *skb)net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 523
Quoted 10 lines
net/openvswitch/conntrack.c +4
-1{struct nf_conntrack_tuple tuple; +struct nf_conntrack_expect *exp;if (!nf_ct_get_tuplepr (skb,skb_network_offset (skb), proto, net, &tuple))return NULL ; -return __nf_ct_expect_find (net, zone, &tuple); + + exp =__nf_ct_expect_find (net, zone, &tuple); +Extraneous whitespace^
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
You mean the empty line?
Yeah.
I can remove this here before applying if that is fine to you, so you don't need to resubmit.
Yes, fine by me! Thank you!
Jarno
Quoted 50 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
net/openvswitch/conntrack.c +10
-0+if (exp) { +struct nf_conntrack_tuple_hash *h; + +/* Delete existing conntrack entry, if it clashes with the +* expectation. This can happen since conntrack ALGs do not +* check for clashes between (new) expectations and existing +* conntrack entries. nf_conntrack_in() will check the +* expectations only if a conntrack entry can not be found, +* which can lead to OVS finding the expectation (here) in the +* init direction, but which will not be removed by the Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 539
Quoted 6 lines
net/openvswitch/conntrack.c +6
-0+* nf_conntrack_in() call, if a matching conntrack entry is +* found instead. In this case all init direction packets +* would be reported as new related packets, while reply +* direction packets would be reported as un-related +* established packets. */ +Extraneous whitespace^
We're converging to netdev comment style, ie.
* ...
* established packets.
*/I know we have a bunch of comments in netfilter ending like the one above, but ideally it would be good to use this comment style.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
net/openvswitch/conntrack.c ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · line 545
Quoted 7 lines
net/openvswitch/conntrack.c +6
-0+ h =nf_conntrack_find_get (net, zone, &tuple); +if (h) { +struct nf_conn *ct =nf_ct_tuplehash_to_ctrack (h); + +nf_ct_delete (ct,0 ,0 ); +nf_conntrack_put (&ct->ct_general);Do we need the extra
nf_conntrack_put()here? Ifnf_conntrack_find_get()returns an entry, we'll callnf_ct_delete()which releases a reference on the CT entry.Quoted 8 lines
Quoted 1 line
There is one reference held by the table, but
nf_conntrack_find_get()takes another.nf_ct_delete()releases the reference held by the table as the entry is removed, but we need to explicitly release the reference taken bynf_conntrack_find_get().Ah, makes sense.
Acked-by Joe Stringer <[email protected]>Did you intend for Pablo to take this? Pablo, is this fine or should Jarno resubmit against net?
I can take this, yes.
Quoted 15 lines · Jarno Rajahalme
Conntrack helpers do not check for a potentially clashing conntrack entry when creating a new expectation. Also,
nf_conntrack_in()will check expectations (viainit_conntrack()) only if a conntrack entry can not be found. The expectation for a packet which also matches an existing conntrack entry will not be removed by conntrack, and is currently handled inconsistently by OVS, as OVS expects the expectation to be removed when the connection tracking entry matching that expectation is confirmed.It should be noted that normally an IP stack would not allow reuse of a 5-tuple of an old (possibly lingering) connection for a new data connection, so this is somewhat unlikely corner case. However, it is possible that a misbehaving source could cause conntrack entries be created that could then interfere with new related connections.
Quoted 6 lines
Fix this in the OVS module by deleting the clashing conntrack entry after an expectation has been matched. This causes the following
nf_conntrack_in()call also find the expectation and remove it when creating the new conntrack entry, as well as the forthcoming reply direction packets to match the new related connection instead of the old clashing conntrack entry.
Applied, with minor changes that we have already discussed here.
Thanks.