From nobody Wed Feb 11 04:36:44 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511213393664104.99810767480233; Mon, 20 Nov 2017 13:29:53 -0800 (PST) Received: from localhost ([::1]:59831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtdC-0002UP-7f for importer@patchew.org; Mon, 20 Nov 2017 16:29:30 -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) 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) 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-Google-Smtp-Source: AGs4zMYG6hOakAsqanR98Tqibb2bvjYOKCL2B/jXdFYLcqMLbZPzyzTlylJOmUYjUryGlQTXYKnf7w== X-Received: by 10.46.95.212 with SMTP id x81mr5296782lje.184.1511212927971; Mon, 20 Nov 2017 13:22:07 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 a= rgc, int envc, #ifdef ELF_HWCAP2 size +=3D 2; #endif + info->auxv_len =3D size * n; + size +=3D envc + argc + 2; size +=3D 1; /* argc itself */ size *=3D n; @@ -1760,7 +1762,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int a= rgc, int envc, put_user_ual(val, u_auxv); u_auxv +=3D n; \ } while(0) =20 - /* 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 a= rgc, 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 =20 - info->auxv_len =3D u_argv - info->saved_auxv; + /* Check that our initial calculation of the auxv length matches how m= uch + * we actually put into it. + */ + assert(info->auxv_len =3D=3D u_auxv - info->saved_auxv); =20 put_user_ual(argc, u_argc); =20 --=20 2.14.2