From patchwork Mon Sep 17 18:13:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10603289 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 25B2F14DA for ; Mon, 17 Sep 2018 18:27:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EB2E2A200 for ; Mon, 17 Sep 2018 18:27:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 028A22A254; Mon, 17 Sep 2018 18:27:15 +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 9352A2A200 for ; Mon, 17 Sep 2018 18:27:15 +0000 (UTC) Received: from localhost ([::1]:36952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1yEs-00049C-5h for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Sep 2018 14:27:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1yDq-00033C-VR for qemu-devel@nongnu.org; Mon, 17 Sep 2018 14:26:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1y1b-0008F9-R3 for qemu-devel@nongnu.org; Mon, 17 Sep 2018 14:13:32 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:46405) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1y1b-0008CU-J5 for qemu-devel@nongnu.org; Mon, 17 Sep 2018 14:13:31 -0400 Received: by mail-lj1-x22d.google.com with SMTP id 203-v6so14040387ljj.13 for ; Mon, 17 Sep 2018 11:13:31 -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=6GiSD2/z0GphCOF0obbPVK5w9Ju+zJojz+Sn/VunbFY=; b=dNH5Ht52fEw0yZCQEHVmDQll3APCHyMUOMcY2iC5kXPcUTnKdsSI/1BfodiGwtTRSw pSiIT5rN0tQug5W/z7DDutffvPao1/lwzzOVyUKz4kDGpPnRppsoVHqV9/OrUjyftQwL Bk+AM92/dqst5mw7D27dmsF+OuQ6rY66MXl5IT2gScvX49fgAa7CyyKYaMUYxriWx0hr WXKf+DWTLAm67AQagH0NAx7iwzRkVkrWdYzYvypej9Xp3jxn+hKrVQusWmX/lpDHLMI+ X82x/WR5T9CCgW72GjyFckZ1nFLzRoYgzMh8tajpPAz5o2blnZ9vj2F8Zj9dHurYsJd/ qO+w== 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=6GiSD2/z0GphCOF0obbPVK5w9Ju+zJojz+Sn/VunbFY=; b=S6dW95z8pDRVEbWbKmedQTGFh5VD+5JkrE7JLTYDuhnCyjH97bRx8oLtAHPlZaj45P B0NFISCR6uRT6tYBIlxuX6SQAJZz1addo0dB2Nhn1k3peQE6e780vxUaoz4f3QnmEKFe aG93nCIZHL6znMAUWYN3yrjVpUTdKGSyXbgXhz4v6GawazYdjyZdHy5UUT7fCn6oJuO5 3soqG3omcb0qhEKRwKpTC1Jjnk3SGLpt/RE9FUOgZ0pcbByl7j1TyAV4gXGNGdibw1s0 VRqsQIEP5UaJhstM6h+CZAJK53V85m8nUkW8schV6d8KJ1fqiZcu3YryZBMP+jtOCsza ZgSw== X-Gm-Message-State: APzg51DDblD2Ka80i7XWUGrnd5PfaPeUSe15LEvejQ+u8VgHlHs5HWy4 jT1n8RBcYAg7z6TPAqm0tP51D/H+ZmM= X-Google-Smtp-Source: ANB0VdZKCRcn+EFFSlGHdbaSwMjSxVdw7Z82NVOclGUs1Bvbmo49/aUdzuiY1mrWm0mFCu42qbGWDQ== X-Received: by 2002:a2e:92c4:: with SMTP id k4-v6mr16656686ljh.18.1537208010016; Mon, 17 Sep 2018 11:13:30 -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 135-v6sm2948930ljj.35.2018.09.17.11.13.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 11:13:29 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 17 Sep 2018 11:13:14 -0700 Message-Id: <20180917181314.22551-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::22d Subject: [Qemu-devel] [PATCH v3] 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 , 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. Reviewed-by: Peter Maydell Signed-off-by: Max Filippov --- Changes v2->v3: - add comment sugessted by Peter Changes v1->v2: - don't limit change to 32-bit guest on 64-bit host case linux-user/syscall.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bb42a225eb58..f06307ebd945 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9275,7 +9275,21 @@ 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 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; + } } break; #endif