From: Juan Agustin Niccolini <juanagusnicco@gmail.com>
To: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Christian Hopps <chopps@labn.net>,
Antony Antony <antony.antony@secunet.com>,
Sabrina Dubroca <sd@queasysnail.net>,
Shaomin Chen <eeesssooo020@gmail.com>,
Roshan Kumar <roshaen09@gmail.com>
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 [thread overview]
Message-ID: <20261201032200.37030-5-juanagusnicco@gmail.com> (raw)
In-Reply-To: <20261201032200.37030-1-juanagusnicco@gmail.com>
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 <juanagusnicco@gmail.com>
---
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
prev parent reply other threads:[~2026-12-01 3:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 3:21 [PATCH ipsec 0/4] xfrm: iptfs: fix use-after-free by held and queued packets Juan Agustin Niccolini
2026-12-01 3:21 ` [PATCH ipsec 1/4] xfrm: iptfs: free held packets on SA delete to fix a netns UAF Juan Agustin Niccolini
2026-12-01 3:21 ` [PATCH ipsec 2/4] xfrm: iptfs: look up the device of held packets again to fix a UAF Juan Agustin Niccolini
2026-12-01 3:21 ` [PATCH ipsec 3/4] xfrm: iptfs: free queued packets on SA delete to fix a netns UAF Juan Agustin Niccolini
2026-12-01 3:22 ` Juan Agustin Niccolini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201032200.37030-5-juanagusnicco@gmail.com \
--to=juanagusnicco@gmail.com \
--cc=antony.antony@secunet.com \
--cc=chopps@labn.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eeesssooo020@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=ipsec@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=roshaen09@gmail.com \
--cc=sd@queasysnail.net \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox