Article View: linux.kernel.netdev
Article #21531Re: [PATCH net v12 2/2] selftests: net: add TAP socket filter attach tests
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 05:45
Date: Tue, 24 Nov 2026 05:45
179 lines
14411 bytes
14411 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The selftest misses the half of the bug where the queue is
left unpublished.
- [Low] None of the new tests check whether the cBPF program actually
runs on packets.
--
selftests: net: add TAP socket filter attach tests
This commit adds kselftests in tools/testing/selftests/net/tun.c for
TUNATTACHFILTER and TUNDETACHFILTER on a multi-queue TAP device. They cover
re-attaching a queue after the original filter buffer becomes unreadable,
bad lengths and bad programs with and without attached queues, a filter
set before any queue is attached, and IFF_NOFILTER handling. Every check
is made through TUNGETIFF and TUNGETFILTER.
> diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
> index 34de2580e32ec..ac326193867b0 100644
> --- a/tools/testing/selftests/net/tun.c
> +++ b/tools/testing/selftests/net/tun.c
[ ... ]
> @@ -548,6 +550,362 @@ TEST_F(tun, reattach_close_delete)
> EXPECT_EQ(tun_delete(self->ifname), 0);
> }
>
> +/* accept: return skb->len. Three instructions on purpose, so that the
> + * length read back through TUNGETFILTER tells it apart from a rejected
> + * program that is shorter.
> + */
> +static const struct sock_filter filter_accept[] = {
> + BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0),
> + BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0),
> + BPF_STMT(BPF_RET | BPF_A, 0),
> +};
[Severity: Low]
Do any of the new tests check that the classic filter actually runs on
packets?
filter_accept is the only valid program the tests use. It returns
skb->len, so it can never show a drop or a trim. None of the new tests
write a frame to the TAP fds or read one back.
Every assertion reads either the IFF_NOFILTER bit from TUNGETIFF or the
fprog header from TUNGETFILTER. TUNGETIFF builds that bit from its own
expression in tun_chr_ioctl():
if (tfile->nofilter || !rcu_access_pointer(tun->cbpf_prog))
ifr.ifr_flags |= IFF_NOFILTER;
The companion commit "tun: run the socket filter from tun_net_xmit()" adds
the execution site as a separate check in tun_net_xmit():
prog = rcu_dereference(tun->cbpf_prog);
if (prog && !READ_ONCE(tfile->nofilter)) {
len = bpf_prog_run_clear_cb(prog->prog, skb);
if (!len || pskb_trim(skb, len)) {
Would these tests still pass if tun_net_xmit() never ran cbpf_prog, ran it
on IFF_NOFILTER queues, or ignored its verdict or trim length?
The test comments say a queue "still gets the filter", "must not get the
filter", or is covered by it. reattach_filter_without_user_buffer already
says its checks "cannot tell an installed filter from no filter". That
limit applies to the other new tests as well.
A test could send a frame through a rejecting or truncating program on a
TAP queue, then read it back or confirm it was dropped. That would cover
the datapath and the IFF_NOFILTER bypass.
There is also a smaller inaccuracy. The comment above
attach_filter_clears_nofilter_queue says:
A later TUNATTACHFILTER covers every queue of the device, including one
that was attached with IFF_NOFILTER.
tun_attach_filter() only clears nofilter for the active queues:
for (i = 0; i < tun->numqueues; i++) {
tfile = rtnl_dereference(tun->tfiles[i]);
WRITE_ONCE(tfile->nofilter, false);
}
A queue opened with IFF_NOFILTER and then detached keeps nofilter set.
TUNGETIFF keeps reporting IFF_NOFILTER for it until TUNSETQUEUE attaches
it again. Should the comment refer to the active queues only?
[ ... ]
> + /* The queue gets that program again, from the device */
> + EXPECT_EQ(tun_attach(self->fd, self->ifname), 0);
> +
> + flags = tun_get_iff_flags(self->fd);
> + EXPECT_GE(flags, 0);
> + EXPECT_EQ(flags & IFF_NOFILTER, 0);
> +}
> +
> +/* A program configured while no queue is attached must cover the queues that
> + * are attached afterwards.
> + */
> +TEST_F(tun, attach_filter_without_queues_then_attach)
> +{
> + short flags = 0;
> +
> + EXPECT_EQ(tun_detach(self->fd, self->ifname), 0);
> + EXPECT_EQ(tun_detach(self->fd2, self->ifname), 0);
> +
> + ASSERT_EQ(filter_attach(self->fd, filter_accept,
> + ARRAY_SIZE(filter_accept)), 0);
> +
> + EXPECT_EQ(tun_attach(self->fd, self->ifname), 0);
> +
> + flags = tun_get_iff_flags(self->fd);
> + EXPECT_GE(flags, 0);
> + EXPECT_EQ(flags & IFF_NOFILTER, 0);
> +}
[Severity: Medium]
Should attach_filter_without_queues_then_attach also check
IFF_DETACH_QUEUE after the re-attach?
The companion commit "tun: run the socket filter from tun_net_xmit()"
describes two failure modes of the old check in tun_attach(). In the
first, a failed read of the user buffer attached the queue without a
filter. In the second, "a successful read returned early and left the
queue unpublished".
reattach_filter_without_user_buffer is the only test that checks
IFF_DETACH_QUEUE. Its buffer is PROT_NONE, so it only exercises the
failed read case.
In this test filter_accept is in readable .rodata. On the baseline
kernel, TUNSETQUEUE(IFF_ATTACH_QUEUE) therefore takes the early return in
tun_attach():
/* Re-attach the filter to persist device */
if (!skip_filter && (tun->filter_attached == true)) {
lock_sock(tfile->socket.sk);
err = sk_attach_filter(&tun->fprog, tfile->socket.sk);
release_sock(tfile->socket.sk);
if (!err)
goto out;
}
That path returns 0 before tun_enable_queue() and before tun->tfiles[] is
published. TUNGETIFF then reports IFF_DETACH_QUEUE set, because
tfile->detached is still set. It also reports IFF_NOFILTER clear, because
sk_filter is set.
Doesn't that let all three assertions here pass on the unfixed kernel
while the queue stays disabled?
The final re-attach in attach_filter_bad_keeps_program_without_queues has
the same gap. That test still fails on the baseline kernel, but only
because of its earlier bad length and bad program checks.
Adding this after the tun_attach() helper call in both tests would cover
the unpublished queue case:
EXPECT_EQ(flags & IFF_DETACH_QUEUE, 0);
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123054209.89946-1-clementwei90%40163.com
Technical Details
Message-ID:
<179549910931.3135.4958196655811648969@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370022-linux-kernel-netdev=dewy.ruReferences:
<20261123054209.89946-3-clementwei90@163.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370022-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v12 2/2] selftests: net: add TAP socket filter attach tests Date: Tue, 24 Nov 2026 05:45:09 +0000 Organization: Usenet Network Message-ID: <179549910931.3135.4958196655811648969@kernel.org> References: <20261123054209.89946-3-clementwei90@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4062426"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:x+fKZxcJA63SNBX3228qYnwOI60= sha256:3+4/M5uSe9BRFXAkl5oKXPaFKXo2OeuNi0veB4K3xyM= sha1:jn+dhd8av9eSGJnbTg3dd9xhK8g= sha256:3LnfWjvbm0Ndwax6NwufG9E40INl0Le0UnKXxcGaXG0= 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 334AB125DCE; Tue, 24 Nov 2026 08:45:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org 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 4ozRincbPxzk; Tue, 24 Nov 2026 08:45:29 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370022-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 1FA66125DCF; Tue, 24 Nov 2026 08:45:20 +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 A8FC7314E6; Tue, 24 Nov 2026 05:45:18 +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=1795499116; b=kviidH0HxAywVNg2BiPu6wBBQMnQrU3H8C90XxXRrHKQyam++TsTnq+rKiex3Lcbe6iL V3Uwwvs1G2ZriZxRrqTPCoRFj8VAeODuvD9aXdgPyYSyekRzYaZtCeWUwLsaI2AwPMPY2 M/oVtxEwrBreknjZGpDVaDSQhYp/vgMpn57pH/wXT/slDKs65w89Ux6LF/alOzqEwVwWI FwKzmNN/9TbZ6vJnJ2bQPtT5wCaHhS3/XFz+QJGkhkR4vMpEt2oyBCABSt1gi/sgANQY+ rttg+DdKkh9s8qdWtBPJToJTdrx/0Wh+szW/tSsFFD5emNPDm8wWq9BL2ukRGGos19A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795499116; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=b7hzx4hdT/aWGEHT3B9cp/wHj65qJWImONpb6FDPul4=; b=HQD25kBuJ2Gxcip+FFkfmQwZM/YaRd/qOcBAImh5NW+y8mLLdxHamFbcsxsc6Bsrm+O7 HgkpgsQxwUWsrI0XfATkVvvLzoyAnqDuzSpT87slv0tDv8TRpj4WEEvpUh5+RhH7TANhg dqX1jkgqi27kqYw0wyPu2aAzhIzSGSn+vdeKLitcyPAniNTLpScfzT8ok96mSKrvAX0e8 zseBM1bXFjME/2No3XS0l8wkKYuDn55swdzws3E6J3o/slSxVaYpgWiO0LwMndEPP14MY hLA84o7Ed7FnbgZcvMt5yKaMzBTfd1L5bDUcMoS8EvbLL76fanqSzFjRflfq0E24NfA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vrcodb3p; 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 BB1D6606A322; Tue, 24 Nov 2026 05:45:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vrcodb3p X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795499110; b=SW/hWYBczWZeWDi6nuRTEPkgIkT0u9qlUu7BsplCyeOb7dyOOzJvc+QenGc2DHkgA9Gs Pb3QjWfgOG5tc1O7qJ5YOxQl/XbJES+vIcvDRWnj98aXTzLsv9W00HoItr9fSOsxZ5O2B iMONbSLB4OYWChREgMG4ecNmgMonVVZ4ViVwxVavKHRfR35Fqn7jLtWAwF/vPU3i8cot0 ZTDam4HUh/yHti24KJAKv5oGUobVYJWk9l9jmoc9PXMTUMkOjUSseK7iV4q8PsONatF3L 9zMIyZSKvHzVi6zGxGXw/ebNMfU3XDBEJ7DynYeOjJY2OPVOJ91U4Nqm+cGxyE01wlw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795499110; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=b7hzx4hdT/aWGEHT3B9cp/wHj65qJWImONpb6FDPul4=; b=u/zsycF9hspY3XuYZ7XsjiBKw7Hy4GmU4CrkfaJwtuPcnHxISkeXKgDWEcraWmuO+cQR RcUKA/U29xeHz0+48Y2w/X0W+P0p2cOBS1HReKMuMmBlcCsM+ztr+EHS3cRZZRyqSJkxl 6kVbraDEalsQa+Q726Vue3vozthm1r1aMyEbSEqCROrx1vciaRtOzIqqcWxjLdHAx3Dl+ x78NhElnZgH31djSKArnWUCiTU6GfSxlrR5RNqKELkP0GaHA6wLgbknFiqBEItsg0yV7q wPuYOB/aln6KGVgSPEgCJPSGjQHxp3OnzfuDUsnK6XTRCDbMhwbW9Sg81o5t7ITTZbw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vrcodb3p; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7A7C606A333; Tue, 24 Nov 2026 05:45:10 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBBA81F000C0; Tue, 24 Nov 2026 05:45:09 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795499110; bh=b7hzx4hdT/aWGEHT3B9cp/wHj65qJWImONpb6FDPul4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Vrcodb3pExD7IvnRJ++M28lf/71cgaIy6O2yMrMX+tiJ+/bLMLI4faFbjLWyK86Ks 46creBgmZY87nJiZm6InSM58VnczzVQRyMZ6FR9fRN8e9yyxkPHRH+5pBUvlIf6pyJ CdWf5m9tTKjNw3f52dmZ/LXNNqW5esRVeGZFwh5sm7eOG9L/Ds5caUNvGYUncpvPIN tSAKk/EE48riNy34lxLJwcjgyNYj+BoJC8xztgprVFN7ilYuYbY20BvyXW4nobZcuz 1Cza7+lCS0pN7x4ldEVOBTIFr33kuZ2WGJF7OnLEiq4/X34p8gmiYAvZYQZE+Gez9z ZdRYQNxKRNRHg== X-Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, willemdebruijn.kernel@gmail.com, jasowangio@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, alexei.starovoitov@gmail.com, andrii@kernel.org, weirongguang@kylinos.cn X-In-Reply-To: <20261123054209.89946-3-clementwei90@163.com> X-sashiko-severity: Medium 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