From nobody Fri Apr 17 00:21:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1603303223; cv=none; d=zohomail.com; s=zohoarc; b=TSN7CUbv1WY3dGEgwsX96m+6SUxVR/UpOF0bmoUQzJLmPS573hRxWfKKRS/yB2kO/wi2rNGHhVr4r8WpxX1BruaqfAraNccXK0MspXU830BsAOtMeDYn11J2EHtg5CyAHBXgWEsuxnF3hqZrX4RbM0SgGuxnxU7mgzKtRwXRsfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603303223; 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=kGZNmudBhXIU/a8gp/KXcyIKcPKoqtSco3EGBov+V2s=; b=MXyum13c1ZkBx3+XLyBi2pVvpA3cWhktHDnBsCOd6KTOsctnOeeY9n56eoZ7sd0zSb8FWBVlwCXyZWP2fIh/vSAGq8Hj8QSyY3L2M62ZwtNMmWoE9/yroQK50HzYfz6GoDJiaCagyPEsiit2DC0udKzNJsRX6+efrO7w1PgNeOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1603303223081673.23922225599; Wed, 21 Oct 2020 11:00:23 -0700 (PDT) Received: from localhost ([::1]:37910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIPL-0006EC-5Q for importer@patchew.org; Wed, 21 Oct 2020 14:00:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3x-0006g6-Hq for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:13 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:34891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006Uf-6C for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:13 -0400 Received: by mail-pl1-x643.google.com with SMTP id 1so1583264ple.2 for ; Wed, 21 Oct 2020 10:38:09 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38:07 -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=kGZNmudBhXIU/a8gp/KXcyIKcPKoqtSco3EGBov+V2s=; b=NoUbKxpW3VhC+PWgLSxnCQTeahhzhagmdmde0QQeat3O5qHiw6hSLW8n1O57vyK1EY oIxiBKpVz82L/3ku+RrZGf5DKOx59IaBIMd3UwUYmg4c6HpN+XDY10L7/auGic1RQU8z S4rclsYwA4p52fjPeQViETn8Vqw6YC768SETF/n97JHCaj4vNvdW6YGmAnQDPiHNOc3m PJPCXmhPUUot51A7EX8FJERHhdQrn0pMiLrlFoK7IiSl+glUw0hFHCAJPAtkcqDMUmWD pKWLm3xz+FQgjFiOtaQTad6IivEnXY+++hK2mgAIGQ4hu00kjjKiFtBLyOgvGxL6HOcn KKyQ== 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=kGZNmudBhXIU/a8gp/KXcyIKcPKoqtSco3EGBov+V2s=; b=DcKDa1fmnxat+c56tzWX1kxSpnWzKAwAwAoaNdjgYbv1CgtI9FTdiz2O9IbLzRz+HA GFNP/ZNQfDJ4Yh6GskfRVk96jvcXXxwRHuUuUZpjtFxX8JuBoFVfmgEOQ1nddTWwtC70 SXwDxhibJJfxmucNbsHozt7NQL/u+87Ikay1W7kZIXErgOhHiiivoZqAnONgbPM7pWHK vp5WvFnY5C7X7g7pRtyELVyGgvDY1riUFMl07D0DGZu7pYE5qWe8xyd0bWEyvsgkqL+U XE1a8tRqhGdi+m6ryhlX9V5CNGDUXxuC904bFXpSOuI74pzPSjnHMr9MfygIBumnpcsX NWkw== X-Gm-Message-State: AOAM5330MZaJvtf2/Xcmek0qlnEApDJKHnKlATCvkUJzRsbiSprJIv2C tYbATQoCtg3e46GhkKK18ARdnLV7hjeFPA== X-Google-Smtp-Source: ABdhPJzoafBy+ad2vMGdAlW4743GlbVD10bCPorz0DA+Z9ptQl0Iz1KU4tY6N+hf6F06uaLcL5F2Gg== X-Received: by 2002:a17:90a:cb86:: with SMTP id a6mr4215936pju.161.1603301888152; Wed, 21 Oct 2020 10:38:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 11/12] linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND Date: Wed, 21 Oct 2020 10:37:48 -0700 Message-Id: <20201021173749.111103-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201021173749.111103-1-richard.henderson@linaro.org> References: <20201021173749.111103-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::643; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x643.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=ham 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Use the new generic support for NT_GNU_PROPERTY_TYPE_0. Signed-off-by: Richard Henderson --- v11: Split out aarch64 bits from generic patch. --- linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 428dcaa152..bf8c1bd253 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1522,6 +1522,28 @@ static void elf_core_copy_regs(target_elf_gregset_t = *regs, =20 #include "elf.h" =20 +/* We must delay the following stanzas until after "elf.h". */ +#if defined(TARGET_AARCH64) + +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, + const uint32_t *data, + struct image_info *info, + Error **errp) +{ + if (pr_type =3D=3D GNU_PROPERTY_AARCH64_FEATURE_1_AND) { + if (pr_datasz !=3D sizeof(uint32_t)) { + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AN= D"); + return false; + } + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ + info->note_flags =3D *data; + } + return true; +} +#define ARCH_USE_GNU_PROPERTY 1 + +#else + static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, const uint32_t *data, struct image_info *info, @@ -1531,6 +1553,8 @@ static bool arch_parse_elf_property(uint32_t pr_type,= uint32_t pr_datasz, } #define ARCH_USE_GNU_PROPERTY 0 =20 +#endif + struct exec { unsigned int a_info; /* Use macros N_MAGIC, etc for access */ @@ -2545,7 +2569,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, struct elfhdr *ehdr =3D (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval; + int i, retval, prot_exec; Error *err =3D NULL; =20 /* First of all, some simple consistency checks */ @@ -2712,6 +2736,26 @@ static void load_elf_image(const char *image_name, i= nt image_fd, info->brk =3D 0; info->elf_flags =3D ehdr->e_flags; =20 + prot_exec =3D PROT_EXEC; +#ifdef TARGET_AARCH64 + /* + * If the BTI feature is present, this indicates that the executable + * pages of the startup binary should be mapped with PROT_BTI, so that + * branch targets are enforced. + * + * The startup binary is either the interpreter or the static executab= le. + * The interpreter is responsible for all pages of a dynamic executabl= e. + * + * Elf notes are backward compatible to older cpus. + * Do not enable BTI unless it is supported. + */ + if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) + && (pinterp_name =3D=3D NULL || *pinterp_name =3D=3D 0) + && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) { + prot_exec |=3D TARGET_PROT_BTI; + } +#endif + for (i =3D 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt =3D phdr + i; if (eppnt->p_type =3D=3D PT_LOAD) { @@ -2725,7 +2769,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, elf_prot |=3D PROT_WRITE; } if (eppnt->p_flags & PF_X) { - elf_prot |=3D PROT_EXEC; + elf_prot |=3D prot_exec; } =20 vaddr =3D load_bias + eppnt->p_vaddr; --=20 2.25.1