From patchwork Tue Sep 4 21:00:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10587891 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 A06325A4 for ; Tue, 4 Sep 2018 21:01:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 905882A0FB for ; Tue, 4 Sep 2018 21:01:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 840AC2A17C; Tue, 4 Sep 2018 21:01:31 +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 2FE1D2A172 for ; Tue, 4 Sep 2018 21:01:31 +0000 (UTC) Received: from localhost ([::1]:52627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxIS2-0008WT-Ha for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Sep 2018 17:01:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxIRO-0008Ac-NX for qemu-devel@nongnu.org; Tue, 04 Sep 2018 17:00:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxIRN-0001MB-UH for qemu-devel@nongnu.org; Tue, 04 Sep 2018 17:00:50 -0400 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]:38652) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxIRN-0001Kc-Gx for qemu-devel@nongnu.org; Tue, 04 Sep 2018 17:00:49 -0400 Received: by mail-lf1-x143.google.com with SMTP id i7-v6so4158681lfh.5 for ; Tue, 04 Sep 2018 14:00:49 -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=gaW21bM0vIYRS0Wq/VvDo8SRV2VjOx6vzvcefIq4Y74=; b=jpb69YEENfnGJOud48m5LdLXjfzeaoYKCyMe7GSLuViBpdyI9TYTSGIex6I97WkxUO 2ZQGNv0FzY5tcdbx9lW00RCKL/xBjcCqi+3olqVGL2EXysp2J8U4K2BW7fyXIWD4si/s bNHxo6Df0tFtVCJ0FK2QLYfr/oU9J7MZJZ/FNHJmXndsThNzYifwq1cRtkqFIv+fHxvf xvoW5IvGeXyLM/lIJlrQ4i3H9l1yfbmZs+Jlkm5j0MuuAnAqQUPdSphFJ3zdl2XV69Yq P7PUIvyjBT7vpw8bpHw+HPCjtArKAcS+uqPXXotqJQzUHYp3e7otNC762BVGyxULzm7U 6rPw== 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=gaW21bM0vIYRS0Wq/VvDo8SRV2VjOx6vzvcefIq4Y74=; b=rEhp/8yXAbgZ8V8aEdvCrg1sr18JohIxQGGofgkDTdI+zI14Um7qLpjr4NW0bdBZhk DJkasFphdzlfxtFdvbgMj2duqm7w4+NgcWKW+B84WrAwFduVRwzv9VIvMD5zSUEdu6se lI+cWdU1IVH+wrPZY/daU6kmHGqEl+2nuTQwcpFZRZO9ssZh2NAkYHKR4CghzhrWGW3d wq5UZ+Ljl/5CrOCLCzJLeL8x6JmZafaS7fnEijXhd/YHwPexlb/UtjYsyPttbli0Kky8 t8v4+BPgHSW5n40o7j1wa8DP1xcEHIC9Ehq5nnUokj7rEFLZRZm24dEd10rrMeE4zzcX /2hw== X-Gm-Message-State: APzg51DS87M0CJ/grDpcKseGGLhWN7C2l3cNxN1g2UPes9KmtdEgbMh2 h5qMbbyMEUrqNSE/X+Z7HR+OWfAFtWc= X-Google-Smtp-Source: ANB0VdZeOf36l57GHLcuuqb28QV9iKHsUlW6HDgnnGVSMyNsBpTLK4CYPfj2Wfa/wGIXlVU3uhqIrg== X-Received: by 2002:a19:1761:: with SMTP id n94-v6mr21206312lfi.64.1536094847701; Tue, 04 Sep 2018 14:00:47 -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 f9-v6sm4122043ljf.9.2018.09.04.14.00.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 14:00:46 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 14:00:36 -0700 Message-Id: <20180904210036.7317-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::143 Subject: [Qemu-devel] [PATCH] 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 When running 32-bit guest on 64-bit host setrlimit guest calls that affect memory resources (RLIMIT_{AS,DATA,STACK}) don't always make sense as is. 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 when running 32-bit guest on 64-bit host. Signed-off-by: Max Filippov --- linux-user/syscall.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 850b72a0c760..693a6c8aa7bb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9272,7 +9272,14 @@ 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 (HOST_LONG_BITS <= TARGET_LONG_BITS || + (resource != RLIMIT_DATA && + resource != RLIMIT_AS && + resource != RLIMIT_STACK)) { + return get_errno(setrlimit(resource, &rlim)); + } else { + return 0; + } } #endif #ifdef TARGET_NR_getrlimit