From: Rongguang Wei <weir…@kylinos.cn> This series fixes attaching a queue to a TAP device, which re-installs the socket filter saved by TUNATTACHFILTER. TUNATTACHFILTER keeps only the sock_fprog header, so the instructions are read from user space again for every queue that is attached later. With the inverted check in tun_attach(), a failure there attaches the queue without a filter, while a success returns early and leaves the queue unpublished. Keep the program on the device instead, run it from tun_net_xmit(), and record IFF_NOFILTER per queue. Patch 1 does that, patch 2 adds selftests for the re-attach, for bad programs with and without queues, and for the IFF_NOFILTER paths. The removal of the sk_attach_filter() and sk_detach_filter() exports is not part of this series: it is a net-next cleanup and will be sent separately once this fix is in. Thanks to Willem de Bruijn and Alexei Starovoitov for the reviews. --- v13: - drop the net/core/filter.c hunk: removing the two exports is a net-next cleanup and will be sent separately once this fix is in - describe the full scope of the inverted check and the runtime differences from sk_filter_trim_cap() - selftests: check that the re-attached queue is not left disabled, and fix a comment about the active queues v12: - drop the EXPORT_SYMBOL_GPL() of sk_attach_filter() and sk_detach_filter() - https://lore.kernel.org/netdev/2026…@163.com/ v11: - keep one program on the device instead of a copy per queue, as Alexei suggested; sk_attach_filter_kern() and bpf_prog_validate_classic() are gone with it - TUNDETACHFILTER now applies to queues detached with IFF_DETACH_QUEUE too - selftests: cover the zero-queue and detached-queue paths - https://lore.kernel.org/netdev/2026…@163.com/ v10: - add b…@vger.kernel.org and the BPF maintainers to Cc - selftests: fix the queue numbering and add a zero-queue case - https://lore.kernel.org/netdev/2026…@163.com/ v9: - zero the whole sock_fprog header, so that the padding TUNGETFILTER copies is not uninitialized stack - https://lore.kernel.org/netdev/2026…@163.com/ v8: - narrow the bpf_prog_validate_classic() contract to the classic verifier and note that it can also return -ENOMEM - commit the new program only after every queue took it - https://lore.kernel.org/netdev/2026…@163.com/ v7: - verify the instructions before anything is replaced - fix the kernel-doc of sk_attach_filter_kern() - reject a program whose length is out of range before allocating memory - selftests: add a case for a rejected program with valid length and bad instructions - https://lore.kernel.org/netdev/2026…@163.com/ v6: - add description for return value of sk_attach_filter_kern() - https://lore.kernel.org/netdev/2026…@163.com/ v5: - add kernel-doc for sk_attach_filter_kern() - fix the wording of the mprotect() comment - https://lore.kernel.org/netdev/2026…@163.com/ v4: - merge the kernel copy and the error check into one patch - charge the kernel copy to the caller's memory cgroup - https://lore.kernel.org/netdev/2026…@163.com/ v3: - reorder: the kernel copy of the program comes before the corrected error check - add sk_attach_filter_kern() in the patch that first uses it - https://lore.kernel.org/netdev/2026…@163.com/ v2: - roll back the filter attach when a later step of tun_attach() fails - keep a copy of the program in the kernel - add selftests for the re-attach and for a rejected TUNATTACHFILTER - https://lore.kernel.org/netdev/2026…@163.com/ v1: - https://lore.kernel.org/netdev/2026…@163.com/ Rongguang Wei (2): tun: keep the socket filter on the device selftests: net: add TAP socket filter attach tests drivers/net/tun.c | 93 ++++---- tools/testing/selftests/net/tun.c | 362 ++++++++++++++++++++++++++++++ 2 files changed, 405 insertions(+), 50 deletions(-) base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 2.25.1 No virus found Checked by Hillstone Network AntiVirus