Article View: linux.kernel.netdev
Article #23963[PATCH net 2/2] tap: clear the socket file pointer on release to fix a struct file UAF
From: Juan Agustin Niccolini
Date: Sat, 28 Nov 2026 17:48
Date: Sat, 28 Nov 2026 17:48
63 lines
13603 bytes
13603 bytes
tap_open() stores the file in the socket embedded in the tap_queue,
and nothing has ever cleared it when the file is released. As in tun,
a frame written to the fd keeps the socket alive after close(), and
sk->sk_socket->file then points to a freed struct file.
A frame written to a macvtap device on top of a bridge reaches
nfnetlink_queue with the tap socket attached, and NFQA_CFG_F_UID_GID
makes it read file->f_cred through that pointer, a use-after-free:
BUG: KASAN: slab-use-after-free in __nfqnl_enqueue_packet+0x33d0/0x38c0
Read of size 8 at addr ff1100000ff59a30 by task tap_nfqueue_uaf/272
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. This takes CAP_NET_ADMIN
in the network namespace of the device and access to its /dev/tapN
node, which is not world-accessible the way /dev/net/tun usually is.
Fix this by clearing the pointer in tap_release(), 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: 501c774cb13c ("net/macvtap: add vhost support")
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/tap_nfqueue_uaf.c
Tested on mainline f4585067150b (same tap.c as net) with KASAN: the
reproducer gets the report above on 100 of 100 runs as root on a
macvtap device, 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 macvtap and ipvtap devices as the backend. Frames were
sent in both directions, and the backend was then released in four
ways: closing the tap fd first, closing the vhost fd first, detaching
the backend, and exiting the process. All 180 runs passed for each
device type, with no KASAN report or warning in the kernel log.
drivers/net/tap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 2f19fb07bb2d4..e05bf8ecc65fd 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -514,6 +514,8 @@ static int tap_open(struct inode *inode, struct file *file)
static int tap_release(struct inode *inode, struct file *file)
{
struct tap_queue *q = file->private_data;
+
+ WRITE_ONCE(q->sock.file, NULL);
tap_put_queue(q);
return 0;
}
--
2.53.0
Technical Details
Message-ID:
<20261128174844.53113-3-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-373253-linux-kernel-netdev=dewy.ruReferences:
<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-373253-linux-kernel-netdev=dewy.ru
From: juanagusnicco@gmail.com (Juan Agustin Niccolini)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 2/2] tap: clear the socket file pointer on release to fix a struct file UAF
Date: Sat, 28 Nov 2026 12:48:44 -0500
Organization: Usenet Network
Message-ID: <20261128174844.53113-3-juanagusnicco@gmail.com>
References: <20261128174844.53113-1-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="999694"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KP8ZNoDXRaOuUg+88gU+nd7+bu0= sha256:38U72Bb//p6fN74cqV3D9XbnqwsnPUmpgLSYh4slLjw=
sha1:jJG5fYwNhjMnN/GUNisSSSn/YPw= sha256:WpGOu7QiYZzFkFzI3Wo+g+wQQjv3SGzQfbilPG96uJY=
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 4CBAB125F76; Sat, 28 Nov 2026 20:49:12 +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 TnRH0XA-LoSZ;
Sat, 28 Nov 2026 20:49:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373253-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 527C6125F86; Sat, 28 Nov 2026 20:49:00 +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 3612226A5A; Sat, 28 Nov 2026 17:48:57 +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=1795888137;
b=Bh8cXHKPDLPSwG/URogPzhUNQOLm1LRKuH2c6MIYJrR7JBBwZDKNg1MLKtSrp0bXFDRO
sv2FpNME/NaWeMdlURnPiMq96yvFWWuqW4u6rPWLOjkOqiMGDIDZSmUw1n43AMefz9D5G
Ji/MWL4kfyllxEoDgUBrB033NIrpiGfC+sN9ewuEuEkB9y18SC67S6+SXDNNl2pdW8Mmi
mPMsWNq7k2E/w0GzHJFyYjjt/oQ/3kis0JyXl4vlaRSAWOIFA6xLjYj++1NjIstzHblq0
1WfcncSjof+99C+CiP2ZjoNtD+0bA5VX1/MPW++Wi6oExRbQKsUSEKlVu3o8n5fqE4w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795888137;
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=V0RBQ7IGBKXTXGaWVl55cmq5G7e9BJ/ukmRpPb8VaOs=;
b=mkEwJuT77n8LyZYizsqfHLcL8zBFNpLXu1XuVvgn8D4H5l4kmUzc8O/moCCHxjROrPX4
p+LcX1Kcr+x+vj6f5My6zfd0ftNBx3Oe1ZUWBN+3lAkd80n3s6tKxvpgwNmAnl/jkoDBj
jg1KOZWtCHyWuX2Bbfsrwdw8GJ1NbCnq+n8SzpFH8gIdNrdm+s0uQ9mre+DSAeaRpvMEI
+jLQtp2AE99g2w4fAsOaTi6ru4UtVNDqTZZ9IDitqdcOQjAcUx0sg9FK2j7ETVmRtN825
SY7z6aZlk12+qS3VrLfhRmfFNczs772uRJP9b2k4V8xstGQAr3H1SsMxcPOSgme2qJQ==
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=dDwgi4B2;
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 0ED41606A31C;
Sat, 28 Nov 2026 17:48:57 +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=dDwgi4B2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.52
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795888136;
b=YqHpMBj7JzRtiEgZiXz9Hu2uVHM9YdP36DpNQDhxbI4LKpfTLMhtMguYx00GRB0ayVVV
IrAll9Vsho8oWMl4KZKYPQZLq5csOcJ0OlQFgbRCuY1IS6+eJq2Qme+YTUe1X/rLydcPl
OKrcNq7nj8DzWU+aaRh639pDjQAbC2uSOsJbNTiEaP6SXJxCphBPphLFiblOynlvm75ug
1pOGKtwaAfkmN+BGGqW2ArlKDSZAP3e4u35q7i8ops7MziOP0YsC1wrHj8rNMIZYjFfdE
Jykl3rXhrCoWcpbAgQFGRlg3CuhaIryaWTNmRL+XvgxV5lwfRWHM1nw+53fS6OyesFw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795888136;
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=V0RBQ7IGBKXTXGaWVl55cmq5G7e9BJ/ukmRpPb8VaOs=;
b=rl4cmaw8A3mvvjmY1+KjAlUlpE6RgqzjHQscCkcPaP3ysRM0MrKxCeyd7It7+ZGeEQF4
1zNiN0cZt2iNL3l+CPklamdMoyrAIWF8eRavtTRXbdCxbSKbXvIYs1YqhrkbwHOZPy7cK
ObhF3rjKbf2FPksiXkk1Ybkdo+vxgI7KiwypURwD0Mmtw9G2uUVMiuHjQWxM8yRRFfw5e
jPctWR4vTT+8+Xuy6Zpe+L2KDgs4ssN/0EdT6OPQuMNER/fC9u8A6FpDyUfLjjMvR+sar
WQ0jRgXlhndz2k5vzFBnWPKJyvIWw3N44BTrPyuNx/vJWEZHKavMGxNk8XzFWo89iMA==
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=dDwgi4B2;
arc=none smtp.remote-ip=74.125.224.52
X-Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52])
(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 D1568606A32A
for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 17:48:55 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1568606A32A
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-yx1-f52.google.com with SMTP id 956f58d0204a3-67db1f6f50eso9359766d50.0
for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 09:48:55 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795888135; x=1796492935; 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=V0RBQ7IGBKXTXGaWVl55cmq5G7e9BJ/ukmRpPb8VaOs=;
b=dDwgi4B2YipZIx/sLNJB8FjxRhIMx0tLaanYtNVGC5UPpMCo0/DLZRDQvsNwGncb8X
CWCQ50xOZmAY13fNGoevT/zRAuIqGjKgMLQ8R2HSN0UoIxUtoRWon66tsfl1gHonuc9l
x3x/UALdA3eLBWZFbHXvnizDnbx+DFH1AFtAlP4ZBmn96gnRfJpgw5ZXlAXM4ot0oIaE
1DZVyiYS45XgYVEUVY/yKEjsSgN/4BX4t/EiQgH1EGXGhiKNfW2gudnlrYqbkSkITlLP
e8bkgt/4CPbdL/09wMyBBHXAxtk26gLTkPUrpVK5LJN+y3I+FcJ9jXIZeqE0h+6uK5yx
fx5g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795888135; x=1796492935;
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=V0RBQ7IGBKXTXGaWVl55cmq5G7e9BJ/ukmRpPb8VaOs=;
b=sqvgjYIi6Oeb9Gox/ufbiWr+xwmYWtkRtEHG99b9KqArjaKIztxJxlnG4Hu0+CFNpt
kzBnL4h61fRBGQ8+QM2uR3tnwCkoHEq/o+Db6XhSGpPX6XEmpP8xpl2UPDH4d9Q5cuOl
+vI1W24Vk2qhr+lF8TOnJ5iYOQ1PFCZ6lSEBlhPi8sEPIk4+3M1ZE+m1nW4pXwqSf/Cn
jCPBeNXXQJjBuu5WBy6JcJG/6IcXQjZZ71HgJeZJYew2/3PfEFf29hWkXJTWNOFFSggM
xHfUMezUJ/mb2YCHzKdPIFmLi91TOgMPm3fkNPh/CyPzRi/+8RF2qVSkNKnHcuJQRNZN
NDWg==
X-Gm-Message-State: APuU4Z8y8mNP6Y6JiYF29Ou/kzPd4c5A5QvWGMIjxA9O6nlTZMRlvxIU
ZHQ7P5Ad9eApBX3/2ohLT8SKALaWFjmaCefX6Px8ElB3RBp+Rv9TPfxL
X-Gm-Gg: AZFdTZdjaafEYwSv6aHbuA1xpYtKBBGopBFDdEHcBUfwG/iGRvs4eLPiFmfLoZprXcu
CU7m0cMFLomQRbL58cHGoF8wz7SILHUQW8rL8QJcfxoWIEwRVgzWSVxXOiDCBpZu4j3aV/73f9U
wnEspC6+nrVy+KccxbTCuEne4BoAaD+ZtSjCbPnFFjNFTDTWitN284GQzCH+3rcy+fep0yOzwSs
Yz2jpQ2cLUtXGEzB3bAAw5Esthibz5FxrXXCL/eY7MlL5N1GXTfchiruaDKc3rQsyEuyADFxTXc
hdgzrR80hFa4Js6dAiofthnnPDqqSMA7fwidLSdd/owFogAOP0yP0dQcCjVHb2Al2emzdInxwzm
j3xS3iuv37MSyz4/RHTGhkDmXXBFH9c78LOWvsufB2WXA8CJv0SUpEcQZECTI0iRD6grmLn05O9
oxwYGaebewG/GpXCF4EXrBRAcxyAE+EiORwgsrzv+JJBDxguOqc/GPa/GGLeFO4kYkl8ynokvzw
fb9PLmTMGBuz0M5aICukAwIsC9LDh/eCJCfKC2fWEzKSphe82arv8qDeTptuTGDK4raTQr+1tH3
bru4Na9Q8AG7cpq8SWJgkvYIs3+LbCriXURQZ0iuFK4zmjkhrR2M
X-Received: by 2002:a05:690c:d0f:b0:8b4:d516:f820 with SMTP id 00721157ae682-8b5204d2c1bmr114718747b3.45.1795888134687;
Sat, 28 Nov 2026 09:48:54 -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.52
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Sat, 28 Nov 2026 09:48:54 -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