Skip to contentSkip to conversation

br_netfilter: Drop dst references before setting.

PATCH Superseded Harsh Modi 2 participants 2 messages Aug 23, 2022 – Aug 24, 2022

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Harsh Modi

author
#0 lore raw

PATCH 1/1 br_netfilter: Drop dst references before setting.

It is possible that there is already a dst allocated. If it is not released, it will be leaked. This is similar to what is done in bpf_set_tunnel_key().

---
 net/bridge/br_netfilter_hooks.c | 2 ++
 1 file changed, 2 insertions(+)
net/bridge/br_netfilter_hooks.c +2 -0
index ff4779036649..f20f4373ff40 100644
@@ -384,6 +384,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
 				/* - Bridged-and-DNAT'ed traffic doesn't
 				 *   require ip_forwarding. */
 				if (rt->dst.dev == dev) {
+					skb_dst_drop(skb);
 					skb_dst_set(skb, &rt->dst);
 					goto bridged_dnat;
 				}
@@ -413,6 +414,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
 			kfree_skb(skb);
 			return 0;
 		}
+		skb_dst_drop(skb);
 		skb_dst_set_noref(skb, &rt->dst);
 	}
 
Signature · 1 line
2.37.1.595.g718a3a8f04-goog
#1 lore raw

Hi,

Quoted 1 line · Harsh Modi

It is possible that there is already a dst allocated.

This is bridge path, do you know what might have already set up the dst to the skbuff? Is this a theoretical issue or you are observing a dst leak there?

Quoted 31 lines

If it is not released, it will be leaked. This is similar to what is done in bpf_set_tunnel_key().

---
 net/bridge/br_netfilter_hooks.c | 2 ++
 1 file changed, 2 insertions(+)
net/bridge/br_netfilter_hooks.c +2 -0
index ff4779036649..f20f4373ff40 100644
@@ -384,6 +384,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
 				/* - Bridged-and-DNAT'ed traffic doesn't
 				 *   require ip_forwarding. */
 				if (rt->dst.dev == dev) {
+					skb_dst_drop(skb);
 					skb_dst_set(skb, &rt->dst);
 					goto bridged_dnat;
 				}
@@ -413,6 +414,7 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
 			kfree_skb(skb);
 			return 0;
 		}
+		skb_dst_drop(skb);
 		skb_dst_set_noref(skb, &rt->dst);
 	}
 
Signature · 1 line
2.37.1.595.g718a3a8f04-goog