Skip to content

Commit 7350d08

Browse files
bpf: don't use bpf_redirect_neigh() from overlay programs
Yusuke chased down a kernel bug [0] that causes memory leaks when bpf_redirect_neigh() is called from bpf_overlay. As work-around we can opt-out from using the helper, and going down the fallback path in the callers (eg treating it like a call from XDP context). [0]: https://lore.kernel.org/netdev/20251003073418.291171-1-daniel@iogearbox.net/T/#u Reported-by: Yusuke Suzuki <yusuke.suzuki@isovalent.com> Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
1 parent eb94bee commit 7350d08

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

bpf/lib/overloadable_skb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ redirect_self(const struct __sk_buff *ctx)
153153
static __always_inline __maybe_unused bool
154154
neigh_resolver_available(void)
155155
{
156+
/* Work around for
157+
* https://lore.kernel.org/netdev/20251003073418.291171-1-daniel@iogearbox.net
158+
*/
159+
if (is_defined(IS_BPF_OVERLAY))
160+
return false;
161+
156162
return true;
157163
}
158164

bpf/tests/overlay.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
/* Copyright Authors of Cilium */
3+
4+
#include <bpf/ctx/skb.h>
5+
#include "common.h"
6+
7+
#include "bpf_overlay.c"
8+
9+
CHECK("tc", "overlay_neigh_resolver")
10+
int overlay_neigh_resolver(__maybe_unused struct __sk_buff *ctx)
11+
{
12+
test_init();
13+
14+
/* Due to https://lore.kernel.org/netdev/20251003073418.291171-1-daniel@iogearbox.net
15+
* we shouldn't use bpf_redirect_neigh() from overlay programs.
16+
*/
17+
TEST("no_neigh_resolver_on_overlay", {
18+
assert(!neigh_resolver_available());
19+
});
20+
21+
test_finish();
22+
}

bpf/tests/tc_egressgw_redirect_from_overlay_with_egress_interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ static __always_inline __maybe_unused long
5353
mock_fib_lookup(void *ctx __maybe_unused, struct bpf_fib_lookup *params __maybe_unused,
5454
int plen __maybe_unused, __u32 flags __maybe_unused)
5555
{
56-
/* Should not need a FIB lookup, we provide the EGRESS_IFINDEX */
57-
return -1;
56+
params->ifindex = IFACE_IFINDEX;
57+
return 0;
5858
}
5959

6060
/* Test that a packet matching an egress gateway policy on the from-overlay program

0 commit comments

Comments
 (0)