]> Git Repo - qemu.git/commitdiff
linux-user: do setrlimit selectively
authorMax Filippov <[email protected]>
Mon, 17 Sep 2018 18:13:14 +0000 (11:13 -0700)
committerLaurent Vivier <[email protected]>
Tue, 25 Sep 2018 20:36:49 +0000 (22:36 +0200)
setrlimit guest calls that affect memory resources
(RLIMIT_{AS,DATA,STACK}) may interfere with QEMU internal memory
management. They may result in QEMU lockup because mprotect call in
page_unprotect would fail with ENOMEM error code, causing infinite loop
of SIGSEGV. E.g. it happens when running libstdc++ testsuite for xtensa
target on x86_64 host.

Don't call host setrlimit for memory-related resources.

Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Max Filippov <[email protected]>
Message-Id: <20180917181314[email protected]>
[lv: rebase on master]
Signed-off-by: Laurent Vivier <[email protected]>
linux-user/syscall.c

index 019af632dfa618434532156979a04966c3b6b88c..ae3c0dfef75d1df96f5cec86b88555b071f8b0c2 100644 (file)
@@ -7879,7 +7879,21 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
             rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
             unlock_user_struct(target_rlim, arg2, 0);
-            return get_errno(setrlimit(resource, &rlim));
+            /*
+             * If we just passed through resource limit settings for memory then
+             * they would also apply to QEMU's own allocations, and QEMU will
+             * crash or hang or die if its allocations fail. Ideally we would
+             * track the guest allocations in QEMU and apply the limits ourselves.
+             * For now, just tell the guest the call succeeded but don't actually
+             * limit anything.
+             */
+            if (resource != RLIMIT_AS &&
+                resource != RLIMIT_DATA &&
+                resource != RLIMIT_STACK) {
+                return get_errno(setrlimit(resource, &rlim));
+            } else {
+                return 0;
+            }
         }
 #endif
 #ifdef TARGET_NR_getrlimit
This page took 0.037715 seconds and 4 git commands to generate.