Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796332515; b=UeLdYIdxsHjYn/0tJLWuXLRghluvLLWKNd2mivQ86/pJcMp/YACwhswaESdqpZ2OcM2Q gWvTK0uFbV2LJQw6zYxTv/Fuj6U3xA0u3A/nDZBCAgw/UM/gMq8u0gWBr9H80khlMCnwn qb21bnwQ3i/DObHbMk/ibWoI/bhBqp5rxqUOkLhRDgoGToRX68Q/GCiAbWaqBco9UmK2H u8Xt8HjTAITzr52Y8Iw4dFw3J+Efi+oqtnYR2oU7bCkI0u1WikQAw/XftaGxS8gTM4Yg/ v/nulS6gzD6geEoF18zSUGXW8RGv8C0CehThkmtwOST5728CXEvE5Cox5NimPLIjkZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796332515; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Received:From:To:Cc:Subject: Date:Message-ID:MIME-Version:Content-Transfer-Encoding:X-Scanned-By; bh=EADa5H83lpQvAGVSnI0EpemXYBd0JwUvlvo64Rvya8U=; b=bX1ajWtIpoc1Tjm0kQl15XrFIJmrHQdlAX33GxnOJ92BOC9HkpSPTbQW2yNMmp9nhQ32 EMSgM2ni88y/zZDcOE1itwO6OZ62MSs69/pJCUna95GrYDHvvTdP5dewV9zBR/ZPVwUgs BtClBSVcI+M46NAagaBQHFu0AiEmVIzlawrf3q6vGRkhYOxum/TFziVz8r384BIq4jirF wd3EJaYr/Lc4wOMf0/yZEZk9TPJdkYtxTig7qQkMUoZ2A2nfXLVC/UDucQU5NpTCvFfGt NsliqVvTePL7EQK0lgcCsTbFqgO0jewMvQUzXQQSlf+8s3UyzlZY4DwsWTn05Tj8XfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=So8qansV; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBDC3606A322 for ; Thu, 3 Dec 2026 21:15:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CBDC3606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=So8qansV DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796332514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EADa5H83lpQvAGVSnI0EpemXYBd0JwUvlvo64Rvya8U=; b=So8qansVcXcPxQbFKrOBjUgqe9nh+Y017llEpVCbqUd/vMpuoMNmt4RlvKljqbLp8RIWGo SakXy2p4wLWttOCq99J0Og3sPJ/VOoJ0zgntkfOPLLqpqSXm/AWXyYAb0VSNcbBOJ0iBuz /5Ifv8Ogd2gBTIRsGOyp34VkfNY6ySk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-4Qq5CxtyNh-9b9TsQPdmOA-1; Thu, 3 Dec 2026 21:15:12 +0000 X-MC-Unique: 4Qq5CxtyNh-9b9TsQPdmOA-1 X-Mimecast-MFC-AGG-ID: 4Qq5CxtyNh-9b9TsQPdmOA_1796332511 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1E3CE18B5FB1 for ; Thu, 3 Dec 2026 21:15:11 +0000 (UTC) Received: from smayhew-thinkpadp1gen4i.remote.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9742195605B; Thu, 3 Dec 2026 21:15:10 +0000 (UTC) Received: from smayhew-thinkpadp1gen4i.redhat.corp (localhost [IPv6:::1]) by smayhew-thinkpadp1gen4i.remote.csb (Postfix) with ESMTP id 449BA5D75354; Thu, 03 Dec 2026 16:15:10 -0500 (EST) From: Scott Mayhew To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [libtirpc PATCH] svc_dg: bound the datagram decode to the received length Date: Thu, 3 Dec 2026 16:15:10 -0500 Message-ID: <20261203211510.93733-1-smayhew@redhat.com> X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 svc_dg_recv() decoded every UDP request against su_xdrs, a single XDR memory stream that svc_dg_create() sizes to the whole receive buffer (su_iosz) and that is reused for the life of the transport. Before calling xdr_callmsg() it only did XDR_SETPOS(xdrs, 0). The xdrmem backend uses x_handy as the authoritative count of bytes remaining, and XDR_SETPOS(xdrs, 0) restores x_handy to the full su_iosz, so the decode was never limited to the number of bytes actually received (rlen). recvmsg() fills only the first rlen bytes of the buffer and leaves the tail holding stale data from a previous, larger datagram -- or from the reply that svc_dg_reply() encodes back into the same buffer. Any field whose decode runs past rlen therefore consumed that stale data as if it belonged to the current request: the call header, the credential and verifier parsed by xdr_callmsg(), and -- the main consequence -- the procedure arguments decoded afterwards by svc_dg_getargs(). A client could thus send a short datagram and have the service act on argument bytes it never sent; for a service whose reply reflects its arguments this can also return bytes left behind by another client's request or reply. This was reported as CVE-2026-104357. Size the decode stream to rlen -- re-create it with xdrmem_create() rather than only resetting the position -- which bounds xdr_callmsg() and the later svc_dg_getargs() decode alike; a request that advertises more than it sent now fails cleanly instead of reading stale bytes. Because the shared stream can then no longer be grown back to su_iosz by XDR_SETPOS(xdrs, 0), svc_dg_reply() re-creates it over the full buffer before encoding the reply, which is commonly larger than the request. Assisted-by: LLM Signed-off-by: Scott Mayhew --- src/svc_dg.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/svc_dg.c b/src/svc_dg.c index 3d42b6a..7764499 100644 --- a/src/svc_dg.c +++ b/src/svc_dg.c @@ -215,8 +215,20 @@ again: } __xprt_set_raddr(xprt, &ss); - xdrs->x_op = XDR_DECODE; - XDR_SETPOS(xdrs, 0); + /* + * Bind the decode stream to the number of bytes actually received in + * this datagram. rpc_buffer(xprt) is a single su_iosz-byte buffer + * reused for every datagram; recvmsg() fills only the first rlen bytes + * and leaves the tail holding stale data from a previous datagram (or + * from the reply encoded back into the same buffer). A plain + * XDR_SETPOS(xdrs, 0) restores the xdrmem bound (x_handy) to the full + * su_iosz, so decoding of any field that runs past rlen -- the call + * header, the credential and verifier, and in particular the procedure + * arguments decoded later by svc_dg_getargs() -- would consume those + * stale bytes as part of the current request. Sizing the stream to + * rlen makes such an over-read fail cleanly instead. + */ + xdrmem_create(xdrs, rpc_buffer(xprt), (u_int)rlen, XDR_DECODE); if (! xdr_callmsg(xdrs, msg)) { return (FALSE); } @@ -257,8 +269,13 @@ svc_dg_reply( } else has_args = FALSE; - xdrs->x_op = XDR_ENCODE; - XDR_SETPOS(xdrs, 0); + /* + * svc_dg_recv() sized the shared stream down to the received datagram + * length, so it can no longer be grown back to su_iosz with a plain + * XDR_SETPOS(xdrs, 0). Re-create it over the full buffer for encoding + * the reply, which is commonly larger than the request. + */ + xdrmem_create(xdrs, rpc_buffer(xprt), su->su_iosz, XDR_ENCODE); msg->rm_xid = su->su_xid; if (xdr_replymsg(xdrs, msg) && (!has_args || -- 2.56.1