bpf: Fix metadata_dst leak __bpf_redirect_neigh_v{4,6}
Subsystems (4)
Daniel Borkmann
maintainerPATCH 1/1 bpf: Fix metadata_dst leak __bpf_redirect_neigh_v{4,6}
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
The traffic is directed to the gateway via vxlan tunnel in collect md mode. A recent BPF change utilized the bpf_redirect_neigh() helper to forward packets after the arrival and decap on vxlan, which turned out over time that the kmalloc-256 slab usage in kernel was ever-increasing.
The issue was that vxlan allocates the metadata_dst object and attaches it through a fake dst entry to the skb. The latter was never released though given bpf_redirect_neigh() was merely setting the new dst entry via skb_dst_set() without dropping an existing one first.
--- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/filter.c +2 -0
@@ -2281,6 +2281,7 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,if (IS_ERR (dst)) goto out_drop; +skb_dst_drop (skb);skb_dst_set (skb, dst); }else if (nh->nh_family !=AF_INET6 ) { goto out_drop;
@@ -2389,6 +2390,7 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, goto out_drop; } +skb_dst_drop (skb);skb_dst_set (skb, &rt->dst); }
Signature · 1 line
2.43.0
Quoted 14 lines · Daniel Borkmann
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
The traffic is directed to the gateway via vxlan tunnel in collect md mode. A recent BPF change utilized the
bpf_redirect_neigh()helper to forward packets after the arrival and decap on vxlan, which turned out over time that the kmalloc-256 slab usage in kernel was ever-increasing.The issue was that vxlan allocates the
metadata_dstobject and attaches it through a fake dst entry to the skb. The latter was never released though givenbpf_redirect_neigh()was merely setting the new dst entry viaskb_dst_set()without dropping an existing one first.
Quoted 7 lines
Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")Reported-by Yusuke Suzuki <[email protected]>Reported-by Julian Wiedmann <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Cc Martin KaFai Lau <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Jordan Rife <[email protected]>
Quoted 48 lines · Daniel Borkmann
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
The traffic is directed to the gateway via vxlan tunnel in collect md mode. A recent BPF change utilized the
bpf_redirect_neigh()helper to forward packets after the arrival and decap on vxlan, which turned out over time that the kmalloc-256 slab usage in kernel was ever-increasing.The issue was that vxlan allocates the
metadata_dstobject and attaches it through a fake dst entry to the skb. The latter was never released though givenbpf_redirect_neigh()was merely setting the new dst entry viaskb_dst_set()without dropping an existing one first.Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")Reported-by Yusuke Suzuki <[email protected]>Reported-by Julian Wiedmann <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Cc Martin KaFai Lau <[email protected]>Cc Jakub Kicinski <[email protected]>Cc Jordan Rife <[email protected]>--- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+)net/core/filter.c +2
-0@@ -2281,6 +2281,7 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,if (IS_ERR (dst)) goto out_drop; +skb_dst_drop (skb);skb_dst_set (skb, dst); }else if (nh->nh_family !=AF_INET6 ) { goto out_drop;@@ -2389,6 +2390,7 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, goto out_drop; } +skb_dst_drop (skb);skb_dst_set (skb, &rt->dst); }Signature · 1 line
2.43.0
Nice catch!
Quoted 3 lines · On Fri, 3 Oct 2025 09:34:18 +0200 Daniel Borkmann wrote:
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
Nice! The warning Stan added at work?
Daniel Borkmann
maintainerQuoted 6 lines · Jakub Kicinski
Quoted 3 lines · On Fri, 3 Oct 2025 09:34:18 +0200 Daniel Borkmann wrote:
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
Nice! The warning Stan added at work?
We should add CONFIG_DEBUG_NET to our Cilium CI test kernels actually. The memory leak was observed on AWS nodes with the above Cilium config, so bpftrace came to the rescue in the end.
Thanks,
Daniel
Quoted 9 lines · Daniel Borkmann
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
The traffic is directed to the gateway via vxlan tunnel in collect md mode. A recent BPF change utilized the
bpf_redirect_neigh()helper to forward packets after the arrival and decap on vxlan, which turned out over time that the kmalloc-256 slab usage in kernel was ever-increasing.
Quoted 4 lines
The issue was that vxlan allocates the
metadata_dstobject and attaches it through a fake dst entry to the skb. The latter was never released though givenbpf_redirect_neigh()was merely setting the new dst entry viaskb_dst_set()without dropping an existing one first.
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Fri, 3 Oct 2025 09:34:18 +0200 you wrote:
Cilium has a BPF egress gateway feature which forces outgoing K8s Pod traffic to pass through dedicated egress gateways which then SNAT the traffic in order to interact with stable IPs outside the cluster.
The traffic is directed to the gateway via vxlan tunnel in collect md mode. A recent BPF change utilized the
bpf_redirect_neigh()helper to forward packets after the arrival and decap on vxlan, which turned out over time that the kmalloc-256 slab usage in kernel was ever-increasing.[...]
Here is the summary with links:
- [bpf] bpf: Fix metadata_dst leak __bpf_redirect_neigh_v{4,6}
https://git.kernel.org/bpf/bpf/c/23f3770e1a53
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html