Re: git: 838ff5548b4f - main - xdr: Limit xdr_wrapstring
- In reply to: Dag-Erling Smørgrav : "git: 838ff5548b4f - main - xdr: Limit xdr_wrapstring"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 14 Nov 2026 20:26:21 UTC
Dag-Erling and reviewers,
On Sat, Nov 07, 2026 at 11:03:22PM +0000, Dag-Erling Smørgrav wrote:
D> The branch main has been updated by des:
D>
D> URL: https://cgit.FreeBSD.org/src/commit/?id=838ff5548b4f83707f34cfd28769e35393da3f05
D>
D> commit 838ff5548b4f83707f34cfd28769e35393da3f05
D> Author: Dag-Erling Smørgrav <des@FreeBSD.org>
D> AuthorDate: 2026-11-07 23:02:44 +0000
D> Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
D> CommitDate: 2026-11-07 23:03:14 +0000
D>
D> xdr: Limit xdr_wrapstring
D>
D> The previous commit (re)introduced the possibility that a malicious or
D> corrupt message can cause the receiver to allocate a very large amount
D> of memory before realizing that the message is much shorter than
D> claimed. Revert the change to xdr_wrapstring() to avoid this.
D>
D> Fixes: d2018cedb414 ("xdr: Fix xdr_string")
D> Reported by: bjk@
D> Reviewed by: markj
D> Differential Revision: https://reviews.freebsd.org/D60898
D> lib/libc/xdr/xdr.c | 4 +++-
D> sys/xdr/xdr.c | 4 +++-
D> 2 files changed, 6 insertions(+), 2 deletions(-)
D>
D> diff --git a/lib/libc/xdr/xdr.c b/lib/libc/xdr/xdr.c
D> index f8cc5267d350..82f69882a30d 100644
D> --- a/lib/libc/xdr/xdr.c
D> +++ b/lib/libc/xdr/xdr.c
D> @@ -47,6 +47,8 @@
D> #include <stdlib.h>
D> #include <string.h>
D>
D> +#include <rpc/rpc.h>
D> +#include <rpc/rpc_com.h>
This function is literally documented as:
int
xdr_wrapstring(XDR *xdrs, char **sp)
A primitive that calls xdr_string(xdrs, sp, MAXUN.UNSIGNED);
where MAXUN.UNSIGNED is the maximum value of an unsigned integer.
The xdr_wrapstring() function is handy because the RPC package
passes a maximum of two XDR routines as arguments, and
xdr_string(), one of the most frequently used primitives,
requires three. Returns one if it succeeds, zero otherwise.
Limiting it directly opposed the documented purpose.
IMHO, the d2018cedb414 was a good change in general. It made XDR less RPC
specific. It removed a header include from dependant library code into
consumer library.
IMHO, the right thing to do would be to provide rpc_wrapstring() in RPC library
that can be casted to xdrproc_t. In the kernel we have only one consumer NLM
that can be fixed easily.
In the userland we have few small consumers and KRB5 :( We can contant
Kerberos people to check if they agree on using a different function that would
be documented as limited to RPC size.
--
Gleb Smirnoff