mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 19:34:43 +01:00
* limit size of buffers to RPC_MAXDATASIZE
* don't leak memory * be more picky about bad parameters From: https://raw.githubusercontent.com/guidovranken/rpcbomb/master/libtirpc_patch.txt https://github.com/guidovranken/rpcbomb/blob/master/rpcbind_patch.txt via NetBSD. Reviewed by: emaste, cem (earlier version) Differential Revision: https://reviews.freebsd.org/D10922 MFC after: 3 days
This commit is contained in:
1 parent
26f923dca3
commit
6448ec89e7
9 files changed
+96
-30
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319369
No files matched your search
@@ -609,6 +609,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
if (nbuf->len < sizeof(*sin))
|
||||
return NULL;
|
||||
sin = nbuf->buf;
|
||||
if (inet_ntop(af, &sin->sin_addr, namebuf, sizeof namebuf)
|
||||
== NULL)
|
||||
@@ -620,6 +622,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
if (nbuf->len < sizeof(*sin6))
|
||||
return NULL;
|
||||
sin6 = nbuf->buf;
|
||||
if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6)
|
||||
== NULL)
|
||||
@@ -658,6 +662,10 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr)
|
||||
|
||||
port = 0;
|
||||
sin = NULL;
|
||||
|
||||
if (uaddr == NULL)
|
||||
return NULL;
|
||||
|
||||
addrstr = strdup(uaddr);
|
||||
if (addrstr == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/rpcb_prot.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
bool_t
|
||||
@@ -62,13 +63,13 @@ xdr_rpcb(XDR *xdrs, RPCB *objp)
|
||||
if (!xdr_rpcvers(xdrs, &objp->r_vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_addr, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_owner, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
@@ -162,19 +163,19 @@ xdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
|
||||
bool_t
|
||||
xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
|
||||
{
|
||||
if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_maddr, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_protofmly, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_proto, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
@@ -289,7 +290,7 @@ xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *p)
|
||||
bool_t dummy;
|
||||
struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p;
|
||||
|
||||
if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->addr, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_u_int(xdrs, &objp->results.results_len)) {
|
||||
|
||||
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
/* Link list of all the stats about getport and getaddr */
|
||||
@@ -63,7 +64,7 @@ xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
|
||||
if (!xdr_int(xdrs, &objp->failure)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
|
||||
IXDR_PUT_INT32(buf, objp->failure);
|
||||
IXDR_PUT_INT32(buf, objp->indirect);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
pnext = &objp->next;
|
||||
@@ -154,7 +155,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
|
||||
objp->failure = (int)IXDR_GET_INT32(buf);
|
||||
objp->indirect = (int)IXDR_GET_INT32(buf);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
@@ -182,7 +183,7 @@ xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
|
||||
if (!xdr_int(xdrs, &objp->indirect)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_pointer(xdrs, (char **) pnext,
|
||||
|
||||
+25
-5
@@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$");
|
||||
#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"
|
||||
@@ -64,7 +66,6 @@ typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */
|
||||
*/
|
||||
#define XDR_FALSE ((long) 0)
|
||||
#define XDR_TRUE ((long) 1)
|
||||
#define LASTUNSIGNED ((u_int) 0-1)
|
||||
|
||||
/*
|
||||
* for unit alignment
|
||||
@@ -561,6 +562,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
{
|
||||
char *sp = *cpp; /* sp is the actual string pointer */
|
||||
u_int nodesize;
|
||||
bool_t ret, allocated = FALSE;
|
||||
|
||||
/*
|
||||
* first deal with the length since xdr bytes are counted
|
||||
@@ -584,6 +586,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
}
|
||||
if (sp == NULL) {
|
||||
*cpp = sp = mem_alloc(nodesize);
|
||||
allocated = TRUE;
|
||||
}
|
||||
if (sp == NULL) {
|
||||
warnx("xdr_bytes: out of memory");
|
||||
@@ -592,7 +595,14 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case XDR_ENCODE:
|
||||
return (xdr_opaque(xdrs, sp, nodesize));
|
||||
ret = xdr_opaque(xdrs, sp, nodesize);
|
||||
if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
|
||||
if (allocated == TRUE) {
|
||||
free(sp);
|
||||
*cpp = NULL;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
|
||||
case XDR_FREE:
|
||||
if (sp != NULL) {
|
||||
@@ -683,6 +693,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
char *sp = *cpp; /* sp is the actual string pointer */
|
||||
u_int size;
|
||||
u_int nodesize;
|
||||
bool_t ret, allocated = FALSE;
|
||||
|
||||
/*
|
||||
* first deal with the length since xdr strings are counted-strings
|
||||
@@ -716,8 +727,10 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
if (nodesize == 0) {
|
||||
return (TRUE);
|
||||
}
|
||||
if (sp == NULL)
|
||||
if (sp == NULL) {
|
||||
*cpp = sp = mem_alloc(nodesize);
|
||||
allocated = TRUE;
|
||||
}
|
||||
if (sp == NULL) {
|
||||
warnx("xdr_string: out of memory");
|
||||
return (FALSE);
|
||||
@@ -726,7 +739,14 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case XDR_ENCODE:
|
||||
return (xdr_opaque(xdrs, sp, size));
|
||||
ret = xdr_opaque(xdrs, sp, size);
|
||||
if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
|
||||
if (allocated == TRUE) {
|
||||
free(sp);
|
||||
*cpp = NULL;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
|
||||
case XDR_FREE:
|
||||
mem_free(sp, nodesize);
|
||||
@@ -744,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, LASTUNSIGNED);
|
||||
return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -311,6 +311,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
if (nbuf->len < sizeof(*sin))
|
||||
return NULL;
|
||||
sin = nbuf->buf;
|
||||
if (inet_ntop(af, &sin->sin_addr, namebuf, sizeof namebuf)
|
||||
== NULL)
|
||||
@@ -323,6 +325,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
if (nbuf->len < sizeof(*sin6))
|
||||
return NULL;
|
||||
sin6 = nbuf->buf;
|
||||
if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6)
|
||||
== NULL)
|
||||
@@ -366,6 +370,10 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr)
|
||||
|
||||
port = 0;
|
||||
sin = NULL;
|
||||
|
||||
if (uaddr == NULL)
|
||||
return NULL;
|
||||
|
||||
addrstr = strdup(uaddr, M_RPC);
|
||||
if (addrstr == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -1287,6 +1287,11 @@ xdr_netbuf(XDR *xdrs, struct netbuf *objp)
|
||||
return (FALSE);
|
||||
}
|
||||
pp = &objp->buf;
|
||||
|
||||
if (objp->maxlen > RPC_MAXDATASIZE) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
dummy = xdr_bytes(xdrs, (char **) pp,
|
||||
(u_int *)&(objp->len), objp->maxlen);
|
||||
return (dummy);
|
||||
|
||||
+8
-7
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include <rpc/rpcb_prot.h>
|
||||
|
||||
bool_t
|
||||
@@ -74,13 +75,13 @@ xdr_rpcb(XDR *xdrs, RPCB *objp)
|
||||
if (!xdr_uint32_t(xdrs, &objp->r_vers)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_addr, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_owner, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
@@ -175,19 +176,19 @@ xdr_rpcblist(XDR *xdrs, RPCBLIST **rp)
|
||||
bool_t
|
||||
xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp)
|
||||
{
|
||||
if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_maddr, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_netid, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_uint32_t(xdrs, &objp->r_nc_semantics)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_protofmly, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
|
||||
if (!xdr_string(xdrs, &objp->r_nc_proto, RPC_MAXDATASIZE)) {
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
|
||||
+25
-5
@@ -51,6 +51,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
|
||||
@@ -62,7 +64,6 @@ typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */
|
||||
*/
|
||||
#define XDR_FALSE ((long) 0)
|
||||
#define XDR_TRUE ((long) 1)
|
||||
#define LASTUNSIGNED ((u_int) 0-1)
|
||||
|
||||
/*
|
||||
* for unit alignment
|
||||
@@ -503,6 +504,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
{
|
||||
char *sp = *cpp; /* sp is the actual string pointer */
|
||||
u_int nodesize;
|
||||
bool_t ret, allocated = FALSE;
|
||||
|
||||
/*
|
||||
* first deal with the length since xdr bytes are counted
|
||||
@@ -526,6 +528,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
}
|
||||
if (sp == NULL) {
|
||||
*cpp = sp = mem_alloc(nodesize);
|
||||
allocated = TRUE;
|
||||
}
|
||||
if (sp == NULL) {
|
||||
printf("xdr_bytes: out of memory");
|
||||
@@ -534,7 +537,14 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case XDR_ENCODE:
|
||||
return (xdr_opaque(xdrs, sp, nodesize));
|
||||
ret = xdr_opaque(xdrs, sp, nodesize);
|
||||
if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
|
||||
if (allocated == TRUE) {
|
||||
mem_free(sp, nodesize);
|
||||
*cpp = NULL;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
|
||||
case XDR_FREE:
|
||||
if (sp != NULL) {
|
||||
@@ -622,6 +632,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
char *sp = *cpp; /* sp is the actual string pointer */
|
||||
u_int size;
|
||||
u_int nodesize;
|
||||
bool_t ret, allocated = FALSE;
|
||||
|
||||
/*
|
||||
* first deal with the length since xdr strings are counted-strings
|
||||
@@ -655,8 +666,10 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
if (nodesize == 0) {
|
||||
return (TRUE);
|
||||
}
|
||||
if (sp == NULL)
|
||||
if (sp == NULL) {
|
||||
*cpp = sp = mem_alloc(nodesize);
|
||||
allocated = TRUE;
|
||||
}
|
||||
if (sp == NULL) {
|
||||
printf("xdr_string: out of memory");
|
||||
return (FALSE);
|
||||
@@ -665,7 +678,14 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case XDR_ENCODE:
|
||||
return (xdr_opaque(xdrs, sp, size));
|
||||
ret = xdr_opaque(xdrs, sp, size);
|
||||
if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
|
||||
if (allocated == TRUE) {
|
||||
mem_free(sp, nodesize);
|
||||
*cpp = NULL;
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
|
||||
case XDR_FREE:
|
||||
mem_free(sp, nodesize);
|
||||
@@ -683,7 +703,7 @@ xdr_string(XDR *xdrs, char **cpp, u_int maxsize)
|
||||
bool_t
|
||||
xdr_wrapstring(XDR *xdrs, char **cpp)
|
||||
{
|
||||
return xdr_string(xdrs, cpp, LASTUNSIGNED);
|
||||
return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <stdio.h>
|
||||
#ifdef PORTMAP
|
||||
#include <netinet/in.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#endif /* PORTMAP */
|
||||
#include <string.h>
|
||||
@@ -418,7 +419,8 @@ rpcbproc_taddr2uaddr_com(void *arg, struct svc_req *rqstp __unused,
|
||||
static bool_t
|
||||
xdr_encap_parms(XDR *xdrs, struct encap_parms *epp)
|
||||
{
|
||||
return (xdr_bytes(xdrs, &(epp->args), (u_int *) &(epp->arglen), ~0));
|
||||
return (xdr_bytes(xdrs, &(epp->args), (u_int *) &(epp->arglen),
|
||||
RPC_MAXDATASIZE));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user