svc_dg: bound the datagram decode to the received length
Subsystems (2)
PATCH 1/1 svc_dg: bound the datagram decode to the received length
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.
--- src/svc_dg.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
src/svc_dg.c +21 -4
@@ -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 ||
Signature · 1 line
2.56.1