From: Daniel Borkmann Ingress bpf_sk_assign() can borrow an RCU-protected listener. Redirecting to a qdisc or receive backlog can outlive that protection. Orphan prefetched assignments before potentially queued redirects, including peer egress. Keep synchronous peer-ingress handoff unchanged. Fixes: 7ae215d23c12 ("bpf: Don't refcount LISTEN sockets in sk_assign()") Signed-off-by: Daniel Borkmann Signed-off-by: Nikolay Aleksandrov --- CC: Alexei Starovoitov CC: Daniel Borkmann CC: Andrii Nakryiko CC: Eduard Zingerman CC: Kumar Kartikeya Dwivedi CC: Martin KaFai Lau CC: Song Liu CC: Yonghong Song CC: Jiri Olsa CC: Emil Tsalapatis CC: Ihor Solodrai CC: John Fastabend CC: Stanislav Fomichev CC: David S. Miller CC: Eric Dumazet CC: Jakub Kicinski CC: Paolo Abeni CC: Simon Horman CC: Joe Stringer CC: Paul Chaignon CC: Alasdair McWilliam CC: netdev@vger.kernel.org net/core/filter.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 946b07a17fce..1ad57a371534 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2558,6 +2558,15 @@ int skb_do_redirect(struct sk_buff *skb) ri->flags = 0; if (unlikely(!dev)) goto out_drop; + + /* + * Prefetched sockets may borrow a listener under RCU. Orphan them + * before redirects that can outlive this section. Peer ingress + * stays in the same RCU section. + */ + if (skb_sk_is_prefetched(skb) && + (!(flags & BPF_F_PEER) || (flags & BPF_F_EGRESS))) + skb_orphan(skb); if (flags & BPF_F_PEER) { dev = skb_get_peer_dev(dev); if (unlikely(!dev || -- 2.47.3