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=1796095339; b=whS4U1Q8eVhDvdM/CTFVzGaL9rawuTW3SGXdq2oM0qm9/z8jUWYbyE45RP3w7VbkF7ah Ky+xug8PK4GYVW3W1rm80IzODrhDXYu4yH5QFyUfCnkOEhFgdQ2ycmPAK1KCrZCUG8jgK WIhai9PF5ZIsi2IZJB1jlXQfZmRvV+bstwj7VlZ0OeDc+DFd8X6bIfVCdIyLY9GXlOI+C dDrfIWn/URugF5Aa/fZu3+0uWbTMI77EeUjEXW0SP7n6fMBpdA7f0qi+IYY0dydrzDp/H ax+hD79Y3427nEMzUkV/wLr06PUiXBaJWx1X3yOWO47dB/tr8yJBfH1mKC6V82uug9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796095339; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=rCU9lZeNhLgHeEr4W+YZph5zcQlCCiqHAQpCqRVvRhsVLW/hgGi2RDCgjHpHDb/2kniu nfJ0nD38x5/2660UQvtX9Enl2MLZiTZK2venBCizQsJ11JO3llrssIgLEhuA3wT0Yyxsw LNnFq3yMFekhW6NcRCrRxhI0JNaTD1lEK6AZeQh5WhGwofTaixCRsCBCagpCC9rhZumUS TgH7fhowZDISD+wtcAHnHJ6lSWEyKyJh+l7p6YQqG1W/oQEY/pRK6ggC6ez8IIdUD9Bzw hMvQC0RPbwH3cAQ0YKMHxD+6k7fMZ24FAJEdcwsW9GWHOghp/qtAaRwvnkO4HA0RFgw== 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=Z+uhfe3Q; 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 60729606A327 for ; Tue, 1 Dec 2026 03:22:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 60729606A327 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=Z+uhfe3Q Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-67df3b1ca06so12638180d50.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=lists.linux.dev; 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=Z+uhfe3QVt5+PnCJATNCWSp4SlFbSMnRuwyQDVoePYfSF1o3G5CHYHL5SheFwZMAI2 UMOJpmiUIolabBVC+xgn0xGReweE8t4cWCNL6D0DyZELzbPA3peIKdGUspHiwqyIwzn9 kpXQEOfPG3FNt6Q9I8a8gk+9kRqhUmursHpyAH17OWlBErpNOIkfDTBiCo7R85xA60Oq InU+xvkE/wvm56qdt9W4n0HiUbUwXv15Y/pWlmKZ/Q4gheIb5c+SVv64vZAoJhCcchNB 0kvw7W+fGMn/7RI9XIT68IkBdepruHcEli5cUWEn9zevWTjf38DaLs8KowFCx6mkLFaO lryw== 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=xedYe3hASOwlhetXisESgONtrS9wMMSsZIPxwaqbGbLTSEcRBpQ4jSdk5FuzCBlEna FwwJkXbIPyymMBMOQYI3TbMxr+u/XYTv7zIJ1cK4BBJRNQfEL1jCg7TG3DR5vfSn/Z6I LCDRZMZiOuY/OmxI74YhD/CHaKCZRXQmBhT2tVJ9zIehU+jMbgKATjd77kfL4YoABaSU 5tWg2O8mGZ+pQ6nLfft8xNSocj3Cl3nNe3JJqaSKFqaVe53I7PMPXRzTt6iXNYurWun+ mgN7vISxQbqaVtRMoXljxTYx08sQZ02upqqxOvcOwWOjnAYn8KaH7sVHXw2OjAqY4SaL MfAA== X-Forwarded-Encrypted: i=1; AL+hErHsmGQAbQ1/zlYfuAkJTAr9nQu1SKXNI1WVfr3RH3F5j8+o/tQgOa9xVj4TS8c7LibUGAJSEA==@lists.linux.dev X-Gm-Message-State: APuU4Z/nwDFusBVQU0QxPNgCwGhuH1WgbR8wk1kH8pD6A5kzYFUJ9NVA 3I26WvZ7TjARfQ/u4LxrqXxONt4hj1owUxIe2LWA0oqacNTJBMpQt2ni X-Gm-Gg: AZFdTZez8s5AuNdqhcxESFxKxfkErfhcCrpB4COQ/gDOdwRXwPFUuQTPphMeWWSoTxs JeoSbFcwW5rhZTXQSgGlD/5vRY61RwIN7bK34jYBi8Dv0tFyvwFf0mt0TkSsZzl11Ltfp4zVBRK JA8WReCIjqOkhYlOqnLCafzfd7K+UooQv3Bgbdd7mSOeQUGIdnK1Xtw8rRPcN1bLEGjbSUt4kGU vHWxp8tWP4QfPx3Z2uN58ncX9PQZghKPH3JjKCu07WVBze+O9IvwZMPPJ36R4oAU/n9bqdwKbaF ATzhtzGz2f3iGPVsjYhYicz/n9JQGuZHXUUiL6igelcxAkWIp52cnxWjaMf0vpr2eUgulM6L8XX 5gWzL3Cu6vH2OiFMkXSC3+7dWECNaBzeI0KsBFxwb8TpWrb+xVrZqi05T/iDs30NF3ihQciZSbb jXGlOejDWdUHoYQy5OrGonPv8PtKICKSA2mZnLmEwwpHPCv2WGOcUve2FvYoxzY/VuTH+nihGIX TtU7LBADTK1KxZtNGITW++5bhJe8gi/LfYRKzS0pfJiHyjHUIMgk4zT1cCQ0GrNsUW2AjlmZk8b EdKNbiWmRLR/ixDgru1PnNs7eOBWO5Q04rqEQnvDp6FubY4bWai5 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: ipsec@lists.linux.dev 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