From: Oancea Catalin <john3@mailbox.org>
To: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>
Cc: "David S. Miller" <davem@davemloft.net>,
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>,
linux-afs@lists.infradead.org, netdev@vger.kernel.org,
security@kernel.org
Subject: [PATCH net] rxrpc: Fix use-after-free of the UDP socket by queued error packets
Date: Sun, 29 Nov 2026 17:36:04 +0200 [thread overview]
Message-ID: <20261129153604.15390-1-john3@mailbox.org> (raw)
When a local endpoint is destroyed, an ICMP error packet that rxrpc
took from the endpoint's UDP socket can be freed after that socket.
The socket is then destroyed with receive memory still charged, and
the packet's destructor writes to the freed socket:
WARNING: net/ipv4/af_inet.c:159 at inet_sock_destruct+0x644/0x810
__sk_destruct
rcu_core
BUG: KASAN: slab-use-after-free in sock_rmem_free+0x6b/0x90
Write of size 4 at addr ffff888008758980 by task krxrpcio/20001
sock_rmem_free
skb_release_head_state
consume_skb
rxrpc_purge_queue
rxrpc_destroy_local
rxrpc_io_thread
Freed by task 98411:
kmem_cache_free
__sk_destruct
rcu_core
An unprivileged local user can trigger this with AF_RXRPC and UDP
sockets alone.
sock_queue_err_skb() puts an error packet on sk->sk_error_queue with
skb->sk set, sock_rmem_free() as its destructor and its truesize added
to sk->sk_rmem_alloc. It takes no reference on the socket, because the
socket purges that queue itself when it is destroyed.
rxrpc_error_report() dequeues these packets and queues them on
local->rx_queue for the I/O thread without changing their ownership,
so they end up on a queue the socket does not know about.
rxrpc_destroy_local() releases the UDP socket and only then purges
local->rx_queue. The socket is freed one RCU grace period after the
release. An error packet that arrived after the I/O thread's last pass
over the queue is still on it, and if the grace period ends before the
purge frees that packet, sock_rmem_free() subtracts from sk_rmem_alloc
in a socket that is gone.
Orphan the packet when it is taken off the socket's error queue.
rxrpc_input_error() only uses the packet's contents.
The warning was hit once by a local syzkaller instance. The cause was
found by reading the code and confirmed with a C reproducer that runs
as an ordinary user without any capability or namespace, on unmodified
kernels and without error injection. It gives both reports above on
v7.4-rc4-1054-g4f069ab1ec24 with KASAN. On kernels built without KASAN
and lockdep it gives the warning on that commit, on v6.12.107 and on
v6.2, and with slab poisoning for the UDP cache the first two also
report the overwritten poison. It does not trigger on v6.1 or on the
parent of the commit named below. With this patch, which applies
unchanged to v6.12.107 and v6.2, it no longer triggers on any of the
three, and ICMP errors still fail the calls they belong to. There are
no rxrpc selftests to run. The reproducer is available on request.
An AI coding assistant (Claude Code) was used in the analysis and in
writing the reproducer and the patch.
Fixes: ff7348254e70 ("rxrpc: Move error processing into the local endpoint I/O thread")
Cc: stable@vger.kernel.org
Signed-off-by: Oancea Catalin <john3@mailbox.org>
---
Notes for reviewers, not for the changelog:
Where it reproduces. KVM guests (QEMU, x86-64; 2 vCPUs for the KASAN
kernel, 4 for the others), fresh boot per run, reproducer run as uid 65534.
"namespace" means inside a new user and network namespace with forged ICMP
errors from a raw socket; "plain" means no namespace and no capability,
with real host-unreachable errors.
kernel namespace plain with this patch
v7.4-rc4-1054-g4f069ab1ec24, KASAN 2 of 4 4 of 4 0 of 3, 0 of 2
the same commit, no KASAN/lockdep 4 of 4 3 of 3 0 of 4, 0 of 2
v6.12.107, Debian 13's config 4 of 4 3 of 3 0 of 4, 0 of 2
v6.2 5 of 6 1 of 6 0 of 4, 0 of 2
ff7348254e70 (the Fixes commit) 3 of 3 1 of 1
446b3e14525b (its parent) 0 of 3 0 of 1
v6.1 0 of 3 0 of 1
The KASAN kernel is my syzkaller config (lockdep, PREEMPT_LAZY, HZ=1000).
The others are built without KASAN, lockdep and the other debug options,
with PREEMPT_DYNAMIC and HZ=250. The v6.12.107 build uses the config file
of Debian 13's 6.12.107 kernel with AF_RXRPC, the boot drivers and three
filesystems my test image mounts built in; it is not Debian's binary.
Without KASAN a hit is the inet_sock_destruct() warning. Booted with
slub_debug=FZP,UDP, the non-KASAN mainline and v6.12.107 kernels also
report "BUG UDP: Object corrupt" with the poison overwritten at offset 0xc0
of a freed object, which is sk_rmem_alloc. On v6.2 the plain run needed
100000 idle connections instead of 60000; that is the one hit in six.
With the patch the console shows no other warning in any run, calls to an
address that does not answer ARP still fail when the kernel reports the
host unreachable, and in a traced run all 86 error packets taken from the
socket reached rxrpc_input_error(). net/rxrpc/ builds with W=1 under
allmodconfig and allyesconfig without warnings. net/main (28a371228d4e)
has the same net/rxrpc/io_thread.c; I did not build or run that tree.
About the reproducer. It uses AF_RXRPC and UDP sockets only, preempts
nothing and needs no special scheduling. It is not attached, as
security-bugs.rst asks when AI assistance was used. I will send it, with
a description of how it gets the timing, on request.
What the write does. It subtracts the packet's truesize from 32 bits at
offset 0xc0 of the freed object, once per leftover error packet. The UDP
socket cache can be merged with caches of other object types, so the slot
is not necessarily reused by a socket. I have not attempted to exploit
this. I can share what I looked at on request.
Not verified:
- a remote trigger. The ICMP errors and the datagrams that make the purge
long can come from another host, but the endpoint is only torn down by
a local event (its last socket is closed, or its network namespace
goes away). Nothing was tested over a network;
- an IPv6 endpoint. From reading, it takes the same path through
ipv6_icmp_error();
- releases other than the ones in the table, and any distribution's own
kernel binary;
- a second way for such a packet to miss the purge, from reading only:
rxrpc_error_report() can fetch local just before rxrpc_destroy_local()
clears sk_user_data and queue the packet after the purge. With this
patch that packet no longer refers to the socket, but it is leaked.
rxrpc_encap_rcv() has the same race for data packets. I have not
reproduced that and this patch does not address it.
Things I weighed:
- With this patch, error packets waiting on local->rx_queue are no longer
limited by the UDP socket's receive buffer. Until now
sock_queue_err_skb() refused new ones while about sk_rcvbuf worth were
outstanding. Data packets on that queue are not limited today either.
- The alternative is to keep the ownership and release the socket last:
clear sk_user_data, synchronize_rcu(), purge the queues, then
sock_release(). The pending "rxrpc: account encapsulated packets to UDP
socket" (v10 at
https://lore.kernel.org/all/63366fc0b98125b0e3581979770b30c19871f2b5.1792168462.git.zihanx@nebusec.ai/)
reorders the teardown that way for the packets it starts to charge. That
puts a grace period into every endpoint teardown, so I chose the smaller
change. If you prefer the reordering as the fix for this as well, I can
respin.
Trigger conditions: CONFIG_AF_RXRPC. No capability, no sysctl, no device.
The plain variant also needs a directly connected IPv4 subnet with an
address that does not answer ARP. I know of no mitigation other than not
having AF_RXRPC available.
I can send the kernel configs and the full logs.
net/rxrpc/io_thread.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/rxrpc/io_thread.c b/net/rxrpc/io_thread.c
index dc5184a2fa9d..a6f3d9d23839 100644
--- a/net/rxrpc/io_thread.c
+++ b/net/rxrpc/io_thread.c
@@ -73,6 +73,10 @@ void rxrpc_error_report(struct sock *sk)
}
while ((skb = skb_dequeue(&sk->sk_error_queue))) {
+ /* The packet leaves the UDP socket's queue and may outlive the
+ * socket, so it must not stay charged to it.
+ */
+ skb_orphan(skb);
skb->mark = RXRPC_SKB_MARK_ERROR;
rxrpc_new_skb(skb, rxrpc_skb_new_error_report);
skb_queue_tail(&local->rx_queue, skb);
base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
--
2.56.1
reply other threads:[~2026-11-29 15:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261129153604.15390-1-john3@mailbox.org \
--to=john3@mailbox.org \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=security@kernel.org \
--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