From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796095340; b=JuLWAmNVwXOAvju4KuPLc3pZUmksx6BUWZA6OuafIfwtaZn4KoFApFgpOhNuAtWK+bvQ dssKlamQzWa6PUUeCIjvELwY0krTpKMKgaHbuGPr7KOZHVK7x/b0t6927zGJ8iWVzkaa7 zICiGJUsT5AAUdFfLFUQab9Imnn3ipq8UoD5nqLNXZhRBDWmGh6Fkf4NGhmb4lpY8UucN HLgbB4554bUHeEgNqEaW4ijg/6cHyUJEGqN+nPAa7XK2ZlntBXTspBt6oBUmbjILlmllZ 5OYQFNVokXQBwxOHcpOAMaj1sBAVHgmKw/HkzcH/X/TcpJBT1zVxGnOQEvikLK5ZzGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796095340; 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=3E9Y0L8nw2lXstZZ+QPNvubQAIGJ1jZ3vH0rK2KbcSk=; b=nQ1jJzQ7vAMAtHBKLdVjfTlEMgMOxPh/QrJoxCeEbkHA5Vv0wHkvsHAtOYnUvOW3xkbR TZicAxkaYT/bVknwGR2v35HlDYrcYZRLEjvtEgUyBijTXwkf6GIofu0UIGiJDaf7bSDf1 IXe81rwf6R8JkWc+OB91A7Ip1GFx56W9XMrh60hJPbWOM6c/A5cpJeV1wtBZqK9pW900E sL7PCdQmCjjsGAOAtkci/GG8RgbHfxLLmhWmOyGrQ2nwwF6CGBYvDlDbKxvbn/LKWxr5r dcDpSChAutXjDCSzg6kfdQgruf8UmWxF7JrqtRGV92T7uZIHRMHYyna0ik0NQxapiKg== 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="qfO3ZF/b"; arc=none smtp.remote-ip=74.125.224.53 Received: from mail-yx1-f53.google.com (mail-yx1-f53.google.com [74.125.224.53]) (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 5AE41606A325 for ; Tue, 1 Dec 2026 03:22:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5AE41606A325 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=qfO3ZF/b Received: by mail-yx1-f53.google.com with SMTP id 956f58d0204a3-67df3b1ca06so12638182d50.2 for ; Mon, 30 Nov 2026 19:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796095338; x=1796700138; 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=3E9Y0L8nw2lXstZZ+QPNvubQAIGJ1jZ3vH0rK2KbcSk=; b=qfO3ZF/b+hjFNv2dOdaGcFNrE7RZSLZ/ug7F0/HrRaaHm3/C2umeNsp1w+gX4Npfg0 Of3WeZQmuHzxuFlbBNGKzKJy/w907FuTgtx+pVEzMJ+aCi4iG1ELVGQ6lnmByno2fQpL eUa2uVW2FyoXMs33YuZKWIEYKEAQ8+Qv2G+wAx6D4h2iBD2r0KFjTvJaLtp3lFmX1mfd cf0+XnD5iiv0/eEQkY5gEHq2umSts26VPa/TVEhGjnhTToriFqMGDDs1wx1oaCrIX1Pr LMUPjtlWNyLtY+sCzqhmw+TPZ1ND9derbLaiPJHik8flVJl41Gp36OuA4c5ScR24b7oV WL2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796095338; x=1796700138; 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=3E9Y0L8nw2lXstZZ+QPNvubQAIGJ1jZ3vH0rK2KbcSk=; b=HpNXzZKZltq+vtY/9ZixOw8qEXSH9Jjqje7JIAD5xblC4mlyEI8nNradNORuKa6peB eHVlcuX+so66RouUZZRja1k76Zs5FJc/M2ky8PqkdBK652DiF4SPbTqV0Dx2msIL2EGA 2YiYvkPpg7aOw/dQSK5qNbSqqnczXHfNmY0yzR8AUW0vT6GQxuxUFBjv+0oXFUfVpbDb yGEhI66HfW4i1jpyTR18KeWhoosbRgxdL/3QQpXMvBXLAIbCc3KPFrGfKTBebFszjUom /frxBpZfENS50SnLSf3Gm8d2l3YQa3Pri8CJu0nCqNZ4NbsJVcqHh7N9x53nDX/bxlSm VnNQ== X-Gm-Message-State: APuU4Z/IA3+mST8xgxWlj9tAYGnLYZ+Zeoyn2ESRVj9LbZ92lM1aqcsT Ii2DFl2Mg1Tzn3Rc41GuN4jTNO8XRzfV5leHwxXemkXxSzmsxFQIdhv8 X-Gm-Gg: AZFdTZdqHMW/RYHfziQ8i9V5qj700dU9yFCNqFSawunJD7woIHzl8LJj/fhAkEaBNGL 5hWNNvJ80IN+Ebl0InByrJS0+XzoN+0X8W8r2fpVV6a3nx7UE1kvhpEsUjnOyM8qjP/P4R//SSv BTWrvUm/IJPr6HDWAr6tMaSyK+Zm3K9KSNjzw6tTVANtZz46F/y9TfOAuVCSotzttS5A3yE3hxY FNm5lRLfHil8lc4c2M/2OKBFhR9GBf1rBSDP4cSFQkmVz1x/keP2denIJafhOwUSApCW1wWIZu1 TWsDqwEIs3nzXlgkjRU1tO+ALFR3iJUQQg3lXBRF1IOJYmqcuy3EBverYSXi4nEkO25/USN43xy tthDCAO5SkWwg6NWS/t5YKCMsIG2o4E+DpSR1axXkfcrJHU+L7uVQo63+2/i73j9l9Y9rBw1fLM 38PXYvMpddLv9tTqiU0mMaBvFv1j0l1TtDrNRM8h+njxyTUM8kSlDjbNuNfCs7Z6kBz+VkqiXXd 200rTbkBwHd2xgqdJbxL2XvXWpVShkY8JlpAvn4fqKme8wdxXA1meze3GRexn/JpDHPczC7GCaZ nxUsP0a0o6HsulaihCdcjVlValIUCCYue9DwUliYakQ5IiwQBoK3 X-Received: by 2002:a05:690e:13cf:b0:67c:17fb:eca8 with SMTP id 956f58d0204a3-67df43d06a2mr16960137d50.32.1796095338374; Mon, 30 Nov 2026 19:22:18 -0800 (PST) Received: from VPN-156-19.vpn.usf.edu ([2607:fe50:0:f802::4046]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df30e4407sm16484916d50.0.2026.11.30.19.22.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 19:22:18 -0800 (PST) From: Juan Agustin Niccolini To: Steffen Klassert , Herbert Xu , "David S . Miller" Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Christian Hopps , Antony Antony , Sabrina Dubroca , Shaomin Chen , Roshan Kumar Subject: [PATCH ipsec 4/4] xfrm: iptfs: don't keep the input device of queued packets to fix a UAF Date: Mon, 30 Nov 2026 22:22:00 -0500 Message-ID: <20261201032200.37030-5-juanagusnicco@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201032200.37030-1-juanagusnicco@gmail.com> References: <20261201032200.37030-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 A forwarded packet reaches iptfs_output_collect() with skb->dev still set to the device it was received on, and waits on xtfs->queue without a reference on that device. Without the queue, forwarding runs within the receive path's RCU read-side section, which keeps the device alive. If the device is deleted before iptfs_timer fires, the packet is still encrypted and sent, and ip_output() or ip6_output() passes the freed device to the POSTROUTING hooks as the input device. A rule that matches on the input device then reads the freed net_device, and an NFQUEUE verdict takes a reference on it with dev_hold(): BUG: KASAN: slab-use-after-free in nft_meta_get_eval+0x4b4/0x600 Read of size 4 at addr ff11000001d120e0 by task swapper/0/0 The rules that read the input device are the namespace owner's own, so the freed memory is returned to them: "meta iif", "iifname", "iiftype" and "iifgroup" hand back its bytes, and "iifkind" dereferences a pointer taken from it, which with the memory refilled reads 16 bytes from an address of the user's choosing. An unprivileged user can trigger this from a user and network namespace, by forwarding a packet into an IP-TFS SA and deleting the receiving device before the timer fires. Clear skb->dev when the packet is queued. The outer packet carries several inner packets, which may have arrived on different devices, so it has no single input device. POSTROUTING rules no longer see an input device for IP-TFS packets, as for packets from local sockets, which are already sent with a NULL skb->dev. Fixes: 0e4fbf013fa5 ("xfrm: iptfs: add user packet (tunnel ingress) handling") Cc: stable@vger.kernel.org Signed-off-by: Juan Agustin Niccolini --- Reproducer: https://github.com/AgusNicco/iptfs-uafs/blob/main/iptfs_output_dev_uaf.c net/xfrm/xfrm_iptfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 320de30ed8bd..0fd3a295d5a7 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -1834,6 +1834,7 @@ static bool iptfs_enqueue(struct xfrm_iptfs_data *xtfs, struct sk_buff *skb) IP6_ECN_set_ce(skb, ipv6_hdr(skb)); } + skb->dev = NULL; __skb_queue_tail(&xtfs->queue, skb); xtfs->queue_size += skb->len; return true; -- 2.53.0