Article View: linux.kernel.netdev
Article #25646[PATCH net v13 0/2] tun: fix re-attaching the socket filter
From: Rongguang Wei
Date: Wed, 02 Dec 2026 07:21
Date: Wed, 02 Dec 2026 07:21
99 lines
12799 bytes
12799 bytes
From: Rongguang Wei <weirongguang@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/20261123054209.89946-1-clementwei90@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/20261109023848.59575-1-clementwei90@163.com/
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/
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
Technical Details
Message-ID:
<20261202072158.115822-1-clementwei90@163.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!feed-us-ny.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375610-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!feed-us-ny.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375610-linux-kernel-netdev=dewy.ru From: clementwei90@163.com (Rongguang Wei) Newsgroups: linux.kernel.netdev Subject: [PATCH net v13 0/2] tun: fix re-attaching the socket filter Date: Wed, 2 Dec 2026 15:21:56 +0800 Organization: Usenet Network Message-ID: <20261202072158.115822-1-clementwei90@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1914065"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:uk+wnuknBWidYlfeyv3X8aEI/Q0= sha256:ota+Y0yE8AzlwYqbjV9q9cdRpwlTDtch1Xd5qLX8TIs= sha1:Lq8DXqizOzxuY6TAnb4HyuJVMUo= sha256:UDu0rgdH0jeFmdq+yxqXI1P5F4nCrflUzG0nXj9uRT4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9949511758F; Wed, 2 Dec 2026 10:23:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.148 X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZNBUEykrT3aN; Wed, 2 Dec 2026 10:22:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375610-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id DA223117517; Wed, 2 Dec 2026 10:22:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 4A98825A78; Wed, 2 Dec 2026 07:22:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796196162; b=0XAAqCf6EZ8HPXHMtbx99DhxEQmKzUQuPIlog5I8nJb4uArVY6kNwLUO+RNrsmJcOWII /r5LlVvE9lc49ehKAa8LjmiFpH74UIA44XheKeQhCwzsFrN9qqoNoJbPY49gFT6Rd8oRY oShkWClv78N2ESy3Ng6CgsOHwkjVs/36RJCSBVccctXo4SmpVTW9udGwsFUHbjRj+c9TV 7py8+ZenFgrWPFogqTRwe7bR6jc3WzZwPMwHRsLYNh7TIXpCcWERA8Wu3BKGQInG1w9ML LQVJLrSLHs4GHKDVrKF+I0nPvZUF6lOr43rGjfO6itMS6Io+LojYVbd8oHkY5w/mdZQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196162; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-Id:X-Mailer:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=X8eaOWOviSxEzPGtwgWGlA/1YgNHdS5SpBHH+V935FM=; b=QVNYQ30YzB/1vzJEHlDVHY6zatnO8J4LG2n0Etk+vM8YNYw8gHzhVLEtHabUESXf17dO DIWzRpQlb3wPydaboxQPiNrGhxGcojCIXgunubYzCgYB/lDLduipU8aNJfaEQ/Ai6pmzE 0gfn3vvp9Da4l/BhmJlYpFi8TdQRQH3lWRFST6vU366tFjJSVbNvGbYtzxZOAQJxNgYGF b0zJd8O/wp300K1uT63YVUPlvHro6L76f1KhRTp7FdQQ9fQY8X6j3orhNK0E1c4eJH8st Ltn26MLZmf1wMoHRDzZUqko1ldfJT+AOfP3Lb2HcXu9Cl1zvGNx+B4wKoNXT93E3+6g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="R/6kNKC3"; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 709DA606A331; Wed, 2 Dec 2026 07:22:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=R/6kNKC3 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.4 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196161; b=jFfaa92BBTkIHmIL351O4NaLpWXNzDrxrpdQ/jUdhR6FXVM4sPOGUuqaXS3tUSk3hVtM hP6bMjv0sqZHjuaipiIjb1dQ4iiU6rOM/74Ov+f++ufPkRCU/LHN5nUY+Td6y1+BlyEcO gXsJ0zy0Tf7pp3i+LH1wzJKr8kB74rw/W9EvBSW7/1/H7qhSTmk0ElIcKfjIPw4DGzviM IlDk6k2smY5MWI5ZCPdLQ41PyBxNR4Ja+pM5H+XtRaad9FXdwJHE3Iq0lp9chB0bZx1nX s4UpeQ3Hc3VP7Z4CCVCPC25q7YPme87GA6TiyKPaC4tax1qiQb6Jkq+4P4ALD/7eIZQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196161; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo; bh=X8eaOWOviSxEzPGtwgWGlA/1YgNHdS5SpBHH+V935FM=; b=CHPla5az0M0eld3zKYifhtxDa/muiT9aZzzz5geDC197zYr2K7cEMX644eulUf/9Vc2Y 19NO4xHHyZL9/6iKkfWnrzyAHTqXxM7okQyoKQzBebYLpB2YqiASfCdEdH9o8nQTagskW sYrjwbhdXlWUgT7meX6Qbs6YpXM0d3Nk+v9O09dn7/LqNThMLaNVtPjp+72AKpJMPbFvE dnj6SyEPOGheGbYxjn99Ho2oZ1+lV8uNfzQx9lbd+RRAAB8LI9Yl6qvQM123hiaNcqgJI NXnXvXr3ANxvjx/7koQGzJQKP/tO/ih4dIKvds6mFI67TID6iA6gXR6dHjpVb1arfLA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="R/6kNKC3"; arc=none smtp.remote-ip=220.197.31.4 X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E01BD606A32F for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 07:22:38 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E01BD606A32F X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=X8 eaOWOviSxEzPGtwgWGlA/1YgNHdS5SpBHH+V935FM=; b=R/6kNKC3xmSRbPJm1O lAWwrJfNRBecDFLADt9LPa2Uk+/s11OralZLbkbjhH28DjGcHeqM6wnSFukmtBND iFySmIb8JmPqTc3opxlRmWj4azkO2Ui1Rh6ivDpyatrBEAoqf1QLv9LXzGtxBT0e wNG9zIYV4dXozumgv+V+PQySQ= X-Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wDn73YYxw9rOkFaLQ--.35022S2; Wed, 02 Dec 2026 15:22:01 +0800 (CST) X-Cc: willemb@google.com, willemdebruijn.kernel@gmail.com, jasowangio@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, kuba@kernel.org, alexei.starovoitov@gmail.com, Rongguang Wei <weirongguang@kylinos.cn> X-Mailer: git-send-email 2.25.1 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-CM-TRANSID: _____wDn73YYxw9rOkFaLQ--.35022S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFWkGr1xWw43ur1UJry3twb_yoWrurWUpF WFgw15Gr1kW34xWw4xuw1xZw15Xw1kGF13uwn7G34rZFWYgry8u3yI93yYv3ZIyrykWr43 JFnIvFnIg3WDXFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jjtC7UUUUU= X-CM-SenderInfo: 5fohzv5qwzvxizq6il2tof0z/xtbC4RqWAmsPxxri0QAA3l