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: 10067331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 959696038F for ; Mon, 20 Nov 2017 21:29:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 888A028BF2 for ; Mon, 20 Nov 2017 21:29:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D7AF290C5; Mon, 20 Nov 2017 21:29:01 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 0107F28BF2 for ; Mon, 20 Nov 2017 21:29:01 +0000 (UTC) Received: from localhost ([::1]:59827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtci-0001Md-5E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Nov 2017 16:29:00 -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-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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 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);