From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.175 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== 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== 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 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 ; Sat, 28 Nov 2026 17:48:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67EDF606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-8b4ea3c5afaso61438287b3.1 for ; Sat, 28 Nov 2026 09:48:53 -0800 (PST) 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) 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) From: Juan Agustin Niccolini To: Willem de Bruijn , Jason Wang , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Schippers , "Michael S . Tsirkin" , Dongli Zhang , Yuchung Cheng , Al Viro , Stanislav Kinsbursky , Sridhar Samudrala , Arnd Bergmann 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 Message-ID: <20261128174844.53113-2-juanagusnicco@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261128174844.53113-1-juanagusnicco@gmail.com> References: <20261128174844.53113-1-juanagusnicco@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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