Netdev List
 help / color / mirror / Atom feed
From: Rongguang Wei <clementwei90@163.com>
To: netdev@vger.kernel.org
Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
	andrew+netdev@lunn.ch, davem@davemloft.net,
	alexei.starovoitov@gmail.com, kuba@kernel.org,
	Rongguang Wei <weirongguang@kylinos.cn>
Subject: [PATCH net v11 0/2] tun: fix re-attaching the socket filter
Date: Thu, 19 Nov 2026 11:22:40 +0800	[thread overview]
Message-ID: <20261119032242.71919-1-clementwei90@163.com> (raw)

From: Rongguang Wei <weirongguang@kylinos.cn>

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, 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.

---
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
v10:
  - add bpf@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/20261030060043.94719-1-clementwei90@163.com/
v9:
  - zero the whole sock_fprog header, so that the padding TUNGETFILTER
    copies is not uninitialized stack
  - https://lore.kernel.org/netdev/20261030060043.94719-1-clementwei90@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/20261028093235.148649-1-clementwei90@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/20261023092239.186665-1-clementwei90@163.com/
v6:
  - add description for return value of sk_attach_filter_kern()
  - https://lore.kernel.org/netdev/20261016070654.170932-1-clementwei90@163.com/
v5:
  - add kernel-doc for sk_attach_filter_kern()
  - fix the wording of the mprotect() comment
  - https://lore.kernel.org/netdev/20261012021113.45939-1-clementwei90@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/20261003063859.136895-1-clementwei90@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/20260930080746.135017-1-clementwei90@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/20260929093712.131096-1-clementwei90@163.com/
v1:
  - https://lore.kernel.org/netdev/20260923025653.59348-1-clementwei90@163.com/

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


base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
-- 
2.43.0

No virus found
		Checked by Hillstone Network AntiVirus


             reply	other threads:[~2026-11-19  3:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  3:22 Rongguang Wei [this message]
2026-11-19  3:22 ` [PATCH net v11 1/2] tun: run the socket filter from tun_net_xmit() Rongguang Wei
2026-11-19  3:47   ` Alexei Starovoitov
2026-11-19  5:42     ` Rongguang Wei
2026-11-19  6:18       ` Alexei Starovoitov
2026-11-19  6:51         ` Rongguang Wei
2026-11-19  3:22 ` [PATCH net v11 2/2] selftests: net: add TAP socket filter attach tests Rongguang Wei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119032242.71919-1-clementwei90@163.com \
    --to=clementwei90@163.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=weirongguang@kylinos.cn \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox