From nobody Thu Apr 16 19:14:11 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61BFB38BF76; Thu, 26 Feb 2026 08:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772094400; cv=none; b=GoF1DUC6hla+uPhEqdhtesEPDm4NDquXPBmSEgGcVXLp+yx9GIANf4LFgHV9A/4SwuenW2Mk85OXe8aWmuKJbkDmrxvPDku6AnUnkAqwn2ygNBzTvIfNrPiV53mkxO0ZHWyb3w/zhcvMdvawAQiLomEZRg9rHMjieMy82no+xkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772094400; c=relaxed/simple; bh=CuI2yNXHozZ33l6jpyWWDZFsLsZN9RIjVXSuGyZRcBo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=XEjKYmgIRxb5PNnXwIOGFeh4iGEywsGaPX6+dMgN/dxmSqAY+vS0oiR1QAwPzr/m8YiWEQMps6qQBYujB4tFTlUXWQuTBfihxB0Fkcu9qFNl9dKQ2BE5tEhgzA2G5eyXeva2j2Np/7mSldUtTD9aD76jXDvG2KWq2Bwp6A/YsWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ErGTIqCz; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ErGTIqCz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=WM jluf9TG1wFE9HBrFIWE9aXj+JL5OmXE4kFqv3zFRw=; b=ErGTIqCzEM/0Qj9WAN tQC5d3FBs9lh8GbRH0LcDpJTOjpuaVKfX3z4js0c9p80Lm4y0WTcwOOVzmpKG9ny 0lY2KCwn96XnCmmWKT2YexcVGo7XRkhjbfmIW8bwDdMMZ9PtKCb/u7n11PvfQYQ4 CZlkkoXgMu9mh6PohhV3d4NAs= Received: from pek-lpg-core5.wrs.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wBndakSA6BpaN3nMw--.29763S2; Thu, 26 Feb 2026 16:23:47 +0800 (CST) From: Robert Garcia To: stable@vger.kernel.org, David Howells Cc: Marc Dionne , Robert Garcia , Steven Rostedt , linux-kernel@vger.kernel.org, Masami Hiramatsu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-afs@lists.infradead.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, Faith , Pumpkin Chang , Nir Ohfeld , Willy Tarreau , Simon Horman Subject: [PATCH 6.12.y] rxrpc: Fix recvmsg() unconditional requeue Date: Thu, 26 Feb 2026 16:23:46 +0800 Message-Id: <20260226082346.3200864-1-rob_garcia@163.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wBndakSA6BpaN3nMw--.29763S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWF4Duw4DWryxKF17Cry7trb_yoWrury8pF n8ArsxZw18Xw1IvFZ3GFy8WF15WFs2gr17Jr1fXasakr1Svw4vqF1jga13ZF15CanrArWU XF1DGw4jyrs8X37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07US9a9UUUUU= X-CM-SenderInfo: 5uresw5dufxti6rwjhhfrp/xtbC5hVIs2mgAxW6OwAA3W Content-Type: text/plain; charset="utf-8" From: David Howells [ Upstream commit 2c28769a51deb6022d7fbd499987e237a01dd63a ] 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 Reported-by: Pumpkin Chang Signed-off-by: David Howells Acked-by: Marc Dionne cc: Nir Ohfeld cc: Willy Tarreau cc: Simon Horman cc: linux-afs@lists.infradead.org cc: stable@kernel.org Link: https://patch.msgid.link/95163.1768428203@warthog.procyon.org.uk Signed-off-by: Jakub Kicinski [Use spin_unlock instead of spin_unlock_irq to maintain context consistency= .] Signed-off-by: Robert Garcia --- include/trace/events/rxrpc.h | 4 ++++ net/rxrpc/recvmsg.c | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h index eea3769765ac..c6cae9456698 100644 --- a/include/trace/events/rxrpc.h +++ b/include/trace/events/rxrpc.h @@ -274,6 +274,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_sock, "PUT rls-sock") \ EM(rxrpc_call_put_release_sock_tba, "PUT rls-sk-a") \ EM(rxrpc_call_put_sendmsg, "PUT sendmsg ") \ @@ -291,6 +292,9 @@ EM(rxrpc_call_see_distribute_error, "SEE dist-err") \ EM(rxrpc_call_see_input, "SEE input ") \ 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 e24a44bae9a3..b6e524c065f0 100644 --- a/net/rxrpc/recvmsg.c +++ b/net/rxrpc/recvmsg.c @@ -430,7 +430,8 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *m= sg, size_t len, if (rxrpc_call_has_failed(call)) goto call_failed; =20 - 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; =20 @@ -461,11 +462,21 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr = *msg, size_t len, error_requeue_call: if (!(flags & MSG_PEEK)) { spin_lock(&rx->recvmsg_lock); - list_add(&call->recvmsg_link, &rx->recvmsg_q); - spin_unlock(&rx->recvmsg_lock); + 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(&rx->recvmsg_lock); + } else if (list_is_first(&call->recvmsg_link, &rx->recvmsg_q)) { + spin_unlock(&rx->recvmsg_lock); + rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_first); + } else { + list_move(&call->recvmsg_link, &rx->recvmsg_q); + spin_unlock(&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); --=20 2.34.1