🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #3869

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

#3869
From: Rongguang Wei
Date: Fri, 16 Oct 2026 07:06
75 lines
9063 bytes
From: Rongguang Wei <weirongguang@kylinos.cn>

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

Patch 1 keeps a copy of the program in the kernel when it is configured,
instead of reading tun->fprog from user space again on every later attach,
and fixes the inverted error check in tun_attach(). The two changes are
one patch on purpose: with only the kernel copy every re-attach returns 0
without publishing the queue, and with only the check fixed a re-attach
that used to succeed without a filter starts to fail. IFF_NOFILTER keeps
working and is no longer needed as a workaround.

Patch 2 adds selftests: it re-attaches a queue after the buffer the program
was copied from was made unreadable, attaches a second queue from a fresh
socket to check that the filter is rebuilt from the kernel copy, and checks
that a rejected TUNATTACHFILTER keeps the saved program, plus the ways to
attach a queue without a filter.

Thanks to Willem de Bruijn for the reviews, and to the CI reviews for
the comments they raised.

Rongguang Wei (2):
  tun: keep a kernel copy of the socket filter program
  selftests: net: add TAP socket filter attach tests

---
v6:
  - add description for return value of sk_attach_filter_kern and No code
    change is involved.
v5:
  - add kernel-doc for sk_attach_filter_kern() describing what the missing
    original program means for SO_GET_FILTER and sock_diag
  - mention in the message that a rejected header now leaves the installed
    filter alone
  - fix the wording of the mprotect() comment and note what the IFF_NOFILTER
    and TUNGETFILTER checks in the re-attach test
  - https://lore.kernel.org/netdev/20261012021113.45939-1-clementwei90@163.com/
v4:
  - merge the kernel copy and the error check into one patch, so that no
    step of the series turns a re-attach into a silent no-op or into a new
    failure
  - charge the kernel copy to the caller's memory cgroup
  - selftests: check that the queue is attached again, and attach a new
    queue to see that the filter was installed from the kernel copy
  - 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
  - address the review of the selftests
  - 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, so that a later attach does
    not depend on the address space of the process that set the filter
  - 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                 |  56 ++++++++-
 include/linux/filter.h            |   1 +
 net/core/filter.c                 |  41 +++++++
 tools/testing/selftests/net/tun.c | 197 ++++++++++++++++++++++++++++++
 4 files changed, 290 insertions(+), 5 deletions(-)

base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
-- 
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus
Technical Details
Message-ID: <20261016070654.170932-1-clementwei90@163.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347146-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347146-linux-kernel-netdev=dewy.ru
From: clementwei90@163.com (Rongguang Wei)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v6 0/2] tun: fix re-attaching the socket filter
Date: Fri, 16 Oct 2026 15:06:52 +0800
Organization: Usenet Network
Message-ID: <20261016070654.170932-1-clementwei90@163.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2705545"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:LVOhWn1JWlGFGWhsmRUmkvpmaFU= sha256:WSsdExMK3ws2enY4kqlWB+UuJrmb1ltc6kekKEKp7rg=
	sha1:yfLVvUfu/N4gP0pETPIYh8b9qhM= sha256:GzzPq7PoeSFok8/wLDsIggpkqW2VJ3a7IItbhnpr8Js=
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 CE168110487; Fri, 16 Oct 2026 10:07:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.147
X-Spam-Status: No, score=-3.147 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.25, 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 9C3TRYi1ZSWT;
	Fri, 16 Oct 2026 10:07:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-347146-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 13E43110483; Fri, 16 Oct 2026 10:07:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id 6AF0D60B356; Fri, 16 Oct 2026 07:07:28 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id AB2A23B19B3;
	Fri, 16 Oct 2026 07:07:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="IvwJRR4A"
X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AE4837F8DD
	for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 07:07:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792134447; cv=none; b=qJjOUEtNXUCkJMvFb4IhXCdAPs+0B6G3LrC3uMA3uI5AsTYzxM2D9lGGP+L1ohVUOJmPWmmkQKWiToouu9aQfoa9oeaEo5RbnLeR1zGzClAP8WZJkIaxs7lU8n7QJKTH6YK2NplXwGvPtCXtcoDIFPEKYU9k+n1lejHYKPLflWk=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792134447; c=relaxed/simple;
	bh=K39YGSxjfWyyl+7+GdlZVK8ivofGvEAdf1YPQNm6KVU=;
	h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=V/n0xHxsu1PD1IMF0qmR3wKVvdpRbFu9hFs7A0u7yJeF4hMDLTaVlnBUnBHRLvWjgP0a4GKWdZDzi1+OQzXkzSkV+gGNh9xBlnINttS52VA9dPG+tv9ZjLxrjS9K3/3UF0VvWyy25ZgLnJmC4DN9NIR8/ksKHub2+x3QIwBOHT8=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=IvwJRR4A; arc=none smtp.client-ip=220.197.31.2
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=v9
	3WurFOh37Cc6a05HYADFjHfrVWwrve8/drkZSTFDI=; b=IvwJRR4AXjWj7jMonj
	aMiYIrfezCbDwtiOCYJBbHnLS5ZMVwzzZ6g2oru1B9HiPRaXExcfpNcw/56b5MST
	9XoprVdm0opyLW6w3Ujm3vssutp5AEeqpjxqxA7HqV5Ua+kOMGXqduNsWFH88hGh
	62+E/MnLyRSJCf1pmQCJzYHm0=
X-Received: from localhost.localdomain (unknown [])
	by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wDnr7wPzdFqoTHrAQ--.20287S2;
	Fri, 16 Oct 2026 15:06:57 +0800 (CST)
X-Cc: willemdebruijn.kernel@gmail.com,
	jasowangio@gmail.com,
	andrew+netdev@lunn.ch,
	davem@davemloft.net,
	kuba@kernel.org,
	Rongguang Wei <weirongguang@kylinos.cn>
X-Mailer: git-send-email 2.25.1
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-CM-TRANSID: _____wDnr7wPzdFqoTHrAQ--.20287S2
X-Coremail-Antispam: 1Uf129KBjvJXoWxAF43Xr1kuw1rCF15ur1fXrb_yoW5ury8pa
	y5W345Gw4kW347u3Za9ayxZ34Yyws7GFW3Zwn7G34rZa15Wryjv3ySg34YvF1qyrZ2gw1j
	yFn0vwnIg3WDJFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joGQDUUUUU=
X-CM-SenderInfo: 5fohzv5qwzvxizq6il2tof0z/xtbC-RGG8WrRzRFioQAA3-