From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.246.68.102]) (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 0989835AC38; Wed, 22 Apr 2026 22:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.246.68.102 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776896678; cv=none; b=l1qJVVhd2j3O8ANdYLTrLd9hfd63EffKbW3TWfnzxWZ0OeFXIRr988+b3EMeEX7Nmu7ua2QhlqUgjkReyc/U/99ru4iuQw9nQQ8SGHBp9KCB40T+ysqmpT86Wgk5UrjXr2kAUDwUrP478y385vSOsGdGYYJechR16Zqk4ButsUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776896678; c=relaxed/simple; bh=aV0Yqusp7dkh6lrlJ2Jv1Zo2aG5LKV0U0aIeTJ3mZbo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZiBmF1b+fY1cSEvV9x6Zrzq7g9ZQWiJ/1jMzekj1B/NHICG3S1VZffU6+H5LD23huH+3y9swb7UniZz1vxf2l7cLuCdenaCxkct3aKQ4Ew5w4VBPUl/B1J9QVYHLhNotAvHJc8OHIhFKbQyj99HmUbH7WO+EZLl15nl6aKr3K2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=srz/BMzB; arc=none smtp.client-ip=44.246.68.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="srz/BMzB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1776896677; x=1808432677; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2j1F84ix7FFqj+0BKDWxaKYO7U6TQBJMkXlqCnvcFf8=; b=srz/BMzBVaQ7knFkkgMEZ9Gm+vjUiVn+TlNsBZSMbiQx9+OGhDtYaPir I+scMxCIMamsF51lv1xfRxQc/F1+O8PhdVnVirgQKQTAnTR0h08NPjtXe yxBAJ1KLW6j35LVlPjdY38hcUSh6ARqKsATxa7LKwCNUANEqc3x9BdJkO z5CyoeCj2g2gvLp4Nl2WONe1PGxbFDld13s3rvLxLx16goRzUT05gpoQq aO5wG77IijQ2fAlHUR6VCv0GYtBqcpiF54+n8kS6HYHkKA7OV85OgAhIH UIEaSiBSCKNvmuCOUOWbjPwUUw/Oc2x7FW38Ecghn5nuzkt3f7aR+wiOd g==; X-CSE-ConnectionGUID: kkMX/GhXSauFJP+kzUZT+w== X-CSE-MsgGUID: G4IQBKh7StaLI0iTIB1cOQ== X-IronPort-AV: E=Sophos;i="6.23,193,1770595200"; d="scan'208";a="17996001" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2026 22:24:36 +0000 Received: from EX19MTAUWA002.ant.amazon.com [205.251.233.234:12510] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.51:2525] with esmtp (Farcaster) id d5547afb-e4a6-4a9a-a52e-92f951ea4799; Wed, 22 Apr 2026 22:24:36 +0000 (UTC) X-Farcaster-Flow-ID: d5547afb-e4a6-4a9a-a52e-92f951ea4799 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 22 Apr 2026 22:24:32 +0000 Received: from dev-dsk-wanjay-2c-d25651b4.us-west-2.amazon.com (172.19.198.4) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 22 Apr 2026 22:24:32 +0000 From: Jay Wang To: CC: , , , , , , , , , Faith , Pumpkin Chang Subject: [PATCH 5.15.y] rxrpc: Fix recvmsg() unconditional requeue Date: Wed, 22 Apr 2026 22:24:32 +0000 Message-ID: <20260422222432.7211-1-wanjay@amazon.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D044UWB001.ant.amazon.com (10.13.139.171) To EX19D001UWA001.ant.amazon.com (10.13.138.214) 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 Signed-off-by: Jakub Kicinski Cc: stable@vger.kernel.org [Adapted to 5.15: use write_lock_bh/write_unlock_bh, trace_rxrpc_call directly for see-call tracing, 5.15 trace enum naming convention, and added entries to both plain enum and EM() macro list.] Signed-off-by: Jay Wang --- include/trace/events/rxrpc.h | 8 ++++++++ net/rxrpc/recvmsg.c | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h --- a/include/trace/events/rxrpc.h +++ b/include/trace/events/rxrpc.h @@ -93,9 +93,13 @@ enum rxrpc_call_trace { rxrpc_call_put_notimer, rxrpc_call_put_timer, rxrpc_call_put_userid, + rxrpc_call_put_recvmsg_peek_nowait, rxrpc_call_queued, rxrpc_call_queued_ref, rxrpc_call_release, + rxrpc_call_see_recvmsg_requeue, + rxrpc_call_see_recvmsg_requeue_first, + rxrpc_call_see_recvmsg_requeue_move, rxrpc_call_seen, }; @@ -291,9 +295,13 @@ enum rxrpc_tx_point { EM(rxrpc_call_put_notimer, "PnT") \ EM(rxrpc_call_put_timer, "PTM") \ EM(rxrpc_call_put_userid, "Pus") \ + EM(rxrpc_call_put_recvmsg_peek_nowait, "PpN") \ EM(rxrpc_call_queued, "QUE") \ EM(rxrpc_call_queued_ref, "QUR") \ EM(rxrpc_call_release, "RLS") \ + EM(rxrpc_call_see_recvmsg_requeue, "SrQ") \ + EM(rxrpc_call_see_recvmsg_requeue_first,"SrF") \ + EM(rxrpc_call_see_recvmsg_requeue_move, "SrM") \ E_(rxrpc_call_seen, "SEE") #define rxrpc_transmit_traces \ diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c --- a/net/rxrpc/recvmsg.c +++ b/net/rxrpc/recvmsg.c @@ -607,7 +607,8 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, if (after(call->rx_top, call->rx_hard_ack) && call->rxtx_buffer[(call->rx_hard_ack + 1) & RXRPC_RXTX_BUFF_MASK]) - rxrpc_notify_socket(call); + if (!(flags & MSG_PEEK)) + rxrpc_notify_socket(call); break; default: ret = 0; @@ -642,11 +643,24 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, error_requeue_call: if (!(flags & MSG_PEEK)) { write_lock_bh(&rx->recvmsg_lock); - list_add(&call->recvmsg_link, &rx->recvmsg_q); - write_unlock_bh(&rx->recvmsg_lock); + if (list_empty(&call->recvmsg_link)) { + list_add(&call->recvmsg_link, &rx->recvmsg_q); + trace_rxrpc_call(call->debug_id, + rxrpc_call_see_recvmsg_requeue, + refcount_read(&call->ref), + __builtin_return_address(0), NULL); + write_unlock_bh(&rx->recvmsg_lock); + } else if (list_is_first(&call->recvmsg_link, &rx->recvmsg_q)) { + write_unlock_bh(&rx->recvmsg_lock); + rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_first); + } else { + list_move(&call->recvmsg_link, &rx->recvmsg_q); + write_unlock_bh(&rx->recvmsg_lock); + rxrpc_put_call(call, rxrpc_call_see_recvmsg_requeue_move); + } trace_rxrpc_recvmsg(call, rxrpc_recvmsg_requeue, 0, 0, 0, 0); } else { - rxrpc_put_call(call, rxrpc_call_put); + rxrpc_put_call(call, rxrpc_call_put_recvmsg_peek_nowait); } error_no_call: release_sock(&rx->sk); -- 2.43.0