From: Daniel Borkmann Accept full SOCK_RCU_FREE sockets, including listeners, on TC egress, taking an skb-owned reference. Request and time-wait sockets remain unsupported. The BPF TPROXY use case needs to assign a listening socket (e.g. Envoy proxy) to an skb from tc egress. With netkit, the BPF program runs on the container's egress side and returns NETKIT_PASS, which delivers the skb to the host via __netif_rx -> backlog. The fq qdisc discards listener assignments; ordinary loopback also drops egress assignments. Both can miss the selected proxy even without GSO. 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: Kuniyuki Iwashima CC: Paul Chaignon CC: Alasdair McWilliam CC: netdev@vger.kernel.org include/uapi/linux/bpf.h | 5 +++-- net/core/filter.c | 3 +-- tools/include/uapi/linux/bpf.h | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 45e3018fb2ae..e8a7ebee305c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -4612,7 +4612,8 @@ union bpf_attr { * interfere with successful delivery to the socket. * * This operation is valid from TC ingress and egress paths. - * On egress, only full refcounted sockets are accepted. + * On egress, only full sockets are accepted. Assignment takes an + * skb-owned reference and releases any previous send-side owner. * Software GSO segmentation after assignment is unsupported. * * The *flags* argument must be zero. @@ -4626,7 +4627,7 @@ union bpf_attr { * **-ENETUNREACH** if the socket is unreachable (wrong netns). * * **-EOPNOTSUPP** if the socket is unhashed, or TC egress uses - * a non-full or non-refcounted socket or a decrypted packet. + * a non-full socket or a decrypted packet. * * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags) * Description diff --git a/net/core/filter.c b/net/core/filter.c index feeb752f7a00..4dea2cc84712 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -8123,8 +8123,7 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags) if (!sk || flags != 0) return -EINVAL; - if (egress && (!sk_fullsock(sk) || !sk_is_refcounted(sk) || - skb_is_decrypted(skb))) + if (egress && (!sk_fullsock(sk) || skb_is_decrypted(skb))) return -EOPNOTSUPP; refcounted = egress || sk_is_refcounted(sk); if (unlikely(dev_net(skb->dev) != sock_net(sk))) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 45e3018fb2ae..e8a7ebee305c 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -4612,7 +4612,8 @@ union bpf_attr { * interfere with successful delivery to the socket. * * This operation is valid from TC ingress and egress paths. - * On egress, only full refcounted sockets are accepted. + * On egress, only full sockets are accepted. Assignment takes an + * skb-owned reference and releases any previous send-side owner. * Software GSO segmentation after assignment is unsupported. * * The *flags* argument must be zero. @@ -4626,7 +4627,7 @@ union bpf_attr { * **-ENETUNREACH** if the socket is unreachable (wrong netns). * * **-EOPNOTSUPP** if the socket is unhashed, or TC egress uses - * a non-full or non-refcounted socket or a decrypted packet. + * a non-full socket or a decrypted packet. * * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags) * Description -- 2.47.3