Skip to contentSkip to conversation

netfilter: nf_conntrack_bridge: Fix not free when error

PATCH In review Yajun Deng 2 participants 4 messages Jul 26, 2021 – Jul 29, 2021

Subsystems (4)
lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH 1/1 netfilter: nf_conntrack_bridge: Fix not free when error

It should be added kfree_skb_list() when err is not equal to zero in nf_br_ip_fragment().

Fixes 3c171f496ef5 ("netfilter: bridge: add connection tracking system")
---
 net/bridge/netfilter/nf_conntrack_bridge.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +8 -4
index 8d033a75a766..059f53903eda 100644
@@ -83,12 +83,16 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
 
 			skb->tstamp = tstamp;
 			err = output(net, sk, data, skb);
-			if (err || !iter.frag)
-				break;
-
+			if (err) {
+				kfree_skb_list(iter.frag);
+				return err;
+			}
+
+			if (!iter.frag)
+				return 0;
+
 			skb = ip_fraglist_next(&iter);
 		}
-		return err;
 	}
 slow_path:
 	/* This is a linearized skbuff, the original geometry is lost for us.
Signature · 1 line
2.32.0
#1 lore raw
Quoted 21 lines · Yajun Deng

It should be added kfree_skb_list() when err is not equal to zero in nf_br_ip_fragment().

Fixes 3c171f496ef5 ("netfilter: bridge: add connection tracking system")
---
 net/bridge/netfilter/nf_conntrack_bridge.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +1 -3
index 8d033a75a766..059f53903eda 100644
@@ -83,12 +83,16 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
 
 			skb->tstamp = tstamp;
 			err = output(net, sk, data, skb);
-			if (err || !iter.frag)
-				break;
-
+			if (err) {

net/bridge/netfilter/nf_conntrack_bridge.c static int nf_br_ip_fragment(struct net *net, struct sock *sk, · line 91

Quoted 10 lines
net/bridge/netfilter/nf_conntrack_bridge.c +7 -1
+				kfree_skb_list(iter.frag);
+				return err;
+			}
+
+			if (!iter.frag)
+				return 0;
+
 			skb = ip_fraglist_next(&iter);
 		}
-		return err;

Why removing this line above? It enters slow_path: on success.

This patch instead will keep this aligned with IPv6.

Quoted 6 lines
net/bridge/netfilter/nf_conntrack_bridge.c +0 -0
 	}
 slow_path:
 	/* This is a linearized skbuff, the original geometry is lost for us.
Signature · 1 line
2.32.0
net/bridge/netfilter/nf_conntrack_bridge.c +5 -0
index 8d033a75a766..3cf5457919c6 100644
@@ -88,6 +88,11 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
 
 			skb = ip_fraglist_next(&iter);
 		}
+
+		if (!err)
+			return 0;
+
+		kfree_skb_list(iter.frag_list);
 		return err;
 	}
 slow_path:
#2 lore raw
Quoted 28 lines · Pablo Neira Ayuso
Quoted 26 lines · Yajun Deng

It should be added kfree_skb_list() when err is not equal to zero in nf_br_ip_fragment().

Fixes 3c171f496ef5 ("netfilter: bridge: add connection tracking system")

---
net/bridge/netfilter/nf_conntrack_bridge.c | 12 ++++++++----

1 file changed, 8 insertions(+), 4 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +5 -3
index 8d033a75a766..059f53903eda 100644
@@ -83,12 +83,16 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
 
 skb->tstamp = tstamp;
 err = output(net, sk, data, skb);
- if (err || !iter.frag)
- break;
-
+ if (err) {
+ kfree_skb_list(iter.frag);
+ return err;
+ }
+
Quoted 9 lines

net/bridge/netfilter/nf_conntrack_bridge.c static int nf_br_ip_fragment(struct net *net, struct sock *sk,

Quoted 6 lines
net/bridge/netfilter/nf_conntrack_bridge.c +3 -1
+ if (!iter.frag)
+ return 0;
+
 skb = ip_fraglist_next(&iter);
 }
- return err;

Why removing this line above? It enters slow_path: on success.

I used return rather than break, it wouldn't enter the slow_path.

Quoted 2 lines

This patch instead will keep this aligned with IPv6.

I think err and !iter.frag are not related, there is no need to put them in an if statement, We still need to separate them after loop. So I separate them in loop and use return instead of break. In addition, if you insist, I will accept your patch.

Quoted 5 lines
Quoted 5 lines
net/bridge/netfilter/nf_conntrack_bridge.c +0 -0
 }

slow_path:
/* This is a linearized skbuff, the original geometry is lost for us. --
2.32.0

#3 lore raw
Quoted 39 lines · On Thu, Jul 29, 2021 at 03:19:01AM +0000, [email protected] wrote:
Quoted 28 lines · Pablo Neira Ayuso
Quoted 26 lines · Yajun Deng

It should be added kfree_skb_list() when err is not equal to zero in nf_br_ip_fragment().

Fixes 3c171f496ef5 ("netfilter: bridge: add connection tracking system")

---
net/bridge/netfilter/nf_conntrack_bridge.c | 12 ++++++++----

1 file changed, 8 insertions(+), 4 deletions(-)
net/bridge/netfilter/nf_conntrack_bridge.c +5 -3
index 8d033a75a766..059f53903eda 100644
@@ -83,12 +83,16 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
 
 skb->tstamp = tstamp;
 err = output(net, sk, data, skb);
- if (err || !iter.frag)
- break;
-
+ if (err) {
+ kfree_skb_list(iter.frag);
+ return err;
+ }
+
Quoted 9 lines

net/bridge/netfilter/nf_conntrack_bridge.c static int nf_br_ip_fragment(struct net *net, struct sock *sk,

Quoted 6 lines
net/bridge/netfilter/nf_conntrack_bridge.c +3 -1
+ if (!iter.frag)
+ return 0;
+
 skb = ip_fraglist_next(&iter);
 }
- return err;

Why removing this line above? It enters slow_path: on success.

Quoted 1 line

I used return rather than break, it wouldn't enter the slow_path.

Right, your patch is correct.

Quoted 6 lines
Quoted 2 lines

This patch instead will keep this aligned with IPv6.

I think err and !iter.frag are not related, there is no need to put them in an if statement, We still need to separate them after loop. So I separate them in loop and use return instead of break. In addition, if you insist, I will accept your patch.

Thanks. Yes, I'd prefer to keep it consistent with existing users of the fragment iterator, see:

net/ipv4/ip_output.c
net/ipv6/netfilter.c
net/ipv6/ip6_output.c

they are roughly using the same programming idiom to iterate over the fragments.

Would you send a v2?