From patchwork Mon Nov 20 21:21:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 119323 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4395808qgn; Mon, 20 Nov 2017 13:28:04 -0800 (PST) X-Google-Smtp-Source: AGs4zManvKVS280a5nTMpkwl+3XgfirF2ZFlcDoWt4dRXeyEPhuOstAkWaliz220t+NTUua2Qhmn X-Received: by 10.37.78.130 with SMTP id c124mr7590155ybb.383.1511213284112; Mon, 20 Nov 2017 13:28:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511213284; cv=none; d=google.com; s=arc-20160816; b=on0EPGWgU6SAY0ruNuGrclNvwPeQjt5KO6GzgrzPuzC+nCXnfF5XPYfENePrXiUOxc g+2Cz4RD+X6utcbyCeCqix9y4U46+358y4wjo5Vwu5U/9ig/FlskehmAu5SKmdIlFdrE aQC6z+xzDqZ2qSvolssiNHQqxJurnblpxssmu1diXZ/Kgmj4/pXMJ1QkJoyNxuOaZv4q MJJ6QVu1UfoFGcLv4RyxwoVxV+J7JsyMS03NSr1EJ69wBkwCRVTBasSkpHtFoIfpuTDZ fQq3Zi+G5yXvyFX/x1bsrn6fNk3vXDRsLKIURI7yvgVkaqMJwcBc5H8GH76Kmm0dpeSG b3Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=uIVpqLT7MT9xmVbQ1a9ljDsAY7KrxgwugJ0GkGCg4hA=; b=CrmCsCXm6asD2jL3wXjOWqL52+cFfRtRVcIn2hn1xVhDvOwSTx8+3GWCADZOoz+nYs 8sewl2HygoM9pKX7mGbU0VtmWnySg69No8a1zX8Tp9aHgKAxLk1QBadLI4g8KVXA+CT7 CllxYEzFbOxtmWVD9+TKwMGyHiSHpAW0+vWTsAm1R0zb1Ov/nCcKDQA3xC1+N8Fq8BT9 cIRTxk8SDvkusz9otW+QHzfTuWxgkPV0U+n9Prd9XxZb78fBhsMGVJebDHCJAtutB7TY U4/aS/0hONPac1IC8iD4tkAckJYR8NAhXf98fJ26wFVCX3+7O6WP4trPoXx5tDoYu9x2 XvzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Z9x2MZzt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s83si2460361ybc.108.2017.11.20.13.28.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Nov 2017 13:28:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Z9x2MZzt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtbn-0001Md-Hy for patch@linaro.org; Mon, 20 Nov 2017 16:28:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtW6-0004xQ-S6 for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:22:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGtW5-00087A-Mf for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:22:10 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGtW5-00086U-El for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:22:09 -0500 Received: by mail-lf0-x242.google.com with SMTP id k66so11727525lfg.3 for ; Mon, 20 Nov 2017 13:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uIVpqLT7MT9xmVbQ1a9ljDsAY7KrxgwugJ0GkGCg4hA=; b=Z9x2MZztQ1rmkOJSEMMr/s22VH7CT3wTYr3ACkvGb04b4RFxS1CPQjLtztEd6Ns704 JABBAc7rLiRT9Ax4KZSoI/YCNYolmIiTZOpIyX84jHqZXfFwr4x89DbQMEnHj2q7AIMH umdXqmcOzh2WGtX4T4UlVrglJhx5LpbkPgAl0= 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:in-reply-to :references; bh=uIVpqLT7MT9xmVbQ1a9ljDsAY7KrxgwugJ0GkGCg4hA=; b=nmIhv6jHjHd+cE9K5uug2nY//deF16r+3nHy+dNbfbxk5HNgbnhgZw8SZefcahPbhG AXBD0MXMuYROZwL/1FM+VB7+1w3NpxcRZ9VCLRBgh4qlySJS3GZiLBzUPck8s92eOTBv K9i6wQIRwcsKmFlZK1Sy9mQMKYz/E+M8cvUPzv/WtFNPvJAUyCN3/AC0ELq3yjw8OyaG XCApRQ6zUvsr38HCrkU5nkjuoGrmSvRYwSaXYCw95Dit8/NsXYYUNKp7yRVL/TF2H9JS 5VPYGnxCoym7F45N6lRuAwgZa+QoY3TkLwwEWAABHSGBJ4dMfpyu4+hFwOcA6hnOGSNp ikmg== X-Gm-Message-State: AJaThX6v92CJODGwA0d8+Hg9erVRYoBvT8EJKknTx0O8USZEFjImCvLi suimSPv+dQz8R5gwmyhOyWgrWvfXggM= X-Received: by 10.46.95.212 with SMTP id x81mr5296782lje.184.1511212927971; Mon, 20 Nov 2017 13:22:07 -0800 (PST) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id v63sm1645409lje.39.2017.11.20.13.22.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 13:22:06 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 20 Nov 2017 23:21:43 +0200 Message-Id: X-Mailer: git-send-email 2.14.2 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::242 Subject: [Qemu-devel] [PULL 15/15] linux-user: Fix calculation of auxv length 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In commit 7c4ee5bcc82e643 we changed the order in which we construct the AUXV, but forgot to adjust the calculation of the length. The result is that we set info->auxv_len to a bogus and negative value, and then later on the code in open_self_auxv() gets confused and ends up presenting the guest with an empty file. Since we now have to calculate the auxv length up-front as part of figuring out how much we're going to put on the stack, set info->auxv_len then; this allows us to assert that we put the same number of entries into auxv as we pre-calculated, rather than merely having a comment saying we need to do that. Fixes: https://bugs.launchpad.net/qemu/+bug/1728116 Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/elfload.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.14.2 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 3b857fbc9c..20f3d8c2c3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1732,6 +1732,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, #ifdef ELF_HWCAP2 size += 2; #endif + info->auxv_len = size * n; + size += envc + argc + 2; size += 1; /* argc itself */ size *= n; @@ -1760,7 +1762,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, put_user_ual(val, u_auxv); u_auxv += n; \ } while(0) - /* There must be exactly DLINFO_ITEMS entries here. */ #ifdef ARCH_DLINFO /* * ARCH_DLINFO must come first so platform specific code can enforce @@ -1768,6 +1769,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, */ ARCH_DLINFO; #endif + /* There must be exactly DLINFO_ITEMS entries here, or the assert + * on info->auxv_len will trigger. + */ NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff)); NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr))); NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); @@ -1793,7 +1797,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, NEW_AUX_ENT (AT_NULL, 0); #undef NEW_AUX_ENT - info->auxv_len = u_argv - info->saved_auxv; + /* Check that our initial calculation of the auxv length matches how much + * we actually put into it. + */ + assert(info->auxv_len == u_auxv - info->saved_auxv); put_user_ual(argc, u_argc);