🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20298

Re: [PATCH net v7] tun: bound the NAPI receive queue

#20298
From: netdev-bot+sashiko
Date: Sat, 21 Nov 2026 23:37
138 lines
13310 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

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

- [High] Bounding the IFF_NAPI queue by packet count only
  (net_hotdata.max_backlog skbs per tun_file, ignoring size) does not…
- [Medium] The patch silently changes behaviour for IFF_NAPI users who
  set a finite send buffer with TUNSETSNDBUF, and the commit message…

--

tun: bound the NAPI receive queue

This patch caps the IFF_NAPI sk_write_queue of each tun_file at
net_hotdata.max_backlog packets. Excess packets are dropped and counted as
rx_dropped in tun_get_user() and tun_xdp_one(). It also changes
tun_napi_receive() to take at most budget skbs from the queue, so the rest
stays visible to writers.

> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 86fd44e107550..b7432bd4d3f03 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c

[ ... ]

> @@ -227,6 +228,16 @@ struct veth {
>  static void tun_flow_init(struct tun_struct *tun);
>  static void tun_flow_uninit(struct tun_struct *tun);
>  
> +/* In IFF_NAPI mode written packets wait in the tfile's sk_write_queue for the
> + * NAPI poll, which may run later in a kthread or ksoftirqd. Bound that queue
> + * like the per-CPU backlog.
> + */
> +static bool tun_napi_queue_full(const struct sk_buff_head *queue)
> +{
> +	return skb_queue_len_lockless(queue) >
> +	       READ_ONCE(net_hotdata.max_backlog);
> +}

[Severity: High]
Is a packet count limit in tun_napi_queue_full() enough to prevent the
global OOM described in the commit message?

tun_get_user() takes total_len = iov_iter_count(from) with no upper bound.
tun_alloc_skb() can then build an skb with up to ~544 KB of frags plus a
linear remainder:

drivers/net/tun.c:tun_alloc_skb() {
    ...
	if (len - linear > MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
		linear = len - MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER);
	skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
				   &err, PAGE_ALLOC_COSTLY_ORDER);
    ...
}

tun_chr_open() sets sk_sndbuf to INT_MAX by default. With that, a single
tun_file can still hold about max_backlog * truesize. That is tens of MB
with 64 KB writes, and much more with multi-MB writes.

The limit is also per tun_file. With IFF_MULTI_QUEUE, tun_set_iff() allows
MAX_TAP_QUEUES (256) queues per device. The only gate is ns_capable() in
the user's own namespace:

	int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
		     MAX_TAP_QUEUES : 1;

Even with 1400-byte packets that is roughly 256 * 1000 * ~2.3 KB, or about
590 MB per device. A namespace can also create several devices.

The commit message lists this under "Still open". Even so, the same uid
1000 process limited to a 128 MB memcg looks able to reach a global OOM
with larger writes, more queues or more devices.

Would this need a truesize based limit, or charging the queued skbs to the
writer's memcg, to close the reported DoS?

[ ... ]

> @@ -2043,6 +2055,19 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>  		struct sk_buff_head *queue = &tfile->sk.sk_write_queue;
>  		int queue_len;
>  
> +		/* Queue full: drop, and schedule NAPI, which a MSG_MORE sender
> +		 * may not have done yet. Lockless: concurrent writers can each
> +		 * still add one.
> +		 */
> +		if (unlikely(tun_napi_queue_full(queue))) {
> +			local_bh_disable();
> +			napi_schedule(&tfile->napi);
> +			local_bh_enable();
> +			rcu_read_unlock();
> +			drop_reason = SKB_DROP_REASON_FULL_RING;
> +			goto drop;
> +		}

[Severity: Medium]
Is this behaviour change intended for IFF_NAPI users who set a finite send
buffer with TUNSETSNDBUF?

With a finite sk_sndbuf, tun_can_build_skb() refuses the build_skb path:

	if (tfile->socket.sk->sk_sndbuf != INT_MAX)
		return false;

So every write goes through tun_alloc_skb()->sock_alloc_send_pskb(), which
charges sk_wmem_alloc.

Before this patch, skbs on sk_write_queue kept their wmem charge until the
NAPI poll consumed them. A slow poll made a blocking writer sleep in
sock_alloc_send_pskb(), and gave a non-blocking writer or vhost-net
-EAGAIN.

After this patch, this branch fires first once sndbuf is larger than about
max_backlog * truesize. That is about 2.3 MB for 1400-byte packets with the
default max_backlog of 1000. The skb is freed, which releases its wmem, and
tun_get_user() returns total_len.

The writer then never blocks and never gets -EAGAIN. Lossless backpressure
that the user configured becomes silent packet loss. The commit message
only mentions sndbuf as being INT_MAX by default.

Could this be documented? Or could a full queue block or return -EAGAIN for
writers on the charged path? Exempting finite-sndbuf queues alone would not
be enough, since the same user could set sndbuf to INT_MAX - 1 to get
around the cap.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119153056.353156-1-antonio%40mandelbit.com
Technical Details
Message-ID: <179530424233.3135.6226986969775563090@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368532-linux-kernel-netdev=dewy.ru
References: <20261119153056.353156-1-antonio@mandelbit.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368532-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v7] tun: bound the NAPI receive queue
Date: Sat, 21 Nov 2026 23:37:22 +0000
Organization: Usenet Network
Message-ID: <179530424233.3135.6226986969775563090@kernel.org>
References: <20261119153056.353156-1-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3523067"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:f7NuQ5uIpSqaLnIMmjCwdyCJCPM= sha256:aeq1qiuAy8bM+cboIBw/kSFd609QVCHXEU8/+8KofLI=
	sha1:flf/+phcjCb/tJvlI6A7S7dl4Zo= sha256:myZer42mVWqoO7NNPsxEQAPsYpT/rhQRhlvcVMXpbYo=
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 4D69A115C40; Sun, 22 Nov 2026 02:37:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 YRGuZsxVszNr;
	Sun, 22 Nov 2026 02:37:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368532-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id F18031096CA; Sun, 22 Nov 2026 02:37:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 02C0737660; Sat, 21 Nov 2026 23:37:26 +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=1795304245;
	b=Hn0pYDkk1YvCSeJNxiJQJGRsFVHjmTHYAQv/gql9QBd4Xl1G1ind/OU8VOgrrVsrM5Qf
	 AN1tNzfx6D0CK3pxlfJr3UZcaOwwu5p8VJKODBbZTRFdaOzW0uiYY54Wjhp6AUSwTvfDx
	 gz+u1Bi+N9PqRU5zxH+h+h798fZTRRqbhHARF8x4/XTF+0ySC6fQC8wihdE96kYTC0mVg
	 d/Tgy4arVp0VdHGHUV6+cHSOmkOPVtaK+ILaace8sNYlxXsN2hnID+Grdw6PPVUQQe343
	 lok2GZqqSSjSLQzz2N+t6VDaw9Q+IKl2cz7/9HI1roHaGgP2PiYHsQEDQQAYeQiwvgA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795304245;
	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=4KPjgcwe8LG/IWwYnJ9R321g+N2W83kSLrvRS4eTumE=;
	b=guRwElzB8yudGdI7+dJ+QpVEyjhFjc1llcYVn/xshlvqvpsg2tdLvshBv5cJUUg5oLRK
	 QQwQnDEir+LSrzdxg22pGRLOyejHHTN9KEkPqHXjxU/BPqC8c/Q3WpC/PLYSxLKugE7DI
	 2hpw1iabqlcV1Ov7jzY9GXzz+/1CwVO1B8UFBaHvJeOgic2XqFpgBSKZKCSePgA6+ueE9
	 NYJn3jjG58vjj/uQQq4c+D0hsUAT9NZ94L4M1q7uO8SdALXW0+sNgaBeCEEr1jAfh/pY4
	 YcwlCr4/HwIBmkHtGZv2OQK5JBlK0/cWW0lw+s/IQ1RFG2nxfqrNUR2v09wS5IRBVZQ==
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=UIHFr5AC;
	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 5C9C2606A33A;
	Sat, 21 Nov 2026 23:37:25 +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=UIHFr5AC
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=1795304244;
	b=PpmguAqeVFFiYT5XPOWxfpTe7HgRZpoJUWRGDyF8XXvhG/ZnWVXYrU9cX+k/FXEdOuvU
	 aj9bCMpeOWQVOD98Re8c/w7eu5OXzYDvPKv8KvHnsYHi0iUhwlabN87ykJPhL2QHv4lGZ
	 1KbOSaiXQtT35coQpR1zbAr3gCtwemyrjz7LGNj5lPSYxtf3rBf/yifDCUP3LBpXx5Ind
	 7/6AQZXsXWVJTB63JazJTaIfr8cChstmU0kA133qKyVxPdyXyHyWZGzWv1tHJwmi56jrJ
	 Qfj3IxYrcEPAiaRXlVopx2Xnaa2KG7IVIAsPDg32f1a2hFSVjC79OAAaI1L6EEBvsrw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795304244;
	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=4KPjgcwe8LG/IWwYnJ9R321g+N2W83kSLrvRS4eTumE=;
	b=B/ZGA8TVqZVrqGSliT6409/V1J/O5S9SnVySq79CJO8HNpBnSsYk13YnWOEbV3mroRPf
	 +qZyF35O4gJNr4oASe7pYtrQssz9vjo8garNuneNhZG7R4uVC4iaWe4OX1ALsVTkrhA6Y
	 NSsZQOWBG1Bg3lffEZWBM78KAVDfcRv1uVJr1LBOEd2M8zeGfgdwrWSDJRCVHdVxfrcXh
	 SQ+A5IGhpOaXOgG1ZmK5UV6JpZVf6V1SAlqa5QtoNJtHXusZGgHQVRGdd1gsyf0fLNVOW
	 jkJuCV0ZmS4qUfWiENz94yK2ioeePLzHY4Kc6W5DDPDr9G5169CAbSNCGMMY4djU1Lw==
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=UIHFr5AC;
	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 7C0E7606A320;
	Sat, 21 Nov 2026 23:37:24 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D120F1F000C0;
	Sat, 21 Nov 2026 23:37:22 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795304244;
	bh=4KPjgcwe8LG/IWwYnJ9R321g+N2W83kSLrvRS4eTumE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=UIHFr5AC4HfoRTZvYJgLLAXJkU+5szVCiBbgx9r4K+94+Ds+B7yjso9fJ6UxO9NEr
	 i5E2H7b/vZ1qERmmoa2esSnQLSm9XliE1WV6fGDRyvy6hzITvZxlT8AsyjJQXPmc/a
	 ZJx7+Eama47+yuYIMr55ujcUBhgADMCMspwjvc+DsKoccgSTuuliBQH5IigyvvFSyP
	 fOBupnfZfSSAVhdYk3lz/hjOu4fShjlZwLjJfRDk9iUPQcyJkIqI1xqAuxfd3W5QSf
	 d6BPPlDUMUaWFgzb9j86AgUgrQZ3a0Z4in29ek7BKLimqDv2FuVA2OwlS4J6ZkJn1N
	 48y3O526nAozA==
X-Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, mst@redhat.com,
 eperezma@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
 john.fastabend@gmail.com, sdf@fomichev.me, maheshb@google.com,
 peterpenkov96@gmail.com, netdev@vger.kernel.org,
 virtualization@lists.linux.dev, bpf@vger.kernel.org
X-In-Reply-To: <20261119153056.353156-1-antonio@mandelbit.com>
X-sashiko-severity: High
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