From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.52 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== 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== 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 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 ; Sat, 28 Nov 2026 17:48:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1568606A32A 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=dDwgi4B2 Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-67db1f6f50eso9359766d50.0 for ; Sat, 28 Nov 2026 09:48:55 -0800 (PST) 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) 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) 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 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 Message-ID: <20261128174844.53113-3-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 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 --- 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