git: 838ff5548b4f - main - xdr: Limit xdr_wrapstring
- Reply: Gleb Smirnoff : "Re: git: 838ff5548b4f - main - xdr: Limit xdr_wrapstring"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 07 Nov 2026 23:03:22 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=838ff5548b4f83707f34cfd28769e35393da3f05
commit 838ff5548b4f83707f34cfd28769e35393da3f05
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-07 23:02:44 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-07 23:03:14 +0000
xdr: Limit xdr_wrapstring
The previous commit (re)introduced the possibility that a malicious or
corrupt message can cause the receiver to allocate a very large amount
of memory before realizing that the message is much shorter than
claimed. Revert the change to xdr_wrapstring() to avoid this.
Fixes: d2018cedb414 ("xdr: Fix xdr_string")
Reported by: bjk@
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D60898
---
lib/libc/xdr/xdr.c | 4 +++-
sys/xdr/xdr.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/libc/xdr/xdr.c b/lib/libc/xdr/xdr.c
index f8cc5267d350..82f69882a30d 100644
--- a/lib/libc/xdr/xdr.c
+++ b/lib/libc/xdr/xdr.c
@@ -47,6 +47,8 @@
#include <stdlib.h>
#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include "un-namespace.h"
@@ -762,7 +764,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
bool_t
xdr_wrapstring(XDR *xdrs, char **cpp)
{
- return (xdr_string(xdrs, cpp, ~0U));
+ return (xdr_string(xdrs, cpp, RPC_MAXDATASIZE));
}
/*
diff --git a/sys/xdr/xdr.c b/sys/xdr/xdr.c
index e012c83104d4..72ffd5ceb76b 100644
--- a/sys/xdr/xdr.c
+++ b/sys/xdr/xdr.c
@@ -46,6 +46,8 @@
#include <sys/malloc.h>
#include <sys/module.h>
+#include <rpc/rpc.h>
+#include <rpc/rpc_com.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
@@ -685,7 +687,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
bool_t
xdr_wrapstring(XDR *xdrs, char **cpp)
{
- return (xdr_string(xdrs, cpp, ~0U));
+ return (xdr_string(xdrs, cpp, RPC_MAXDATASIZE));
}
/*