🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23962

[PATCH net 1/2] tun: clear the socket file pointer on release to fix a struct file UAF

#23962
From: Juan Agustin Niccolini
Date: Sat, 28 Nov 2026 17:48
78 lines
14390 bytes
tun_chr_open() stores the file in the socket embedded in the tun_file,
and nothing clears it when the file is released. A packet written to
the fd is charged to that socket and keeps it alive, so the socket can
outlive the file. For a packet that is still in the stack after
close(), sk->sk_socket->file points to a freed struct file.

xt_owner, nft_meta, nfnetlink_log, nfnetlink_queue, nf_log_syslog and
cls_flow follow that pointer to read file->f_cred, a use-after-free:

  BUG: KASAN: slab-use-after-free in __nfqnl_enqueue_packet+0x33d0/0x38c0
  Read of size 8 at addr ff11000010d09930 by task tun_nfqueue_uaf/270

An unprivileged user can trigger this from a user and network
namespace, by queueing the frames of a bridged tun device (IFF_TAP) to
nfnetlink_queue with NFQA_CFG_F_UID_GID, closing the fd and requeueing
a frame with NF_REPEAT. nfnetlink_queue reports the fsuid and fsgid it
finds through f_cred, so once the freed memory has been reused for data
the user controls, f_cred is an address of the user's choosing and the
eight bytes stored there are returned: an arbitrary kernel memory read.

__tun_detach() used to clear the pointer. Commit 66d1b9263a37 ("tun:
don't zeroize sock->file on detach") removed that in favour of
sock_release(), which already skipped the tun socket by then and which
tun no longer calls.

Fix this by clearing the pointer in tun_chr_close(), as
__sock_release() does for other sockets. vhost-net also uses the
pointer, but only while it holds a reference to the file.

Trees before v7.1 need the clear to be done under sk_callback_lock,
which the netfilter readers still take there.

Fixes: 66d1b9263a37 ("tun: don't zeroize sock->file on detach")
Cc: stable@vger.kernel.org # needs adjustments for <= 7.0
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
Reproducer: github.com/AgusNicco/tun-tap-uaf/blob/main/tun_nfqueue_uaf.c

An exploit that uses this bug to read arbitrary kernel memory as an
unprivileged user is available to the maintainers on request.

The patch was tested on mainline f4585067150b (same tun.c as net) with
KASAN: the reproducer gets the report above on 100 of 100 runs as an
unprivileged user, and on none of 20 with this patch. The github repo
above also has the full KASAN report.

vhost-net also uses this pointer, so it was tested with this patch
applied, using a tun device as the backend. Frames were sent in both
directions, and the backend was then released in four ways: closing
the tun fd first, closing the vhost fd first, detaching the backend,
and exiting the process. All 180 runs passed, with no KASAN report or
warning in the kernel log.

One side effect, in cls_flow: it checks sk->sk_socket->file and then
loads it a second time to use it. With this patch a close() racing
with the classifier can make it dereference NULL for a tun socket, as
it already can for any other socket. The pending patch "net/sched:
cls_flow: pin file with get_file_active before reading f_cred" removes
the second load, so I left cls_flow alone.

 drivers/net/tun.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ae05b1e58abaa..95bda80bed255 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3671,6 +3671,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
 {
 	struct tun_file *tfile = file->private_data;
 
+	WRITE_ONCE(tfile->socket.file, NULL);
 	tun_detach(tfile, true);
 
 	return 0;
-- 
2.53.0
Technical Details
Message-ID: <20261128174844.53113-2-juanagusnicco@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373252-linux-kernel-netdev=dewy.ru
References: <20261128174844.53113-1-juanagusnicco@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373252-linux-kernel-netdev=dewy.ru
From: juanagusnicco@gmail.com (Juan Agustin Niccolini)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 1/2] tun: clear the socket file pointer on release to fix a struct file UAF
Date: Sat, 28 Nov 2026 12:48:43 -0500
Organization: Usenet Network
Message-ID: <20261128174844.53113-2-juanagusnicco@gmail.com>
References: <20261128174844.53113-1-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="999643"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Gx/ROrR+NObcUNwmB3xCKUnM2Bw= sha256:Nq3L2037gHwreoJ/O/sLabizHcgFhKJXrv4u7pWOZSI=
	sha1:f5o1d+YmV5uCfEVZdykVrIe3/ZM= sha256:XkIoouSHp2J6RliFShQRwmUyEd7vBgAF23upsVlWeDg=
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 D8397125F76; Sat, 28 Nov 2026 20:49:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.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 YJ_zxVQ1_Jvq;
	Sat, 28 Nov 2026 20:49:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373252-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 58F54125F87; Sat, 28 Nov 2026 20:48:57 +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 9867F269F1; Sat, 28 Nov 2026 17:48:55 +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=1795888134;
	b=OHAh7AiLLGzjXxWo7NqlDgxJkfCUIxiXNuC5QxPtfRYG8gGxMlpnLrjzinZ+fcyNwPAj
	 2vVHImCCQJjyccWFA8lzEPtK1jtvKlbeeUyq2ucrlm9Ls2L+WPJe0EHZgAItAZKnhUwK4
	 I39HsUhN72vkZTQlHZbqNKsV1azGEOe6CLGFnP4fwvPimCo5gbATXpqYjYALWYRCOpFel
	 ADLErk6alIQHmayFjeQxTtwXYzEkJF5fSDpI/lFNWxXmJ6Z4A7iLxjIXi7KXXlxgn06ZM
	 M95cOl9bRHHiBPLNgmteSyhYgfud0y8oJem6BPv6UAjOa6opTTJU6AJFVlKIskj15rQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795888134;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=DDpt/n2R57Oz5+LJpf8q1LvrlwMnG/uxW5XITUfnDyc=;
	b=Vq6W6ssha5LRmsuTazYCBj+M8Oe7tvCq468fmeksPdstJog58X9B80lTwtY7zvumvR0K
	 KR4TzhehCu8VPIqnXUh3pXvlr1JmJ2OIt2oFRwtF3pl/aH4mu1N7ZDmkyOamUbzYxT/uc
	 p7lHf6U4pOo2gMWJHumBY1agb2J72Ud0IvFYTmK1sR7RdEj46wqQARbcR9tBqSCOl+GQz
	 CdVadwMQeFjEG0vqbeJsHP1btSa4CYOvvPZv1fznNX/vufQvrdhCYapOIYUSy0i9JWzpC
	 Ro6LUlw9coVZh2iCk42eGtezr1uPYT7Z2G+rCKhJTWe8Zs/fZkEkbNbCyYlr+y1KSBQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fl7lvgjG;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.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 9C1F8606A32A;
	Sat, 28 Nov 2026 17:48:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fl7lvgjG
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.175
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795888133;
	b=cNHIhFPy7VFeVCf88z40Lkwn1BdHiaTfMkpM3OAOMDXpYz0xT/dOib34+aqPeO61S0w3
	 2IZdzitWgGNJR6XNpAotFAVjaTObeZOXXsriWOZ6j5m8HYAqrHiG3kSCjvA1Hq7EmvzeG
	 e+9CdDAX3K3OWhO26lRPEtmrGl7VlNV06vJWkTGpfxmpG8erjPQooojPa0EB3t22sgSX2
	 5ztx0jVkIRMStGIj2xEzXLkS6OyinQTqyEEnxiNE3GeNEugZB5YKthENwjA+gK5BzhJH4
	 H/ISpKePQzjdDk3ilFAG6/JRLu3cgvroyF5PLf8vGzI3iSuuk9upTWRKqVn2JcLEqkA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795888133;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=DDpt/n2R57Oz5+LJpf8q1LvrlwMnG/uxW5XITUfnDyc=;
	b=gfufj9+OS2ysATL+DQjWbBHj2KBctwMrj+67tTT/+DsZFcrUZwXoo3bXog1d5jmFjkCN
	 GFql5uIwUFJZR+gGMB2GQeXYziuD9WiEHlV/BVnscF3Cw4FFNa0p/blMvwYfliX3zbCGK
	 GpMUc6Uc39mEb7rrlHlwmgso61lpDrLB9hH9PbHU/nOBX//ieyyQpBlerNHfwviLcIbqQ
	 ns2pXDocg1FoSudeQo5TDE7Dx4FQY2mz26ty0v7QEoKZyvyMOwWSvm9wTyujkgha+qIif
	 Jxhm5WJCM2CWTaCugDj5IBecHDTlThgLZkYUubtCHfZvEBva12tlmLggYzE97+pWouA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fl7lvgjG;
	arc=none smtp.remote-ip=209.85.128.175
X-Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67EDF606A31C
	for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 17:48:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67EDF606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-8b4ea3c5afaso61438287b3.1
        for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 09:48:53 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795888132; x=1796492932; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=DDpt/n2R57Oz5+LJpf8q1LvrlwMnG/uxW5XITUfnDyc=;
        b=fl7lvgjGR0BEaGkTyWlPodATaKBwuzQssTaP24Tln+ub94b+js4fvDCdFlcqfO29pO
         X6RHWE+UnjDJ97JBBRGmMCH6xNwd/x5bOiRwFf0yhlWoRWHYoXqqSD0tfbblxhwsIDzW
         wAIK2c0GlIABOfZh0aegYRTsiYrfQEzdtE38ypbF7RJojgmjyJ6+oMdgWdNQeBdvEz8k
         mRsqXNHFH7WnzXeHKzX6PppKMyMT1G4MEdIg+aQZl/BoUO9LwfmYCm8X80jfMRwLYBgf
         /GESIaH0tBEUyTXATSFB5MnVmU+sLhmTgoxM7Roz7apf8LghgH7TBMvcLh1bv71G/z5F
         muDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795888132; x=1796492932;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=DDpt/n2R57Oz5+LJpf8q1LvrlwMnG/uxW5XITUfnDyc=;
        b=oEs1UVc0+pfSjf9ZCDAVEBeJojE9PLvpCbnimQrXNJ70q+y+ob2BSy/LSME+5I9juF
         bPcHZA4Pleaco7fOrt7NZ8ZACL2lKKWC6Mp7W/g5PKTGnD1uuzrRj156C0PZZus4bILC
         HHM3h72NAWhe4WiMUeL3vW8ZKwyfdOhUulTa3CvzkLXSBitRzrI2OZFNekQR4hWdENHM
         DPnapQ91HPN8ghFS96E32A6x3QLiN/3GmXfDHajbCNGWLp94hhlGvrSx8MzioS28qR4S
         Lfs0xtalJULeO9xlYHNd8WnFBjCn2Ure0kpJ0pX2i+sXju2P/vH6Rs2KV8vTI4L4Xfb9
         vKUA==
X-Gm-Message-State: APuU4Z8VKsAbhqFN2vMfY5KmPS+H/Fsps0UV2Uo9JJo+z6vgiYicVzoA
	Vx7dBx3C4ZRHkLFCUZTvT+cf5/915vOtZ3Mabah/ONkLRxS1koLupHcB
X-Gm-Gg: AZFdTZdRFbkdMSpLzPRIZM/5EQeHnQEgm3hi7XQdxB1lcoYSXcis2P/kcq5Hex956+3
	sUG3kFMleAcfBuAthPrY7W7R5YKXVDWsyX3HnT797ASww/PXMPDoHzFMySZSm21wbKUlXLapqKV
	6ajn9O0dvO0BWI9GH6IMg4NlQ0R4WwM9G4joB++ZQzBejyyY9OXBVTuyH/eJ85P7oBe3OAcMNQX
	NZd9Ry8BREHHBFP9ya6n6pAcXjTBKTxiDmNBbaU0eKo/VLNiPW8Rzhq77B4MGhokZM/HrLOQzP/
	qR1NlxUSwfQqD69zr7oEXk0qw7CCsrisycZ1ner28PVarlybVj1klq7rigr5XLbHoAiSD4wXLiz
	CC2oK4f9tVaXJT+AoI989kkdhF6d8UtSJfYRf04UPxDeqzqB/YoF3L8mmUDpAQUnJPn4Qb61Xef
	MC9AztgxqR5LLUvHISiT1+Z69oSLrTc3ggncMDhRmk6mff0RooXUjIr0eWqKbTwjhWMpbsSNzgE
	MiZxN5IrE4PLBhxU7jcO4yz/Y1qslm3cLIEcXUIkWK/kdwQNd81DvswDrlv9eKvCF82PdzLzYLP
	Jj9WcW6/+BH4YmVo7dwn5dGuZ8z2AZh9UIdTTkSN8Dn0qijJXrR3
X-Received: by 2002:a05:690c:d1e:b0:8b4:c71b:e4fc with SMTP id 00721157ae682-8b5204c67f6mr108588427b3.64.1795888132274;
        Sat, 28 Nov 2026 09:48:52 -0800 (PST)
X-Received: from VPN-156-19.vpn.usf.edu ([2607:fe50:0:f802::4046])
        by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5202c089dsm107438967b3.22.2026.11.28.09.48.49
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Sat, 28 Nov 2026 09:48:51 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
	Simon Schippers <simon.schippers@tu-dortmund.de>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Dongli Zhang <dongli.zhang@oracle.com>,
	Yuchung Cheng <ycheng@google.com>,
	Al Viro <viro@ZenIV.linux.org.uk>,
	Stanislav Kinsbursky <skinsbursky@parallels.com>,
	Sridhar Samudrala <sri@us.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261128174844.53113-1-juanagusnicco@gmail.com>
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