From nobody Wed Jan 15 08:40:33 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676315; cv=none; d=zohomail.com; s=zohoarc; b=hJtVYQCx8x7WAHnkGuaHvqt+uzVtlDHiOBQlxlwc1ZyfovkeJG6fTNoqoiMj2NRsDp5qpiKMWoknS6xc7Mck6l2hLPkdNEJ9ka2+HVQngGz5YW+gIjSd5E80h/IYgUmwvqHej+1WkZaJ/HdRTo5QYvYKVSmCZuQA5P/srsiQ+ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676315; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=KYhfHNn//10KIR5L4tIJgRMzKL8TABQoExSxCWZe2WWAUcf98wj8o2D4uW7UzaAkZnW8Fi4pqkwri563FBFX0tsOuoL6uYHI4UjY0LBf2JZObJsUpJvI5mD8sCOjrvuCsMqtX1rO7bOgbcdBLwiKD1xJVj8XZBnNMCma/cXwx5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676315883329.5017810366036; Fri, 2 Oct 2020 15:05:15 -0700 (PDT) Received: from localhost ([::1]:38232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTAw-0000E8-Iz for importer@patchew.org; Fri, 02 Oct 2020 18:05:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT63-0002hk-6x for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:11 -0400 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]:41305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT60-0007PM-GE for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:10 -0400 Received: by mail-oi1-x242.google.com with SMTP id x69so2722590oia.8 for ; Fri, 02 Oct 2020 15:00:08 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00:06 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=JCe9wMsrZyC3phlm+nCPDYtTM2wgzzXqQeVhag4Fj3984KbhMy/YCPnTQjD5V683ek 80XUY8dr7UseqrBnHBh6eWTf2s/VIHtLkOqqLbF5zXwRbRMPZt0mBlRxO7efMVcAQzi6 BT6QjzAwGnJZ5BMr6zybhOFVpOJ5Q3JyM3ngN6Hb4FToUgKzO0ToJGOrnSow9pQ1qIBV u2MS0ZOQWRJK6mka+A/Gn2JTVkxEyq5C7OgpYg5ydfHRrUkpB/kkRV0zIyF+NsYt12G/ d5tMHQSvmeahqTNqfssPePXXKTVOgvZ+AMvDNA8R0j/3/ATySk3IYWEn4DIUFao9GG9x IRww== 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:mime-version:content-transfer-encoding; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=rlaeZZc912kXKWkaNcx4bfysLCDeEDhfeQ7XD5sELaHFxSEcVApx5BN+b/PujcqoMs EaYsZCpSfknpAijn4bOjzt2GNeKlHo4JmalHPEZx6a4jQ4nfGBAgIg0g6m0GyjdAB0cn GmvbNwb+/KIduSOeh15v0uCvMMgNPeGgyXvflplyhMje4wGQjCfUrGPJoLfByFEjPFNA MymDB2nkzihkTntL5Brd1WuANU6YE0uIAPc5j+lcasxTslwlOKK4rrpofC00BJL5FpKm pJ9SjbyVeyf+GzqWMu5IEEwYe5cPyxb8Q1iV3cBsVT+Ez9oRxadcYVzecYBVvrxscrPN jM0A== X-Gm-Message-State: AOAM532KTBpUUL/aGZMczJ3PNo89XbjXNW7AeJ+Kd+c+n5XnKQbg5VwO ioJaZ1ZMfIqbxt9Rm74piVddNJN8jstnt9YW X-Google-Smtp-Source: ABdhPJwGR+b4eiNsToawk3uOhGkWc/zWtEQm5DkyAXxEm9dRSKNuhaVjnQOtySeTyCt2zBPWkufzFg== X-Received: by 2002:a54:4d88:: with SMTP id y8mr2501987oix.97.1601676006853; Fri, 02 Oct 2020 15:00:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Date: Fri, 2 Oct 2020 16:59:53 -0500 Message-Id: <20201002215955.254866-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::242; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x242.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For BTI, we need to know if the executable is static or dynamic, which means looking for PT_INTERP earlier. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 735ebfa190..6b422990ff 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2421,8 +2421,10 @@ static void load_elf_image(const char *image_name, i= nt image_fd, =20 mmap_lock(); =20 - /* Find the maximum size of the image and allocate an appropriate - amount of memory to handle that. */ + /* + * Find the maximum size of the image and allocate an appropriate + * amount of memory to handle that. Locate the interpreter, if any. + */ loaddr =3D -1, hiaddr =3D 0; info->alignment =3D 0; for (i =3D 0; i < ehdr->e_phnum; ++i) { @@ -2438,6 +2440,33 @@ static void load_elf_image(const char *image_name, i= nt image_fd, } ++info->nsegs; info->alignment |=3D eppnt->p_align; + } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { + char *interp_name; + + if (*pinterp_name) { + errmsg =3D "Multiple PT_INTERP entries"; + goto exit_errmsg; + } + interp_name =3D malloc(eppnt->p_filesz); + if (!interp_name) { + goto exit_perror; + } + + if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { + memcpy(interp_name, bprm_buf + eppnt->p_offset, + eppnt->p_filesz); + } else { + retval =3D pread(image_fd, interp_name, eppnt->p_filesz, + eppnt->p_offset); + if (retval !=3D eppnt->p_filesz) { + goto exit_perror; + } + } + if (interp_name[eppnt->p_filesz - 1] !=3D 0) { + errmsg =3D "Invalid PT_INTERP entry"; + goto exit_errmsg; + } + *pinterp_name =3D interp_name; } } =20 @@ -2590,33 +2619,6 @@ static void load_elf_image(const char *image_name, i= nt image_fd, if (vaddr_em > info->brk) { info->brk =3D vaddr_em; } - } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { - char *interp_name; - - if (*pinterp_name) { - errmsg =3D "Multiple PT_INTERP entries"; - goto exit_errmsg; - } - interp_name =3D malloc(eppnt->p_filesz); - if (!interp_name) { - goto exit_perror; - } - - if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval =3D pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval !=3D eppnt->p_filesz) { - goto exit_perror; - } - } - if (interp_name[eppnt->p_filesz - 1] !=3D 0) { - errmsg =3D "Invalid PT_INTERP entry"; - goto exit_errmsg; - } - *pinterp_name =3D interp_name; #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; --=20 2.25.1