* [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue
@ 2026-01-14 22:03 David Howells
2026-01-19 15:10 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Howells @ 2026-01-14 22:03 UTC (permalink / raw)
To: netdev
Cc: dhowells, Faith, Pumpkin Chang, Marc Dionne, Nir Ohfeld,
Willy Tarreau, Eric Dumazet, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-afs, security, stable,
linux-kernel
If rxrpc_recvmsg() fails because MSG_DONTWAIT was specified but the call at
the front of the recvmsg queue already has its mutex locked, it requeues
the call - whether or not the call is already queued. The call may be on
the queue because MSG_PEEK was also passed and so the call was not dequeued
or because the I/O thread requeued it.
The unconditional requeue may then corrupt the recvmsg queue, leading to
things like UAFs or refcount underruns.
Fix this by only requeuing the call if it isn't already on the queue - and
moving it to the front if it is already queued. If we don't queue it, we
have to put the ref we obtained by dequeuing it.
Also, MSG_PEEK doesn't dequeue the call so shouldn't call
rxrpc_notify_socket() for the call if we didn't use up all the data on the
queue, so fix that also.
Fixes: 540b1c48c37a ("rxrpc: Fix deadlock between call creation and sendmsg/recvmsg")
Reported-by: Faith <faith@zellic.io>
Reported-by: Pumpkin Chang <pumpkin@devco.re>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Marc Dionne <marc.dionne@auristor.com>
cc: Nir Ohfeld <niro@wiz.io>
cc: Willy Tarreau <w@1wt.eu>
cc: "David S. Miller" <davem@davemloft.net>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: netdev@vger.kernel.org
cc: security@kernel.org
cc: stable@kernel.org
---
Changes
=======
ver #2)
- Put our ref if the call is already queued.
include/trace/events/rxrpc.h | 4 ++++
net/rxrpc/recvmsg.c | 21 ++++++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h
index de6f6d25767c..869f97c9bf73 100644
--- a/include/trace/events/rxrpc.h
+++ b/include/trace/events/rxrpc.h
@@ -322,6 +322,7 @@
EM(rxrpc_call_put_kernel, "PUT kernel ") \
EM(rxrpc_call_put_poke, "PUT poke ") \
EM(rxrpc_call_put_recvmsg, "PUT recvmsg ") \
+ EM(rxrpc_call_put_recvmsg_peek_nowait, "PUT peek-nwt") \
EM(rxrpc_call_put_release_recvmsg_q, "PUT rls-rcmq") \
EM(rxrpc_call_put_release_sock, "PUT rls-sock") \
EM(rxrpc_call_put_release_sock_tba, "PUT rls-sk-a") \
@@ -340,6 +341,9 @@
EM(rxrpc_call_see_input, "SEE input ") \
EM(rxrpc_call_see_notify_released, "SEE nfy-rlsd") \
EM(rxrpc_call_see_recvmsg, "SEE recvmsg ") \
+ EM(rxrpc_call_see_recvmsg_requeue, "SEE recv-rqu") \
+ EM(rxrpc_call_see_recvmsg_requeue_first, "SEE recv-rqF") \
+ EM(rxrpc_call_see_recvmsg_requeue_move, "SEE recv-rqM") \
EM(rxrpc_call_see_release, "SEE release ") \
EM(rxrpc_call_see_userid_exists, "SEE u-exists") \
EM(rxrpc_call_see_waiting_call, "SEE q-conn ") \
diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
index 7fa7e77f6bb9..547e3e34f475 100644
--- a/net/rxrpc/recvmsg.c
+++ b/net/rxrpc/recvmsg.c
@@ -518,7 +518,8 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (rxrpc_call_has_failed(call))
goto call_failed;
- if (!skb_queue_empty(&call->recvmsg_queue))
+ if (!(flags & MSG_PEEK) &&
+ !skb_queue_empty(&call->recvmsg_queue))
rxrpc_notify_socket(call);
goto not_yet_complete;
@@ -549,11 +550,21 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
error_requeue_call:
if (!(flags & MSG_PEEK)) {
spin_lock_irq(&rx->recvmsg_lock);
- list_add(&call->recvmsg_link, &rx->recvmsg_q);
- spin_unlock_irq(&rx->recvmsg_lock);
- trace_rxrpc_recvmsg(call_debug_id, rxrpc_recvmsg_requeue, 0);
+ if (list_empty(&call->recvmsg_link)) {
+ list_add(&call->recvmsg_link, &rx->recvmsg_q);
+ rxrpc_see_call(call, rxrpc_call_see_recvmsg_requeue);
+ spin_unlock_irq(&rx->recvmsg_lock);
+ } else if (list_is_first(&call->recvmsg_link, &rx->recvmsg_q)) {
+ spin_unlock_irq(&rx->recvmsg_lock);
+ rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_first);
+ } else {
+ list_move(&call->recvmsg_link, &rx->recvmsg_q);
+ spin_unlock_irq(&rx->recvmsg_lock);
+ rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_move);
+ }
+ trace_rxrpc_recvmsg(call_debug_id, rxrpc_recvmsg_requeue, 0);
} else {
- rxrpc_put_call(call, rxrpc_call_put_recvmsg);
+ rxrpc_put_call(call, rxrpc_call_put_recvmsg_peek_nowait);
}
error_no_call:
release_sock(&rx->sk);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue
2026-01-14 22:03 [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue David Howells
@ 2026-01-19 15:10 ` Simon Horman
2026-01-19 18:05 ` Jakub Kicinski
2026-01-19 18:07 ` Jakub Kicinski
2026-01-19 18:10 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Simon Horman @ 2026-01-19 15:10 UTC (permalink / raw)
To: David Howells
Cc: netdev, Faith, Pumpkin Chang, Marc Dionne, Nir Ohfeld,
Willy Tarreau, Eric Dumazet, David S. Miller, Jakub Kicinski,
Paolo Abeni, linux-afs, security, stable, linux-kernel
On Wed, Jan 14, 2026 at 10:03:23PM +0000, David Howells wrote:
...
> diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
...
> @@ -549,11 +550,21 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
> error_requeue_call:
> if (!(flags & MSG_PEEK)) {
> spin_lock_irq(&rx->recvmsg_lock);
> - list_add(&call->recvmsg_link, &rx->recvmsg_q);
> - spin_unlock_irq(&rx->recvmsg_lock);
> - trace_rxrpc_recvmsg(call_debug_id, rxrpc_recvmsg_requeue, 0);
> + if (list_empty(&call->recvmsg_link)) {
> + list_add(&call->recvmsg_link, &rx->recvmsg_q);
> + rxrpc_see_call(call, rxrpc_call_see_recvmsg_requeue);
> + spin_unlock_irq(&rx->recvmsg_lock);
> + } else if (list_is_first(&call->recvmsg_link, &rx->recvmsg_q)) {
> + spin_unlock_irq(&rx->recvmsg_lock);
> + rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_first);
> + } else {
> + list_move(&call->recvmsg_link, &rx->recvmsg_q);
> + spin_unlock_irq(&rx->recvmsg_lock);
> + rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_move);
> + }
> + trace_rxrpc_recvmsg(call_debug_id, rxrpc_recvmsg_requeue, 0);
Hi David,
If you need to re-spin for some other reason then please
fix the line above so only tabs are used for indentation
(a leading space seems to have sneaked in somehow).
> } else {
> - rxrpc_put_call(call, rxrpc_call_put_recvmsg);
> + rxrpc_put_call(call, rxrpc_call_put_recvmsg_peek_nowait);
> }
> error_no_call:
> release_sock(&rx->sk);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue
2026-01-19 15:10 ` Simon Horman
@ 2026-01-19 18:05 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-19 18:05 UTC (permalink / raw)
To: David Howells
Cc: Simon Horman, netdev, Faith, Pumpkin Chang, Marc Dionne,
Nir Ohfeld, Willy Tarreau, Eric Dumazet, David S. Miller,
Paolo Abeni, linux-afs, security, stable, linux-kernel
On Mon, 19 Jan 2026 15:10:14 +0000 Simon Horman wrote:
> If you need to re-spin for some other reason then please
> fix the line above so only tabs are used for indentation
> (a leading space seems to have sneaked in somehow).
Fixed when applying, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue
2026-01-14 22:03 [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue David Howells
2026-01-19 15:10 ` Simon Horman
@ 2026-01-19 18:07 ` Jakub Kicinski
2026-01-19 18:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-19 18:07 UTC (permalink / raw)
To: David Howells
Cc: netdev, Faith, Pumpkin Chang, Marc Dionne, Nir Ohfeld,
Willy Tarreau, Eric Dumazet, David S. Miller, Paolo Abeni,
Simon Horman, linux-afs, security, stable, linux-kernel
On Wed, 14 Jan 2026 22:03:23 +0000 David Howells wrote:
> cc: security@kernel.org
And I'ma drop this CC, I doubt security@ wants to get CCed as this
patch travels to stable.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue
2026-01-14 22:03 [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue David Howells
2026-01-19 15:10 ` Simon Horman
2026-01-19 18:07 ` Jakub Kicinski
@ 2026-01-19 18:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-19 18:10 UTC (permalink / raw)
To: David Howells
Cc: netdev, faith, pumpkin, marc.dionne, niro, w, edumazet, davem,
kuba, pabeni, horms, linux-afs, security, stable, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 14 Jan 2026 22:03:23 +0000 you wrote:
> If rxrpc_recvmsg() fails because MSG_DONTWAIT was specified but the call at
> the front of the recvmsg queue already has its mutex locked, it requeues
> the call - whether or not the call is already queued. The call may be on
> the queue because MSG_PEEK was also passed and so the call was not dequeued
> or because the I/O thread requeued it.
>
> The unconditional requeue may then corrupt the recvmsg queue, leading to
> things like UAFs or refcount underruns.
>
> [...]
Here is the summary with links:
- [net,v2] rxrpc: Fix recvmsg() unconditional requeue
https://git.kernel.org/netdev/net/c/2c28769a51de
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-19 18:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 22:03 [PATCH net v2] rxrpc: Fix recvmsg() unconditional requeue David Howells
2026-01-19 15:10 ` Simon Horman
2026-01-19 18:05 ` Jakub Kicinski
2026-01-19 18:07 ` Jakub Kicinski
2026-01-19 18:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox