aboutsummaryrefslogtreecommitdiff
path: root/sunrpc/svc.c
diff options
context:
space:
mode:
authorStefan Liebler <stli@linux.ibm.com>2020-12-04 17:00:27 +0100
committerStefan Liebler <stli@linux.ibm.com>2020-12-10 11:11:20 +0100
commit4b2e40a9259fab08161e1c607b06a41e15d543dc (patch)
treed9b01ed2133968f280d1a0d950fd7bd232ddd87a /sunrpc/svc.c
parent0d4ed9d40efa84e8dc88e64cf337c8e95af7b045 (diff)
downloadglibc-4b2e40a9259fab08161e1c607b06a41e15d543dc.zip
glibc-4b2e40a9259fab08161e1c607b06a41e15d543dc.tar.gz
glibc-4b2e40a9259fab08161e1c607b06a41e15d543dc.tar.bz2
Handle out-of-memory case in svc_tcp.c/svc_unix.c:rendezvous_request.
If glibc is build with -O3 on at least 390 (-m31) or x86 (-m32), gcc 11 dumps this warning: svc_tcp.c: In function 'rendezvous_request': svc_tcp.c:274:3: error: 'memcpy' offset [0, 15] is out of the bounds [0, 0] [-Werror=array-bounds] 274 | memcpy (&xprt->xp_raddr, &addr, sizeof (addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors In out-of-memory case, if one of the mallocs in makefd_xprt function returns NULL, a message is dumped, makefd_xprt returns NULL and the subsequent memcpy would copy to NULL. Instead of a segfaulting, we delay a bit (see also __svc_accept_failed and Bug 14889 (CVE-2011-4609) - svc_run() produces high cpu usage when accept() fails with EMFILE (CVE-2011-4609). The same applies to svc_unix.c. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sunrpc/svc.c')
-rw-r--r--sunrpc/svc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/sunrpc/svc.c b/sunrpc/svc.c
index 917e9a3..3ed6cee 100644
--- a/sunrpc/svc.c
+++ b/sunrpc/svc.c
@@ -545,6 +545,13 @@ svc_getreq_common (const int fd)
}
libc_hidden_nolink_sunrpc (svc_getreq_common, GLIBC_2_2)
+void
+__svc_wait_on_error (void)
+{
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 50000000 };
+ __nanosleep (&ts, NULL);
+}
+
/* If there are no file descriptors available, then accept will fail.
We want to delay here so the connection request can be dequeued;
otherwise we can bounce between polling and accepting, never giving the
@@ -555,8 +562,7 @@ __svc_accept_failed (void)
{
if (errno == EMFILE)
{
- struct timespec ts = { .tv_sec = 0, .tv_nsec = 50000000 };
- __nanosleep (&ts, NULL);
+ __svc_wait_on_error ();
}
}