Skip to content

tun: fix re-attaching the socket filter

Rongguang Wei bpf netdev 14 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v12 Latest2 patches 1 replyIn review
  2. v112 patches 4 repliesSuperseded
  3. v10 posting 2/22 patches 4 repliesSuperseded
Earlier versions · 11
VersionPostedPatchesRepliesStatus
v10 posting 1/21 of 2 patches0 repliesSuperseded
v92 patches5 repliesSuperseded
v82 patches3 repliesSuperseded
v72 patches4 repliesSuperseded
v62 patches1 replySuperseded
v5 posting 2/22 patches1 replySuperseded
v5 posting 1/22 patches1 replySuperseded
v42 patches3 repliesSuperseded
v33 patches7 repliesSuperseded
v24 patches6 repliesSuperseded
v11 patch2 repliesSuperseded

Changes in v12 from the cover letter

- drop the EXPORT_SYMBOL_GPL() of sk_attach_filter() and sk_detach_filter(), as Alexei asked. It is a cleanup on its own, so it goes in a separate patch and the stable backport of the fix does not carry it

Patches in v12 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tun: run the socket filter from tun_net_xmit()drivers/net/tun.c net/core/filter.c+43 -520 replies
2/2selftests: net: add TAP socket filter attach teststools/testing/selftests/net/tun.c+358 -00 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAlexei Starovoitov
SeriesA-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v12 thread

Cover letter [PATCH net v12 0/2] tun: fix re-attaching the socket filter

From: Rongguang Wei <[email protected]>

This series fixes attaching a queue to a TAP device, which re-installs the socket filter of a persistent device.

TUNATTACHFILTER keeps only the sock_fprog header, so the instructions are read from user space again for every queue that is attached later. Keep the program on the device instead, run it from tun_net_xmit(), and record IFF_NOFILTER per queue. Patch 1 does that. Also removes the exports of sk_attach_filter() and sk_detach_filter() because no caller in a module.

Patch 2 adds selftests for the re-attach, for bad programs with and without queues, and for the IFF_NOFILTER paths.

Thanks to Willem de Bruijn and Alexei Starovoitov for the reviews.

---
v12:
- drop the EXPORT_SYMBOL_GPL() of sk_attach_filter() and sk_detach_filter(), as Alexei asked. It is a cleanup on its own, so it goes in a separate patch and the stable backport of the fix does not carry it
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/[email protected]/
v10:
- add [email protected] and the BPF maintainers to Cc
- selftests: fix the queue numbering and add a zero-queue case
- https://lore.kernel.org/netdev/[email protected]/
v9:
- zero the whole sock_fprog header, so that the padding TUNGETFILTER copies is not uninitialized stack
- https://lore.kernel.org/netdev/[email protected]/
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/[email protected]/
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/[email protected]/
v6:
- add description for return value of sk_attach_filter_kern()
- https://lore.kernel.org/netdev/[email protected]/
v5:
- add kernel-doc for sk_attach_filter_kern()
- fix the wording of the mprotect() comment
- https://lore.kernel.org/netdev/[email protected]/
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/[email protected]/
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/[email protected]/
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/[email protected]/
v1:
- https://lore.kernel.org/netdev/[email protected]/

Rongguang Wei (2):
tun: run the socket filter from tun_net_xmit()
selftests: net: add TAP socket filter attach tests

 drivers/net/tun.c                 |  93 ++++----
 net/core/filter.c                 |   2 -
 tools/testing/selftests/net/tun.c | 358 ++++++++++++++++++++++++++++++
 3 files changed, 401 insertions(+), 52 deletions(-)

base-commit: c44104f3642da720164042623e4832836aefdd8e

Signature · 5 lines
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus