1 From 7ea36eeece56b59f98e469934e4c20b4da043346 Mon Sep 17 00:00:00 2001
2 From: Doran Moppert <dmoppert@redhat.com>
3 Date: Thu, 11 May 2017 11:42:54 -0400
4 Subject: [PATCH] rpcbind: pair all svc_getargs() calls with svc_freeargs() to
7 This patch is to address CVE-2017-8779 "rpcbomb" in rpcbind, discussed
8 at [1], [2], [3]. The last link suggests this issue is actually a bug
9 in rpcbind, which led me here.
11 The leak caused by the reproducer at [4] appears to come from
12 rpcb_service_4(), in the case where svc_getargs() returns false and the
13 function had an early return, rather than passing through the cleanup
14 path at done:, as would otherwise occur.
16 It also addresses a couple of other locations where the same fault seems
17 to exist, though I haven't been able to exercise those. I hope someone
18 more intimate with rpc(3) can confirm my understanding is correct, and
19 that I haven't introduced any new bugs.
21 Without this patch, using the reproducer (and variants) repeatedly
22 against rpcbind with a numBytes argument of 1_000_000_000, /proc/$(pidof
23 rpcbind)/status reports VmSize increase of 976564 kB each call, and
24 VmRSS increase of around 260 kB every 33 calls - the specific numbers
25 are probably an artifact of my rhel/glibc version. With the patch,
26 there is a small (~50 kB) VmSize increase with the first message, but
27 thereafter both VmSize and VmRSS remain steady.
29 [1]: http://seclists.org/oss-sec/2017/q2/209
30 [2]: https://bugzilla.redhat.com/show_bug.cgi?id=1448124
31 [3]: https://sourceware.org/ml/libc-alpha/2017-05/msg00129.html
32 [4]: https://github.com/guidovranken/rpcbomb/
36 Upstream-Status: Backport
38 Signed-off-by: Fan Xin <fan.xin@jp.fujitsu.com>
40 src/pmap_svc.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---------
42 src/rpcb_svc_4.c | 2 +-
43 src/rpcb_svc_com.c | 8 ++++++++
44 4 files changed, 57 insertions(+), 11 deletions(-)
46 diff --git a/src/pmap_svc.c b/src/pmap_svc.c
47 index 4c744fe..e926cdc 100644
50 @@ -175,6 +175,7 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
57 * Can't use getpwnam here. We might end up calling ourselves
58 @@ -194,7 +195,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
60 if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)®)) {
68 @@ -205,7 +207,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
70 if (!check_access(xprt, op, reg.pm_prog, PMAPVERS)) {
71 svcerr_weakauth(xprt);
77 rpcbreg.r_prog = reg.pm_prog;
78 @@ -258,7 +261,16 @@ done_change:
79 rpcbs_set(RPCBVERS_2_STAT, ans);
81 rpcbs_unset(RPCBVERS_2_STAT, ans);
84 + if (!svc_freeargs(xprt, (xdrproc_t) xdr_pmap, (char *)®)) {
86 + /*(void) xlog(LOG_DEBUG, "unable to free arguments\n");*/
96 @@ -272,15 +284,18 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
102 if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)®)) {
109 if (!check_access(xprt, PMAPPROC_GETPORT, reg.pm_prog, PMAPVERS)) {
110 svcerr_weakauth(xprt);
117 @@ -330,21 +345,34 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
118 pmap_ipprot2netid(reg.pm_prot) ?: "<unknown>",
119 port ? udptrans : "");
123 + if (!svc_freeargs(xprt, (xdrproc_t) xdr_pmap, (char *)®)) {
125 + /* (void) xlog(LOG_DEBUG, "unable to free arguments\n");*/
136 pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
140 if (!svc_getargs(xprt, (xdrproc_t)xdr_void, NULL)) {
147 if (!check_access(xprt, PMAPPROC_DUMP, 0, PMAPVERS)) {
148 svcerr_weakauth(xprt);
154 if ((!svc_sendreply(xprt, (xdrproc_t) xdr_pmaplist_ptr,
155 @@ -354,7 +382,17 @@ pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
162 + if (!svc_freeargs(xprt, (xdrproc_t) xdr_pmap, (char *)NULL)) {
164 + /*(void) xlog(LOG_DEBUG, "unable to free arguments\n");*/
173 int pmap_netid2ipprot(const char *netid)
174 diff --git a/src/rpcb_svc.c b/src/rpcb_svc.c
175 index 709e3fb..091f530 100644
178 @@ -166,7 +166,7 @@ rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
179 svcerr_decode(transp);
181 (void) xlog(LOG_DEBUG, "rpcbind: could not decode");
186 if (rqstp->rq_proc == RPCBPROC_SET
187 diff --git a/src/rpcb_svc_4.c b/src/rpcb_svc_4.c
188 index 5094879..eebbbbe 100644
189 --- a/src/rpcb_svc_4.c
190 +++ b/src/rpcb_svc_4.c
191 @@ -218,7 +218,7 @@ rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
192 svcerr_decode(transp);
194 (void) xlog(LOG_DEBUG, "rpcbind: could not decode\n");
199 if (rqstp->rq_proc == RPCBPROC_SET
200 diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c
201 index 5862c26..cb63afd 100644
202 --- a/src/rpcb_svc_com.c
203 +++ b/src/rpcb_svc_com.c
204 @@ -927,6 +927,14 @@ error:
205 if (call_msg.rm_xid != 0)
206 (void) free_slot_by_xid(call_msg.rm_xid);
208 + if (!svc_freeargs(transp, (xdrproc_t) xdr_rmtcall_args, (char *) &a)) {
210 + (void) xlog(LOG_DEBUG, "unable to free arguments\n");