From patchwork Wed Sep 5 16:18:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10589187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 965B613BB for ; Wed, 5 Sep 2018 16:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 752EE29773 for ; Wed, 5 Sep 2018 16:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69863297DD; Wed, 5 Sep 2018 16:24:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 162FD29773 for ; Wed, 5 Sep 2018 16:24:43 +0000 (UTC) Received: from localhost ([::1]:57067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxabj-0006RD-27 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Sep 2018 12:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxaao-0005uV-48 for qemu-devel@nongnu.org; Wed, 05 Sep 2018 12:23:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxaW7-0002aD-Hp for qemu-devel@nongnu.org; Wed, 05 Sep 2018 12:18:56 -0400 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:39832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxaW7-0002Zl-91 for qemu-devel@nongnu.org; Wed, 05 Sep 2018 12:18:55 -0400 Received: by mail-lj1-x242.google.com with SMTP id l15-v6so6744388lji.6 for ; Wed, 05 Sep 2018 09:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SM2oxf7oFnLjKEZNDXlftjBCaGHfiB316fac839mfNM=; b=GqYJc+c8OrnzdGztxYOijQkzQ9jBVe6D3Kr28bnmnAmwo/ZEh2IhzQv5MrLhLoRVCf FIk6rpR5mVIf5afGIhyf3hb5i1sX0pZxfuYIFaLPj/+E7UHEjRUzaYozlhxYtewASdVb y0+QT5RQ7DiuEop7ZsHImzXvg9QfIn6SzSevv9wfC4PNeGfsrpJivgec/yn84LycIAbz 1WvW+0iz6PonTo/07F0TcUnky4N/kIOxv2/mWQnIHj11AY5QOddQjMh3WQ+7n8h5AcpM fv5m/0KgaVxi92YBXXIRG5uNxUfweNYsDZyi6+BB+FGgKQvD/oCpbeMPDTShXot8Xu6N KNQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SM2oxf7oFnLjKEZNDXlftjBCaGHfiB316fac839mfNM=; b=oPpEPYxoXNurmfzUNZMdcVkUjdlVVk5EQ7e6s730EpSlHOhyrtzhIjbtz2qZIqCQWN srgvL7JRV1GcKrozFwRACfG9sdwRq0MsrKOBCEmdGX7CW8mc8It1bbFZROfUCQUIV6Aq Wtg5x47b+KgDt/IQT0dsaWgRUgNyxt5hq83R+5wWZ9lsfJ+Tp4lvbLPSB3ANjluz8eln ajJhVivMYzYhJKycjDM7mBD0VVQhi/VXE1FE/Q9kJBhJqCLvr3+Qn7A+dZZoBs1nBS1R eZg5KIMYezgQh5tiCDlniAWuWGuKGblIyaH5GRzdFkeHkrCTgGeYWS1Km0mVhoVary+J tHmA== X-Gm-Message-State: APzg51AJD38Dlra7dmOPsYfQp1Qcld+DWHlQOomiwVpZOKWBhuMVCh43 plaSzAyMsa4hkniMAO74/eqibxhd3nE= X-Google-Smtp-Source: ANB0Vdb7F9/mQjk+q8nSkFYsYnmslpd833oMOeLsoEremvyw1j++SFVogSVu5OdGwzxHMMI9jm/SDQ== X-Received: by 2002:a2e:7014:: with SMTP id l20-v6mr24965849ljc.141.1536164333815; Wed, 05 Sep 2018 09:18:53 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id l141-v6sm385071lfg.55.2018.09.05.09.18.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 09:18:53 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 5 Sep 2018 09:18:41 -0700 Message-Id: <20180905161841.10904-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::242 Subject: [Qemu-devel] [PATCH v2] linux-user: do setrlimit selectively X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Laurent Vivier , Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Max Filippov Reviewed-by: Peter Maydell --- Changes v1->v2: - don't limit change to 32-bit guest on 64-bit host case linux-user/syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bb42a225eb58..a9cace49dad8 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9275,7 +9275,13 @@ abi_long do_syscall(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); - ret = get_errno(setrlimit(resource, &rlim)); + if (resource != RLIMIT_AS && + resource != RLIMIT_DATA && + resource != RLIMIT_STACK) { + return get_errno(setrlimit(resource, &rlim)); + } else { + return 0; + } } break; #endif