From nobody Wed May 15 05:50:09 2024 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=1603302902; cv=none; d=zohomail.com; s=zohoarc; b=HzT9RW6X0RT5KwO3kzqIYb7FO3pGMC5TCVpctljSA1HqfvyD+NbZTHdg+33nl9iTXUjBg5k2tSfS/D7dKSC7nwr2+/jmbpY3j7GkyaSMA+zpmDQhNJxVPrh6gDYO3+Iz93mn16OE6ut4Dqqbg/RfKzBBPrWAesvdM7/6keijMU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302902; 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=zVLgn+OX/nTD/oUAFauTpXTtA86xiUG6+rSs26rONZM=; b=Y8FcHHNUPquJxO7XgXCxQXJXViPVx2RkV62qmjDmbXlYmCrRhcschhPUzaf7fVO+z5wjxrRYQFddGVVGrlY3MNjFlHZRnAQPww+eEe6S0BbsTCmCHDCDu6DHu3ZzhYNq+j1X4B7UmmlbsyL/lw5MXDkFIhUmMna119IhQXen7QQ= 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 1603302902883559.5736017664174; Wed, 21 Oct 2020 10:55:02 -0700 (PDT) Received: from localhost ([::1]:48946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIKD-0007Gk-KP for importer@patchew.org; Wed, 21 Oct 2020 13:55:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3v-0006ZO-7l for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:11 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:36929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3j-0006Ry-2O for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: by mail-pf1-x444.google.com with SMTP id 144so1896690pfb.4 for ; Wed, 21 Oct 2020 10:37:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:52 -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=zVLgn+OX/nTD/oUAFauTpXTtA86xiUG6+rSs26rONZM=; b=U9kPexY1nq/Hm4lw3Fdn7NfTqK8WOKYh2ekN9hMlZ7HWdAVNSVnYRQV4eoFcIHqxiD 99qOzJrBn/7FAKZ/M9ioZn9YHz6yEBxJtPb9p8XeBk1dUhsEQOmB7k2lIUciDKQOPNsN 4id0kXPWtHQVkBXmgQIMXQ6tWXmsmBJ/1m+79VSCmRTlyQvtW15dTMe+73bIwpYpl0ja onTzwNsd1SDtYt6v/9wODD+EwFKGbolBH3cQtYMRPc+iUxXDPKZi5FpG35smlttpc+xM GN0qpi2EoBpC1Qikn/14VEDZsnQMisSTHYoXYlCdwmmfP8Q3K010kVYbGwdC3OkK1axw MmRQ== 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=zVLgn+OX/nTD/oUAFauTpXTtA86xiUG6+rSs26rONZM=; b=Vuun4ag1GQ+hAT+qB37i/pwh8l95rQRn5vWadnSagic4Q6TS9H3FM6zufBndE1Sg/j P/V4CSh8XE1pRUpEOkvZ08ibz8rdHtjYXu+qB/x2GTn+Q2j5T4+6Mun3q2HGFovrq/fi jk+TsY/Dx/lH7Y40UUQ9lMQfEDile273G8GBzyBPWu8GwZYvZVrCubVvUPf/ufyodgJL uMNl2E6fWIDLErCDRScnW221ENPhGbCHPXCu90MUghm9oFh74nJajMonSlFk7iWLkdbm 2USlE0E3MQNuBV7nUu4dQZXpiNaiZ8K/HByRxv5PfKnxMtycJUm4mP0Y3/MC7LnH87hL 03yQ== X-Gm-Message-State: AOAM531SThGOAPchhKf+X5oO75j17i4yvSOksR2cPiX1GMlviZrEzOwC bLa5Kvt4vzQOpLjAvsj0kBRxJ6UON/gmRQ== X-Google-Smtp-Source: ABdhPJwCYAERfmWmBaVj8bAcgnZiCEfoD7CoC1O2GHqSRO05H2Q/DzUDKZ2G648fH6l2BVURIT6sjQ== X-Received: by 2002:a63:160b:: with SMTP id w11mr4365669pgl.110.1603301872971; Wed, 21 Oct 2020 10:37:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 01/12] linux-user/aarch64: Reset btype for signals Date: Wed, 21 Oct 2020 10:37:38 -0700 Message-Id: <20201021173749.111103-2-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::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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" The kernel sets btype for the signal handler as if for a call. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/signal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index d50c1ae583..b591790c22 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -506,10 +506,16 @@ static void target_setup_frame(int usig, struct targe= t_sigaction *ka, + offsetof(struct target_rt_frame_record, tramp); } env->xregs[0] =3D usig; - env->xregs[31] =3D frame_addr; env->xregs[29] =3D frame_addr + fr_ofs; - env->pc =3D ka->_sa_handler; env->xregs[30] =3D return_addr; + env->xregs[31] =3D frame_addr; + env->pc =3D ka->_sa_handler; + + /* Invoke the signal handler as if by indirect call. */ + if (cpu_isar_feature(aa64_bti, env_archcpu(env))) { + env->btype =3D 2; + } + if (info) { tswap_siginfo(&frame->info, info); env->xregs[1] =3D frame_addr + offsetof(struct target_rt_sigframe,= info); --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302392; cv=none; d=zohomail.com; s=zohoarc; b=niUgTed6UrtLo0K3PgZdDSd52vGbkQXLUyzLnerCmfVlAZtDhfMNHy02kvBzCbHPe5aXVyUMJCIwHKqrZz+md01/3BV+FN+UFbBYZPnsXNzacMU3Z45hg9t066LWZe3DLMtKsIdoUZyMBodZEPIxIHywv3yQIcICXJ18OZj6tOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302392; 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=sWSDVti4WQsQ83LDBJmh30WxQyxLm/+WzGhuvboKIIc=; b=ER+sroTuNV7b1uFU7uLP20gJp1UQ1a475TkdUn83K1M+ojO/z7BISuGx0n8hTKjAqkOz/exidetjkzvcHq1ymaCsC5OnAWdQah42nA0apgq3U7z+e+vjZ1CmrRsyTZale3rhSWaPJU9QaOUIIy1rNQGRIDCJqcY2lhNP+FvJ8nw= 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 1603302392190381.42791757820396; Wed, 21 Oct 2020 10:46:32 -0700 (PDT) Received: from localhost ([::1]:52672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIBz-0005Tn-2P for importer@patchew.org; Wed, 21 Oct 2020 13:46:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3n-0006VF-Kl for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:46875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3j-0006S9-25 for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:03 -0400 Received: by mail-pg1-x541.google.com with SMTP id n16so1867217pgv.13 for ; Wed, 21 Oct 2020 10:37:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:53 -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=sWSDVti4WQsQ83LDBJmh30WxQyxLm/+WzGhuvboKIIc=; b=ZjszGXpNFNzbFKUOQ/LOH2B3z/Ag3KvkxSYvzo01c5isyUVY7hNy5lDZ64X0nkFfmt ww9FmLsnX1XCXTnwvfvZBY011ilU9UNEAE8UNIo3c/97EEd8KfblKvpd4w/dGac1MsLg odoywAGPEmw14P8ebKHnNH6oiL5NFt3EChbkycnkAeLzho85owjXyZJjlWCIUhly5arm jxUbzcsfL15n5O/XW0uvJYS+ZzbpcVH/25UPG958Ph1Nfl52kUR9EM5OjgKGdVkgxHnU 0wbAI2nX9OWLp7kG6s5xvMo2U0TUx0S5d9ZB5p3OpVThgpI8RDh5jZYjLirgc/Cyxlbu sQvw== 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=sWSDVti4WQsQ83LDBJmh30WxQyxLm/+WzGhuvboKIIc=; b=MDlSVL77FFxGVG2WXHqauMF3HP5feTihr1hPe2Pz721egyKK9//Z26d9Jtq0UDjGtK sRjCYbB3EInSTS4EPkwRHPxzApVbb4oakGuhD+VY4doMpyOOEO+gXBC04qsP/zkbUfhJ VdULt0N8GJAljQ1aM7V1TURqblla0X95AUddnfRR/7gsX9Yg2uKBwyRfqWdo2cD7dpe2 vLtJwrIezEHSK7A4vVUAlBN99wAsvWxGqfTAml1BZdljmYCRKjaAtjG5LU0jtMJnxWi/ 7UAqpmH+Ulk71rsPkZFmsl8yOquoIaAH3w8u0PoXmbapNKj9kh52rkGpRYmkRe+AZPQC YCIg== X-Gm-Message-State: AOAM531Ot7Z8mNzdNsI3cIyGssJF6ELVRZI0n5LjvOPSJ/zGdYo3kO8M rnqBnrHF9uaFI+mMbilsCeRrAjTZBbbgCw== X-Google-Smtp-Source: ABdhPJxDizNjRvt897DDtioUj+goRcTTHivZ1X4WRLysBrv8hnoxA15jOgw53sMXGowZrV/L9w+uCA== X-Received: by 2002:aa7:9059:0:b029:151:d725:e230 with SMTP id n25-20020aa790590000b0290151d725e230mr4624501pfo.77.1603301874462; Wed, 21 Oct 2020 10:37:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 02/12] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Date: Wed, 21 Oct 2020 10:37:39 -0700 Message-Id: <20201021173749.111103-3-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::541; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x541.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" Transform the prot bit to a qemu internal page bit, and save it in the page tables. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v10: Add PAGE_BTI define (pmm). --- include/exec/cpu-all.h | 2 ++ linux-user/syscall_defs.h | 4 ++++ target/arm/cpu.h | 5 +++++ linux-user/mmap.c | 16 ++++++++++++++++ target/arm/translate-a64.c | 6 +++--- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 61e13b5038..656a2a8788 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -274,6 +274,8 @@ extern intptr_t qemu_host_page_mask; /* FIXME: Code that sets/uses this is broken and needs to go away. */ #define PAGE_RESERVED 0x0020 #endif +/* Target-specific bits that will be used via page_get_flags(). */ +#define PAGE_TARGET_1 0x0080 =20 #if defined(CONFIG_USER_ONLY) void page_dump(FILE *f); diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 731c3d5341..cabbfb762d 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1277,6 +1277,10 @@ struct target_winsize { #define TARGET_PROT_SEM 0x08 #endif =20 +#ifdef TARGET_AARCH64 +#define TARGET_PROT_BTI 0x10 +#endif + /* Common */ #define TARGET_MAP_SHARED 0x01 /* Share changes */ #define TARGET_MAP_PRIVATE 0x02 /* Changes are private */ diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 49cd5cabcf..c18a916766 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3445,6 +3445,11 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTx= Attrs *x) #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) =20 +/* + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. + */ +#define PAGE_BTI PAGE_TARGET_1 + /* * Naming convention for isar_feature functions: * Functions which test 32-bit ID registers should have _aa32_ in diff --git a/linux-user/mmap.c b/linux-user/mmap.c index f261563420..00c05e6a0f 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -83,6 +83,22 @@ static int validate_prot_to_pageflags(int *host_prot, in= t prot) *host_prot =3D (prot & (PROT_READ | PROT_WRITE)) | (prot & PROT_EXEC ? PROT_READ : 0); =20 +#ifdef TARGET_AARCH64 + /* + * The PROT_BTI bit is only accepted if the cpu supports the feature. + * Since this is the unusual case, don't bother checking unless + * the bit has been requested. If set and valid, record the bit + * within QEMU's page_flags. + */ + if (prot & TARGET_PROT_BTI) { + ARMCPU *cpu =3D ARM_CPU(thread_cpu); + if (cpu_isar_feature(aa64_bti, cpu)) { + valid |=3D TARGET_PROT_BTI; + page_flags |=3D PAGE_BTI; + } + } +#endif + return prot & ~valid ? 0 : page_flags; } =20 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 7188808341..072754fa24 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14507,10 +14507,10 @@ static void disas_data_proc_simd_fp(DisasContext = *s, uint32_t insn) */ static bool is_guarded_page(CPUARMState *env, DisasContext *s) { -#ifdef CONFIG_USER_ONLY - return false; /* FIXME */ -#else uint64_t addr =3D s->base.pc_first; +#ifdef CONFIG_USER_ONLY + return page_get_flags(addr) & PAGE_BTI; +#else int mmu_idx =3D arm_to_core_mmu_idx(s->mmu_idx); unsigned int index =3D tlb_index(env, mmu_idx, addr); CPUTLBEntry *entry =3D tlb_entry(env, mmu_idx, addr); --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302607; cv=none; d=zohomail.com; s=zohoarc; b=dbKdvMakXbhK25sdTh4aUYX4DnMGoPO9/aJ6yNoa/TlI7dUdAQQHkGIyeH2l86/lXlhmF2WLbswjNDlMqrni+yr+Qaz9nr9exdb6suORjNvKojf3L31O6Mp7yv2nxhZ4GWXQT/BmO/BGb2iaFLpu+EEJ/JOvkx3ArluD+x+nCLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302607; 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=8JkogZW08o4QbERarC4qat0jsqD9fmDjl7gKGBrUP6I=; b=LnyjJ9QkFV9aXeADmE1Jol5i3NnveYHYG597fIxo3B+mEzMDvzTKe18cmiIAab3exUXQw5iYKCzpofNuv4SExxo7UX7gOMBWXPfzw62J1ZtjSjovbhoUG+X2r/MJLgOVY9aBwDNSmakRCCm/yX82be041o9jJGGnfdTKPI4U484= 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 1603302607291596.1667775904406; Wed, 21 Oct 2020 10:50:07 -0700 (PDT) Received: from localhost ([::1]:32932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIFS-0000dV-6N for importer@patchew.org; Wed, 21 Oct 2020 13:50:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3v-0006ag-O2 for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:11 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:40260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3j-0006SG-2j for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:11 -0400 Received: by mail-pf1-x444.google.com with SMTP id w21so1894870pfc.7 for ; Wed, 21 Oct 2020 10:37:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:54 -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=8JkogZW08o4QbERarC4qat0jsqD9fmDjl7gKGBrUP6I=; b=QVF+cvIroLqGiN9P3Rzgp+eJI2A9EIDSWnv3RfHAjTc4yJM3bxsOYh495xGk3obymW fNjZY1Q3i82aEAdYMB3XoKZ81M+b3nG0DWKjDuZWHBKl9cBXer65XTvaYysfHUk1gKrI Cpi6eh8Dluo6ifbDOgALx4T0tndGXReXDmg1LFStgPKF/nOPk9tEq4stxFCU1tMwi543 fz9CAwhA2xKxZY2A4KSw9kz0AAklfuwU65aPxbSkHQsHq/OIvPpO/lWabFKsYy65fDAb OuCcK/h4Hu2TuDfFYEiVlG+RbU3hLkB28dUVSc+OvvIj/fO2fPOyOt+m+m8NomTeD9+u UrvQ== 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=8JkogZW08o4QbERarC4qat0jsqD9fmDjl7gKGBrUP6I=; b=ihCrpJV0/YW60WyzVsZh5YIkPV2WoBtEBNkseWBdasNYZrpUQAvhrv6hVMyLxOTvSl N8efgnJaHAl8uqArBILstWe0zYdR+oPvc9Pvq3aQpIR8vRc0fnm7t380h9tbNN37GtS9 rlfvCvXUh+bOxCROB6UUkpRENYXDNx+LOoZMdPNjFzRSn7zv8czbD9VP8UgNB4la2hcy H4vEb/KQcsrWcGE10Zo8U5CQkK4kfAiYugNs8xw3w2pz9xK+03D6oxVx1T+6drtxlSP1 GwI9ZwNwEV+Fid0vuFEqP0nctkF1z+nF+S1jTchHmTlYcbg0XjC1BIYQB6iLQL2Oe6CC JjPw== X-Gm-Message-State: AOAM530JOlRgBmlsIoedkRL5FDC3mOG80i5hsRIV+BnfznMmDgrHNvRe FPfi5B2jc8hxv0+NLw6J1j+edadsn1vyrQ== X-Google-Smtp-Source: ABdhPJx/r3Y5JlOh5tTp8gtlWwg+gczMHl2CKK9Xgebaly+QddDTsI6nn31km79uftlAfPAECOKVRw== X-Received: by 2002:a62:2905:0:b029:15b:57ef:3356 with SMTP id p5-20020a6229050000b029015b57ef3356mr4615207pfp.36.1603301875708; Wed, 21 Oct 2020 10:37:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 03/12] include/elf: Add defines related to GNU property notes for AArch64 Date: Wed, 21 Oct 2020 10:37:40 -0700 Message-Id: <20201021173749.111103-4-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::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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" These are all of the defines required to parse GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. Other missing defines related to other GNU program headers and notes are elided for now. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/elf.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/elf.h b/include/elf.h index c117a4d1ab..10126ff809 100644 --- a/include/elf.h +++ b/include/elf.h @@ -26,9 +26,13 @@ typedef int64_t Elf64_Sxword; #define PT_NOTE 4 #define PT_SHLIB 5 #define PT_PHDR 6 +#define PT_LOOS 0x60000000 +#define PT_HIOS 0x6fffffff #define PT_LOPROC 0x70000000 #define PT_HIPROC 0x7fffffff =20 +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) + #define PT_MIPS_REGINFO 0x70000000 #define PT_MIPS_RTPROC 0x70000001 #define PT_MIPS_OPTIONS 0x70000002 @@ -1657,6 +1661,24 @@ typedef struct elf64_shdr { #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension r= egs */ =20 +/* Defined note types for GNU systems. */ + +#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */ + +/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). = */ + +#define GNU_PROPERTY_STACK_SIZE 1 +#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 + +#define GNU_PROPERTY_LOPROC 0xc0000000 +#define GNU_PROPERTY_HIPROC 0xdfffffff +#define GNU_PROPERTY_LOUSER 0xe0000000 +#define GNU_PROPERTY_HIUSER 0xffffffff + +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) + /* * Physical entry point into the kernel. * --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302759; cv=none; d=zohomail.com; s=zohoarc; b=lJPsFIoglXJXS3mZoWtpLUkHTpGyJnM3CTodCm0mKMFxZacFyMl/i9kQezSNvKvWwSBc4xo/wLkpg2k7sD5k4JhAwTGp21xSY+Isw9hEQ5MLZiHzW/BwzZoz7Tx4b3dQK5M5WNkPh789BO6V1m3bn6E6K7qBPxadkQEC5aCb+vs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302759; h=Content-Type: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=tcQiTVPZ4EDkEsGCvdGZmCD7eErMNKvjpgH4j/u5Y8I=; b=HH4v/eh+hWcpmokVOjzmniTQi6hHB1qX+C6syWh0Kur99TqjJZmpXDKQeK43Mnu8vjaXFGw3QGXt3CowzO9+PN8Zs/He4Mc8Txw9bstyvUKT/rGSIt6+NfX5OPr1SPLlK8xJCb0ZSbEgyQ+PjerLWYkczii6TNh1NFyLfPH2O/4= 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 1603302759150507.2553466843483; Wed, 21 Oct 2020 10:52:39 -0700 (PDT) Received: from localhost ([::1]:40706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIHu-0003sg-0C for importer@patchew.org; Wed, 21 Oct 2020 13:52:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3l-0006UV-NY for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:03 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:35546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3j-0006SM-2c for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:01 -0400 Received: by mail-pf1-x444.google.com with SMTP id h7so1909055pfn.2 for ; Wed, 21 Oct 2020 10:37:58 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:56 -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=tcQiTVPZ4EDkEsGCvdGZmCD7eErMNKvjpgH4j/u5Y8I=; b=OoIDMQLVZbuk92/VKrSIe20T2WfqrPoyPIEZs65mjRaVg1XQbW7bPXw+v4qBANTZ6R i/AD7oNFZa5Y1A4H7oE5mZg/LIxpYIcyH0GjByCodoMSPtYAOWi4jST2k5qQ3wvh9ERB w11MZR58c/QORQsACqj1pAq3wqN/KexD0Xh2tOo3arL5hrjjygNziO+9vpR+4Tzb0AsI QSwoTnKm0yicoAxsSI7pfGrs+KKCabT0NB4zvjSn0mH+rVQEhPEoJLpQc5s4+qJu6j3k oJY+i8ayLt9MTzx+UMHhh4iWYjJ08KB04dl2fdFdrdohxXvCEsKYv6dT3y54tQaeABDH kabg== 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=tcQiTVPZ4EDkEsGCvdGZmCD7eErMNKvjpgH4j/u5Y8I=; b=nAkK0mR7f04dSH9ftn2gXrNelJ38ABeIlk8y4LhOiGPNU7kKCPHSafmAhlsZsL+eeN J4CHQu7l8RM0UQkkwNTtIVMC8qvoaaFUsTFkEJvQZHxgJw1WwqTzq4LMDIqkfMdytRuj gsS5KwOypVUBoVrHKZQUO3NFO8Q+Nksku/hIR+PADk59DahZsdVCoWsYi1G+tqk171ct pL4JH2Pt7K3uvXjo3b+ahp8dekVDp1eMCY07goGQH/QQfGsArKMekBZ4mJMDWMRjN/J5 tgJikf6Z5GcyBWBKJlzp2bq6YmPoFr5LAaiT7tzqKlQZwWBq7kWhr03ZOOaKvc3MS5w1 hoWQ== X-Gm-Message-State: AOAM531bVGEJOOFeglHBXdkIvTODnYfto4HMqRfeQqs22IkKFW3hUx/I rq1DxZl0Em3nHzGRRCY2BzNRDHM6VgvLUQ== X-Google-Smtp-Source: ABdhPJz8hCC9Lz3q3xQovQ857JoaGVWA/whzxfPCQubkEB6qq/WsfKhEpy+5nsDIcim6LY3/qcwCqg== X-Received: by 2002:aa7:908d:0:b029:15f:d774:584 with SMTP id i13-20020aa7908d0000b029015fd7740584mr300509pfa.6.1603301876889; Wed, 21 Oct 2020 10:37:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 04/12] linux-user/elfload: Avoid leaking interp_name using GLib memory API Date: Wed, 21 Oct 2020 10:37:41 -0700 Message-Id: <20201021173749.111103-5-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-Type: text/plain; charset="utf-8" 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::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) From: Philippe Mathieu-Daud=C3=A9 Fix an unlikely memory leak in load_elf_image(). Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20201003174944.1972444-1-f4bug@amsat.org> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f6022fd704..1a3150df7c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2584,13 +2584,13 @@ static void load_elf_image(const char *image_name, = int image_fd, info->brk =3D vaddr_em; } } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { - char *interp_name; + g_autofree char *interp_name =3D NULL; =20 if (*pinterp_name) { errmsg =3D "Multiple PT_INTERP entries"; goto exit_errmsg; } - interp_name =3D malloc(eppnt->p_filesz); + interp_name =3D g_malloc(eppnt->p_filesz); if (!interp_name) { goto exit_perror; } @@ -2609,7 +2609,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, errmsg =3D "Invalid PT_INTERP entry"; goto exit_errmsg; } - *pinterp_name =3D interp_name; + *pinterp_name =3D g_steal_pointer(&interp_name); #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -2961,7 +2961,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) if (elf_interpreter) { info->load_bias =3D interp_info.load_bias; info->entry =3D interp_info.entry; - free(elf_interpreter); + g_free(elf_interpreter); } =20 #ifdef USE_ELF_CORE_DUMP --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302711; cv=none; d=zohomail.com; s=zohoarc; b=gU05RbXSQ0roBokVD7Y+4Ej92H9qTbeaCq2cjxFf1p7YBDVfjQ28kK56CxDbimIR8ONJrbU28c3Z/b7XmePDQM/TIzT7mPIHRepT6QokV5EAIGFDdK0yIOH3z05pGJvK2VZZGJCoIVnE12OoMKzJ6pXatGAXAKM9grPigGuMEds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302711; 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=/PhyfxonOHMia69Uhhz8aFrAtnkrEZKYG1wmZQKttSI=; b=MMgY+mXopqxFpM+Mku8jRsaLme5nWmlfJZemhFgnVEF6uky8suJrok5hBkd516o7HoYbhuzRj3pe/Iianj5mOU6S3k/NqObvyTHvrmXvBzXCTCyNSRX00KAU4sHX/UwsngEkRpTHJ47Kn9w4q/pegNLjPzKsu+WjmOTO0PSsHdE= 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 1603302711546434.1159264526807; Wed, 21 Oct 2020 10:51:51 -0700 (PDT) Received: from localhost ([::1]:38072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIH8-0002pv-Eh for importer@patchew.org; Wed, 21 Oct 2020 13:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3v-0006bM-TG for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:11 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:35995) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3l-0006SQ-5t for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:11 -0400 Received: by mail-pl1-x644.google.com with SMTP id r10so1577515plx.3 for ; Wed, 21 Oct 2020 10:37:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:57 -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=/PhyfxonOHMia69Uhhz8aFrAtnkrEZKYG1wmZQKttSI=; b=DffcFiJpFHZ7sBimYGJ2yffAGd0vidZCppEY70LI7qEQx+jYU04faKrjwLVzsOzMrs d2u5tirYAVWxQ9vBR0+8FmMhfrMKmnWoXrb5LbG73RPemtnf5srxVeqcFxPbr9CD8rDs rwFL7t1Fnl2uavRLqFGQqHn0GKqf1uc3r/vAAJsNL9X4tn5ya89K1f0emqgA3McPRr+y ZX4RcoVEDTKd1I39JC1AhFrEN/joVpZ12nD8g0SuElcKqhPQovqIaXy3+sPQVQlboYd5 IyWR5adPjuI7FXCZ9HpKg9eyejWJGR3wI+zFc8O7qhWe9LRks2E6wfPQagkn4wD51NWU slvg== 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=/PhyfxonOHMia69Uhhz8aFrAtnkrEZKYG1wmZQKttSI=; b=QA24HYFsHU1e5xCC1wIphTZYByEfSxMr2XmU32yH5qsHHCGO+zLATN8DpHU0+sBx9G 9EUUSOebqipQ1SU0Ogv2e2vVd84TbD03FMIvFBcZ4Mgt48FkziS6W3iP3dc/fkDnusH2 fnphM5Q86fowi/21s1o2++FMKzWy1VDEd98Dz8txWyefs5GHiminIZGfvEKYMxAmCA7D CZCyIZ2IEiooeZ28wE80zyufWNxoNlh5uQkvisdIQ/dLCjDn/ZUeVd6Jfo1wR77KUI1I 7wEmtm6R779fpqKBDbymL7MdWmqFWwH0RHmDXJOd0g7xMpWoglsRzgFP7moI30VoLUE7 ks2g== X-Gm-Message-State: AOAM532RCafpY6+1qeCiH8acmc7qzlOgp9eAj6BcibfG/FXh1WjwN5Zj INDbuPcI8Vfefcc7z9HRreRxcVhxvobwWw== X-Google-Smtp-Source: ABdhPJz4+sv83j4LWgQCU1Xq1Hxx/SqkW76fIEEg1Bz47sx3TZj6b1pCll+2tdMXoxiQOdW7rzbG3w== X-Received: by 2002:a17:902:8f90:b029:d5:f329:50b9 with SMTP id z16-20020a1709028f90b02900d5f32950b9mr4727688plo.21.1603301878128; Wed, 21 Oct 2020 10:37:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 05/12] linux-user/elfload: Fix coding style in load_elf_image Date: Wed, 21 Oct 2020 10:37:42 -0700 Message-Id: <20201021173749.111103-6-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::644; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x644.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" Fixing this now will clarify following patches. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 1a3150df7c..290ef70222 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2531,9 +2531,15 @@ static void load_elf_image(const char *image_name, i= nt image_fd, abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr= _len; int elf_prot =3D 0; =20 - if (eppnt->p_flags & PF_R) elf_prot =3D PROT_READ; - if (eppnt->p_flags & PF_W) elf_prot |=3D PROT_WRITE; - if (eppnt->p_flags & PF_X) elf_prot |=3D PROT_EXEC; + if (eppnt->p_flags & PF_R) { + elf_prot |=3D PROT_READ; + } + if (eppnt->p_flags & PF_W) { + elf_prot |=3D PROT_WRITE; + } + if (eppnt->p_flags & PF_X) { + elf_prot |=3D PROT_EXEC; + } =20 vaddr =3D load_bias + eppnt->p_vaddr; vaddr_po =3D TARGET_ELF_PAGEOFFSET(vaddr); --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302838; cv=none; d=zohomail.com; s=zohoarc; b=nbQo12lIwsuwG0B0FNr7nU/5lW6kaqXbe/OLoxFaAmHRFcM8XX97ESvR5WK/bNVR9dW+2IgTsyw46z4vASuSQQBxSikjxXpyrQzHEjQStvyaY9UyAkHnajhm6AV+40buQuVSkQDu2oPfBjXLm6QKchT2siSfrheuM3pDH/49D30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302838; 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=cq0uFj4EPvaT7XIB2x7QEFAKMyx7fIErYUcL6pVPEzc=; b=e+tkGWPvBC3ZCvEwSbV08aXh4RD/1Zg0ifG2bMg50ksrxbfXYaVgFvphpw6SAlqZWsEeJppktDF4qjsleEEt3lyT8nej+CNaXiym2f9CspWL4qcM9hY1CK5l/EB9fGz3fvWJYJGUQvSJkjCcXpaeqWAl1pQftaBItJkszKtiwbI= 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 1603302838862896.0406305041572; Wed, 21 Oct 2020 10:53:58 -0700 (PDT) Received: from localhost ([::1]:45408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIJ9-0005oR-98 for importer@patchew.org; Wed, 21 Oct 2020 13:53:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006XS-Di for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:36108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3n-0006SW-8v for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: by mail-pj1-x1041.google.com with SMTP id kk5so1496722pjb.1 for ; Wed, 21 Oct 2020 10:38:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:37:58 -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=cq0uFj4EPvaT7XIB2x7QEFAKMyx7fIErYUcL6pVPEzc=; b=po62ZWJ6LgSyaqPvF3x5MXfuM60Mjuv5Ee17slzQ/bZr+N7matQ3T04WsaEyfUI8Y8 xdBsRovJnjo5Dmb/YJljo60fpnsuwmmQOzU8A2enOwQiGCq0yK3q5UXv5IaFHc7xfiQK 3brDhkYNFiG1R7BFzvW9ayf6GF7IRtsQK0I59Erk3uefsVdH+pj+qTqHH8tFhvOYhWJ+ EhjA56n7gyOXEEonAKLQLjVXVuweOWSwLQdtgSAnwY4/VdxGPajwweoRT/x8WzzuVOXQ raejHIA7fjgGh0HgnNCpEV0E57UZD+lUa4cGYrjTV/igD1z2MpweGkbQS5ESG4pM3xTu Uojw== 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=cq0uFj4EPvaT7XIB2x7QEFAKMyx7fIErYUcL6pVPEzc=; b=bNMl1BLOQsyl5RpvPSU+3K9no/tFcYcwpkViLEWnj1DDx/ZFwPFBo0qJ62J7prJq1D kR1c+LJlYyllNV0ZV1oXXTdJab15Jh/AMH7Ckdyx3hfrrtrIn/BQj+9FWbved0x3Mmw4 6pEf5ebch7zdCTCRqUU6Y3drZI/iykBs4GgyBTm+mpCJCh1uHXkBNTCKKeCKuB9SUGm6 7mWuQEFmyeoNYr5ospoLwoEPr8ahXHtEYJY39mHQvZ0F+PDhFyI2Id8JHR3KPuQ1ZSnq +wry8ySDmyfPD9XXhahI1g2zegOui4ymYgt6eBUwAa0eN5W5Kf735HNrdk+mgjmmwDW7 vd6w== X-Gm-Message-State: AOAM533hpM4SfXpmLTDzV9Srpg7qSlEfr0A5E06v1qMiJ9VKsUVrlhkp ct0XaH2EjrZxebYwjjZ9IzsVr/iS8gzgiw== X-Google-Smtp-Source: ABdhPJwT9a36e/RjUA37+rDlhMgUUTttda8+JYppFpgYOcs4BIpMO30KV96l7FOFvfceqiU2fJgZfQ== X-Received: by 2002:a17:902:7882:b029:d3:b3bc:9d8a with SMTP id q2-20020a1709027882b02900d3b3bc9d8amr4738555pll.46.1603301879987; Wed, 21 Oct 2020 10:37:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 06/12] linux-user/elfload: Adjust iteration over phdr Date: Wed, 21 Oct 2020 10:37:43 -0700 Message-Id: <20201021173749.111103-7-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::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.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" The second loop uses a loop induction variable, and the first does not. Transform the first to match the second, to simplify a following patch moving code between them. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 290ef70222..210592aa90 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2426,17 +2426,18 @@ static void load_elf_image(const char *image_name, = int image_fd, loaddr =3D -1, hiaddr =3D 0; info->alignment =3D 0; for (i =3D 0; i < ehdr->e_phnum; ++i) { - if (phdr[i].p_type =3D=3D PT_LOAD) { - abi_ulong a =3D phdr[i].p_vaddr - phdr[i].p_offset; + struct elf_phdr *eppnt =3D phdr + i; + if (eppnt->p_type =3D=3D PT_LOAD) { + abi_ulong a =3D eppnt->p_vaddr - eppnt->p_offset; if (a < loaddr) { loaddr =3D a; } - a =3D phdr[i].p_vaddr + phdr[i].p_memsz; + a =3D eppnt->p_vaddr + eppnt->p_memsz; if (a > hiaddr) { hiaddr =3D a; } ++info->nsegs; - info->alignment |=3D phdr[i].p_align; + info->alignment |=3D eppnt->p_align; } } =20 --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603303008; cv=none; d=zohomail.com; s=zohoarc; b=mo9LoiVn872AkjM1uNyqPM6pjEi3Gq5kxV43PCHOlx69TT3rU15Opn+TSPIXMmVVa14JZ9tSxLBR5QQGO7tCyGEAbuX/13XiP5hwg7N+D7yrOm3VBEUNtWdrAlu2ajPrsdBW5qxmXX8P2RJWDGk2kaHhc5uWa9oVaG2jSEBBaFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603303008; 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=XLExgzrLRIoZ+1AkNjtHtGQ6oai05Dc/yN88SMU2dO4=; b=YPqhVJ95URO8lAMvVr/rswujwMd8SebN0TgAfPKvHM7X+l+mOb+if05c3Cp3Cj4LpZlqA1KFsHYAix/F+sdz1sYHl4vHehiq4mhGIqd1NQZUU+KPA0t4i8UjOlnEqjKAAOz1BWOEylvqEGg5JEtL//zpzePZKrZT4vcNB+SxvUk= 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 1603303008929804.0494344292923; Wed, 21 Oct 2020 10:56:48 -0700 (PDT) Received: from localhost ([::1]:53594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVILv-0000tx-Rb for importer@patchew.org; Wed, 21 Oct 2020 13:56:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006Yd-V5 for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:39837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3n-0006Sj-Cw for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:10 -0400 Received: by mail-pj1-x1043.google.com with SMTP id m3so408181pjf.4 for ; Wed, 21 Oct 2020 10:38:02 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38:00 -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=XLExgzrLRIoZ+1AkNjtHtGQ6oai05Dc/yN88SMU2dO4=; b=e8Tc/R58wCdYTQ2hvOg04zN84/j1Ce51unYv4lddeokkAQ5lyy+SUD2p+qiHGMiWjg HCfxguZzWItSLGQbnhj5rBzPSpjkW9Q0Ql/kI7A4gnYobZxboYKSTiMirNAYs+hsT9xg vgZm43SkUN826+bYjV7LstyN6kHCbYUJGFkzvDsNrFuPRFgdPs50cT45fy69ge4KSAOj Ll7RDE9nlnkupdUY0JXALI1H/QuuD9OQFh3smLzziPL87epVqwDsS4F3mYU8LrULxUge KOi217nlkoGn/Ze6mIJ+t2rf5Q3n4IhhWySpCDmjIbB6PcfVGlnJpqZbD6E90eoKyIFW cTcw== 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=XLExgzrLRIoZ+1AkNjtHtGQ6oai05Dc/yN88SMU2dO4=; b=tRvsAomKMWoulHKggEdM3+w1f5AHGmOYio2e7/qranE5NE+2zCwqasOnr/DLTd0U+R aZiSyzwDXRzKuQUbW+Aiab2lDGW95rgQY0DGkIGZUBM7PZRxryX3eGjIAyYuBZzdxu9e tdJco7RgN80++4CcyvJJ7/QA6lUjKaj8BtM8dVkxio/kDF1g2hhQD3loGHWan6Il1kjM QDQ6RSP/R0tsawcFDtsIxEjWHvPiH4eDYCY90MsxAZ7taeiHTyJwetF0AHAO5sPJeIFg +DPzTCh8BY3Z/tN4vq2l8daRwzSSAJf87joTZTrSC7529xmG0oq6JgsG191hv6Rym1vH dXhg== X-Gm-Message-State: AOAM532IjAgLAYNuA8HqbAaQoPlwgiF35WyvgT1rmhFOFBTXQusNJSjW sSlZSQQgQelZA4G21pVCYhua3eJII65oCQ== X-Google-Smtp-Source: ABdhPJxTUESwvxIH0+jb/rLZXik5oyLqjzQdHqXB1yyZSXhfOoPSLX2IJdWCZ+njhUKzI81eF2qCLQ== X-Received: by 2002:a17:902:bc8a:b029:d4:dc57:6c29 with SMTP id bb10-20020a170902bc8ab02900d4dc576c29mr4765610plb.77.1603301881450; Wed, 21 Oct 2020 10:38:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 07/12] linux-user/elfload: Move PT_INTERP detection to first loop Date: Wed, 21 Oct 2020 10:37:44 -0700 Message-Id: <20201021173749.111103-8-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::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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" 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 --- 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 210592aa90..107a628a9e 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) { + g_autofree char *interp_name =3D NULL; + + if (*pinterp_name) { + errmsg =3D "Multiple PT_INTERP entries"; + goto exit_errmsg; + } + interp_name =3D g_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 g_steal_pointer(&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) { - g_autofree char *interp_name =3D NULL; - - if (*pinterp_name) { - errmsg =3D "Multiple PT_INTERP entries"; - goto exit_errmsg; - } - interp_name =3D g_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 g_steal_pointer(&interp_name); #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603303102; cv=none; d=zohomail.com; s=zohoarc; b=ex7swfPxDd5hykeDDBCWoWg1/TmEeWof4qGSS0MN2PyofMkEpI76yklI5bzYydS0bdhxcBJow72haxtNxqjP5VdbGh7ed9fXADiphwzfcgJRxIW98KVt+4s7ug5+q5o8nPVcyPM+70IW+K+6fYnxK4Do2ittlhJKPu4wHBO66dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603303102; 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=i9e477C0zg/4lfiSUJ/DUA8jokwPxP/mv4JJb8OtKrE=; b=Nalnf/uFtjDVsG/trjwdskleAXKNrAQS/e2qXLXOrJrMlaCcPSMg0D7s7zfmR7wu2CBO9SeKhOnmwdUeodVnNFvPoHLenxGT9B0BAbN0tcwsIfk/tyyTdZsd5EhqMUuEMEO7RrutP8VRSJUsVaAnFXLuDMQjekmsO81ZfTU3DOE= 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 1603303102505846.9629000107623; Wed, 21 Oct 2020 10:58:22 -0700 (PDT) Received: from localhost ([::1]:33220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVINR-00049d-EX for importer@patchew.org; Wed, 21 Oct 2020 13:58:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3x-0006fO-9b for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:13 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:34891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006T5-5C for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:12 -0400 Received: by mail-pl1-x644.google.com with SMTP id 1so1583148ple.2 for ; Wed, 21 Oct 2020 10:38:05 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38:01 -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=i9e477C0zg/4lfiSUJ/DUA8jokwPxP/mv4JJb8OtKrE=; b=hTfU1Yq5A14rUMvyRNdxWZNn5fDVheCb/WYZeB/u5humMA4BjkoEg2kBSvgzsjEPut gWry1Tk0U7AWQtqrNFphogmL4BzUqrkLeUOqF1h+/8NrPfxsaBOWsbTMyGNjuzfTzGiw 0hTKb6+JHFhg0Bd+Tg6az9QNdqxpAe1VLfbF2Bh7/X+cdXyr+6ItqMAiU0URS3E8zje3 k96aE8D0MU4t9rIjI3mP4P+XE/krI5GxqxKQwP+Hfph1yLL/ATcxdriI0jKJCP0vQHfu ijKIzSuY7U/25BrKcpqAW2sz9zu7676XGGfOhUjH5Pxf79DkET30EUhEgkNiIWN0rwfh q7tQ== 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=i9e477C0zg/4lfiSUJ/DUA8jokwPxP/mv4JJb8OtKrE=; b=dIrENPTeVRcK0MwaD10KzWKZG1D17TJUZ3GOtn/TNCPCcr9VC0ykmOK7QW3FL52U1M dYHYPIEYLbletTEyuSw5EIYYZZgKTzfaicqN73cv4AMr5ucq4Y6Xfnq7BFrJ+9Foq7GJ YTwSGmJYxgliRdtCxo3zH3wJrGFGXh7DDZYJsV8lJbo8lga8/9Z9h1t2m8TgP/LzT8/N yk0j/yOFzN+SGqWw4wNyeaqldOfxRGdOZExZL1JsIKXYZlR8qcSKfp1EJlTHiudg/7B+ qYYp3/K3dRaMhWcf8jsJDb8ThnV4mFQK78hxUsN1vg30I2tyKBnJyBOV1E319D9Qc4aE mI5g== X-Gm-Message-State: AOAM533omyUlmztM289qBZ0iXnbgVX3kKOPAeSHmRtSnIz0km1RFW2Ae fK7oAQSMowBodnxmUQf+Tsq3Am9Ba8XGGQ== X-Google-Smtp-Source: ABdhPJzvI5PtwUlcSlkNe+Wivj4+f2aHNxepKoXFvghkFrTMH5B2fgYKqgE4/87j2SMQ4LN03TB/EQ== X-Received: by 2002:a17:902:9f96:b029:d4:c459:a181 with SMTP id g22-20020a1709029f96b02900d4c459a181mr4759859plq.28.1603301882721; Wed, 21 Oct 2020 10:38:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 08/12] linux-user/elfload: Use Error for load_elf_image Date: Wed, 21 Oct 2020 10:37:45 -0700 Message-Id: <20201021173749.111103-9-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::644; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x644.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" This is a bit clearer than open-coding some of this with a bare c string. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 107a628a9e..56fbda93d0 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -12,6 +12,7 @@ #include "qemu/guest-random.h" #include "qemu/units.h" #include "qemu/selfmap.h" +#include "qapi/error.h" =20 #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -2392,15 +2393,16 @@ static void load_elf_image(const char *image_name, = int image_fd, struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval; - const char *errmsg; + Error *err =3D NULL; =20 /* First of all, some simple consistency checks */ - errmsg =3D "Invalid ELF image for this architecture"; if (!elf_check_ident(ehdr)) { + error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; } bswap_ehdr(ehdr); if (!elf_check_ehdr(ehdr)) { + error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; } =20 @@ -2444,13 +2446,11 @@ static void load_elf_image(const char *image_name, = int image_fd, g_autofree char *interp_name =3D NULL; =20 if (*pinterp_name) { - errmsg =3D "Multiple PT_INTERP entries"; + error_setg(&err, "Multiple PT_INTERP entries"); goto exit_errmsg; } + interp_name =3D g_malloc(eppnt->p_filesz); - if (!interp_name) { - goto exit_perror; - } =20 if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { memcpy(interp_name, bprm_buf + eppnt->p_offset, @@ -2459,11 +2459,11 @@ static void load_elf_image(const char *image_name, = int image_fd, retval =3D pread(image_fd, interp_name, eppnt->p_filesz, eppnt->p_offset); if (retval !=3D eppnt->p_filesz) { - goto exit_perror; + goto exit_read; } } if (interp_name[eppnt->p_filesz - 1] !=3D 0) { - errmsg =3D "Invalid PT_INTERP entry"; + error_setg(&err, "Invalid PT_INTERP entry"); goto exit_errmsg; } *pinterp_name =3D g_steal_pointer(&interp_name); @@ -2520,7 +2520,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED : 0), -1, 0); if (load_addr =3D=3D -1) { - goto exit_perror; + goto exit_mmap; } load_bias =3D load_addr - loaddr; =20 @@ -2587,7 +2587,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, image_fd, eppnt->p_offset - vaddr_po); =20 if (error =3D=3D -1) { - goto exit_perror; + goto exit_mmap; } } =20 @@ -2623,7 +2623,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { - errmsg =3D "Invalid PT_MIPS_ABIFLAGS entry"; + error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); goto exit_errmsg; } if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { @@ -2633,7 +2633,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, retval =3D pread(image_fd, &abiflags, sizeof(Mips_elf_abif= lags_v0), eppnt->p_offset); if (retval !=3D sizeof(Mips_elf_abiflags_v0)) { - goto exit_perror; + goto exit_read; } } bswap_mips_abiflags(&abiflags); @@ -2658,13 +2658,16 @@ static void load_elf_image(const char *image_name, = int image_fd, =20 exit_read: if (retval >=3D 0) { - errmsg =3D "Incomplete read of file header"; - goto exit_errmsg; + error_setg(&err, "Incomplete read of file header"); + } else { + error_setg_errno(&err, errno, "Error reading file header"); } - exit_perror: - errmsg =3D strerror(errno); + goto exit_errmsg; + exit_mmap: + error_setg_errno(&err, errno, "Error mapping file"); + goto exit_errmsg; exit_errmsg: - fprintf(stderr, "%s: %s\n", image_name, errmsg); + error_reportf_err(err, "%s: ", image_name); exit(-1); } =20 --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302823; cv=none; d=zohomail.com; s=zohoarc; b=R9VosdkwbeVDxh69F0rlZmQ98HxrnSacPjXqNvIoT9Gs3OpriOOw7DhggDmdciqD/4Wk74KyQRQW4w6gyNQFfzlCVSO5xUtc3rceSD0YBTt9ttF2XMBs/asf+QGta+5iyUES+MePEQgA1oR+UAPspBQhut4gWdRR2RaU1HwjVCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302823; 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=r7Om/lCAM0XeGEoR/BbgvQnU929VV6uqCsbicYkIs8s=; b=CQxBT7bbix+OCYePLLSP0rqhH7P/CPipohfOINptHt1tVBwAba7ZH2O3YodNqcfwMPsH/2eUMeN8Yx1lS3E/SufHkdhwDK98STIbyHfJGWzGIlEvpwjMy3pZhtkR7Gf0FV1qDGriTtoYBQc3RePAS9jvkBYORfw4eGISxMypUG0= 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 1603302823610125.11595920795253; Wed, 21 Oct 2020 10:53:43 -0700 (PDT) Received: from localhost ([::1]:44138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIIw-0005IP-Hh for importer@patchew.org; Wed, 21 Oct 2020 13:53:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3w-0006dv-MH for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:12 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:51912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006TE-4k for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:12 -0400 Received: by mail-pj1-x1041.google.com with SMTP id a17so1522241pju.1 for ; Wed, 21 Oct 2020 10:38:06 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38:04 -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=r7Om/lCAM0XeGEoR/BbgvQnU929VV6uqCsbicYkIs8s=; b=qYr1z1BWmJW5qCiXztlPzE77U7HI/tv+Fn9oyCjz80MNczmRmWceWQ3a/P2G7BCRjI 69GuBi43EJWPrCbM17af429pS6BpZxy33t/0XYxuVM+kU2J76RVyAEv7UDEeUZueGAGQ QHuX9AOxfymzDRy93dJl9WS0xarxBV1Qcy2hPSKXNDn1FHCxMz4dPdTuahJvptxyYnDf 2cIOL/hFYzRqwl9rdIGbYh+I04E+AexxBY+k0JKQXB1xGF+MhWA1Of0+7NecPuuvUY3f 5A6V1utr6vZbnCxS+dPBMHBt59eZz8H5yUSwlK7lz3uRMKBjWw0FOTUjBUCrUntt7tsZ sM6A== 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=r7Om/lCAM0XeGEoR/BbgvQnU929VV6uqCsbicYkIs8s=; b=qCYOY2dguwIZiLjSBhEWuuqRZojk4h/YHdqa92fV9isLCn5+V2sz+qEhcwTNDPQJBE xnB3XAKn8ucgxrksEVQmS9Er4VwXQ1vAjrn12i9oExR7n5Nbjzt1FsgQ7hHjFIZyRFhL 9rF3owZvpzmBVlkhk91/6T3IGSsoA12ag1ZdfG1jZIFRfixWWUAtg/nrXzxAYkSsGpAb dUkkhWS3CNuLZzCy6z8fCVtLAi55BJyh+MjkM5btpwXm+JZedwBS4nx5v+kTsphBmwRU wDljNTAaXga+e/QJnrEgpV5Y0eV9EsUbGmsFyAwnYkVCOsIwMUOVoJjpIrsLt8L3ZVgV zUAw== X-Gm-Message-State: AOAM53287tWN+C8j5YBQ82q6ZeyyQSRRDQDuZM3raIp0mjl7ttJQDF8I NAVw+ouY4qvlz1OpGwyT3sqoonD4VstrRw== X-Google-Smtp-Source: ABdhPJwwD4km7ClYoUoGlQfkhMMDuu2Efab+WUrYUMUH9mZG02hDL5cJo0odxneYnDEhjkEBNbRNOw== X-Received: by 2002:a17:90b:90c:: with SMTP id bo12mr4237908pjb.7.1603301885194; Wed, 21 Oct 2020 10:38:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 09/12] linux-user/elfload: Use Error for load_elf_interp Date: Wed, 21 Oct 2020 10:37:46 -0700 Message-Id: <20201021173749.111103-10-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::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.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" This is slightly clearer than just using strerror, though the different forms produced by error_setg_file_open and error_setg_errno isn't entirely convenient. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 56fbda93d0..04c04bc260 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2675,26 +2675,27 @@ static void load_elf_interp(const char *filename, s= truct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { int fd, retval; + Error *err =3D NULL; =20 fd =3D open(path(filename), O_RDONLY); if (fd < 0) { - goto exit_perror; + error_setg_file_open(&err, errno, filename); + error_report_err(err); + exit(-1); } =20 retval =3D read(fd, bprm_buf, BPRM_BUF_SIZE); if (retval < 0) { - goto exit_perror; + error_setg_errno(&err, errno, "Error reading file header"); + error_reportf_err(err, "%s: ", filename); + exit(-1); } + if (retval < BPRM_BUF_SIZE) { memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); } =20 load_elf_image(filename, fd, info, NULL, bprm_buf); - return; - - exit_perror: - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); - exit(-1); } =20 static int symfind(const void *s0, const void *s1) --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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=1603302857; cv=none; d=zohomail.com; s=zohoarc; b=BG5sn17SrIbdnS+1Zy+b1m+mbGtIroLo0ZYhoOE8GECstJLyfbCpgwlWaFEBLU4x9alpaAJ2mskvWqwQONvEJYMp0GNcxzeycp8JhTtwulPd0DKDBGFPCnkbVB1WgFLLAwX9seqUzE830mK/2UqwxfKbDz9m8EuoHfAHvCgr47U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603302857; 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=uXEiXCwmZ4IatXzjo8oCm1sQVSclKFFXnkVflorhWjg=; b=gkf8avK0kK1aEX5HINymCXEoUQG2lk3OZR1UwXuOw1di25FQzUABEUmchKbF+EoARpdSfEN8EhcoB+tuL769V2jvute7U/Ng6FlEgkDh1Z6t8Ky1svrOuJbjiVUHM4AasQeoROkJPlFPJXzh3JFVfG0j9qCaQ52IIo/nNpdh80s= 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 1603302856977216.57914902135167; Wed, 21 Oct 2020 10:54:16 -0700 (PDT) Received: from localhost ([::1]:46454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIJT-0006EV-SQ for importer@patchew.org; Wed, 21 Oct 2020 13:54:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3x-0006hC-W2 for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:14 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:44568) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3u-0006UY-6c for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:13 -0400 Received: by mail-pf1-x441.google.com with SMTP id f19so1880732pfj.11 for ; Wed, 21 Oct 2020 10:38:08 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38: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=uXEiXCwmZ4IatXzjo8oCm1sQVSclKFFXnkVflorhWjg=; b=cLidm0XuUM7MSAP6Wh9lagSVqpYg6YyccFm218JS/hD14EZYis6gZr3svZWmJGa73s zRzI3nTxuOk5mW47b7AA5A50Pen3l8gTOxYHo2nMzNEJ2wZ44icaoDgey/8fI2yak3tL 2xKaZzfdtgNlTdx32sSyii8MFBGozaDWfvJmPJWOx/ntF6gGXhKhbfz6pfUBofCDrsW5 8lTXsyYoCptmA3dOU3nboqIHctu2ZG/z/bxdNH18RFYpYJ9AS27G5Slh158nX3KwJyuf PJas4AAAR8rYU6kgTgCSFewG2/trEqUyYSV9WmIcYc+MVMa+VHVd1Bi5ePm4OTwo6aKz Jo2Q== 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=uXEiXCwmZ4IatXzjo8oCm1sQVSclKFFXnkVflorhWjg=; b=h3X9+u8xUtYYeyjwzO4tKQoZpIGzG1YBpSaS3kHw3CQA9Qzc+s5YKhFls7t0fCMC0d sKk9WqSlUC0yfRpcUo5RC2CCZtKXWH8ZVPkHtNj3r2iXGcqMSYifiZ2vrLtNaUyGMVbL A6vyIScWG20T9F+Ts9McmJhmIG5EVadUui/YNAcLj7uVy8P5l3hNznnUmkY5ncN3tShH 0XTZo6cRfigaSVHgfvZ+ZqOOFloKmwcrN7eFzcc2UB4duGdw3NzTDqYWsdsV3LvyPaVU mUHfMkF5qTf0FmvqxPl+4Zw5InaCUPmIxNbjT85uelYMZtpR30MvGkdNY4QX2IkKaIHQ GeTQ== X-Gm-Message-State: AOAM5328md9jFdPDny+WW0JaLOuqLPmTbD/FvPXTKTzkWu6iXhzy/yoa TEeTtNS6FkUtdx8tP6TEhK3WnXchjY6IiA== X-Google-Smtp-Source: ABdhPJz+wIYocRi8SBDyTYbF5+lWxZAK8g1x/9hBahiJ5k2Qn23OEeECRfU5E6mRC030lFlAaj7+gg== X-Received: by 2002:a62:17c2:0:b029:158:ca2e:3cd7 with SMTP id 185-20020a6217c20000b0290158ca2e3cd7mr4546856pfx.43.1603301886732; Wed, 21 Oct 2020 10:38:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 10/12] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Date: Wed, 21 Oct 2020 10:37:47 -0700 Message-Id: <20201021173749.111103-11-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::441; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x441.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" This is generic support, with the code disabled for all targets. Signed-off-by: Richard Henderson --- v9: Only map the startup executable with BTI; anything else must be handled by the interpreter. v10: Split out preparatory patches (pmm). v11: Mirror(-ish) the kernel's code structure (pmm). --- linux-user/qemu.h | 4 ++ linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 941ca99722..534753ca12 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -61,6 +61,10 @@ struct image_info { abi_ulong interpreter_loadmap_addr; abi_ulong interpreter_pt_dynamic_addr; struct image_info *other_info; + + /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */ + uint32_t note_flags; + #ifdef TARGET_MIPS int fp_abi; int interp_fp_abi; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 04c04bc260..428dcaa152 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1522,6 +1522,15 @@ static void elf_core_copy_regs(target_elf_gregset_t = *regs, =20 #include "elf.h" =20 +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, + const uint32_t *data, + struct image_info *info, + Error **errp) +{ + g_assert_not_reached(); +} +#define ARCH_USE_GNU_PROPERTY 0 + struct exec { unsigned int a_info; /* Use macros N_MAGIC, etc for access */ @@ -2373,6 +2382,150 @@ void probe_guest_base(const char *image_name, abi_u= long guest_loaddr, "@ 0x%" PRIx64 "\n", (uint64_t)guest_base); } =20 +enum { + /* The string "GNU\0" as a magic number. */ + GNU0_MAGIC =3D const_le32('G' | 'N' << 8 | 'U' << 16), + NOTE_DATA_SZ =3D 1 * KiB, + NOTE_NAME_SZ =3D 4, + ELF_GNU_PROPERTY_ALIGN =3D ELF_CLASS =3D=3D ELFCLASS32 ? 4 : 8, +}; + +/* + * Process a single gnu_property entry. + * Return false for error. + */ +static bool parse_elf_property(const uint32_t *data, int *off, int datasz, + struct image_info *info, bool have_prev_typ= e, + uint32_t *prev_type, Error **errp) +{ + uint32_t pr_type, pr_datasz, step; + + if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) { + goto error_data; + } + datasz -=3D *off; + data +=3D *off / sizeof(uint32_t); + + if (datasz < 2 * sizeof(uint32_t)) { + goto error_data; + } + pr_type =3D data[0]; + pr_datasz =3D data[1]; + data +=3D 2; + datasz -=3D 2 * sizeof(uint32_t); + step =3D ROUND_UP(pr_datasz, ELF_GNU_PROPERTY_ALIGN); + if (step > datasz) { + goto error_data; + } + + /* Properties are supposed to be unique and sorted on pr_type. */ + if (have_prev_type && pr_type <=3D *prev_type) { + if (pr_type =3D=3D *prev_type) { + error_setg(errp, "Duplicate property in PT_GNU_PROPERTY"); + } else { + error_setg(errp, "Unsorted property in PT_GNU_PROPERTY"); + } + return false; + } + *prev_type =3D pr_type; + + if (!arch_parse_elf_property(pr_type, pr_datasz, data, info, errp)) { + return false; + } + + *off +=3D 2 * sizeof(uint32_t) + step; + return true; + + error_data: + error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY"); + return false; +} + +/* Process NT_GNU_PROPERTY_TYPE_0. */ +static bool parse_elf_properties(int image_fd, + struct image_info *info, + const struct elf_phdr *phdr, + char bprm_buf[BPRM_BUF_SIZE], + Error **errp) +{ + union { + struct elf_note nhdr; + uint32_t data[NOTE_DATA_SZ / sizeof(uint32_t)]; + } note; + + int n, off, datasz; + bool have_prev_type; + uint32_t prev_type; + + /* Unless the arch requires properties, ignore them. */ + if (!ARCH_USE_GNU_PROPERTY) { + return true; + } + + /* If the properties are crazy large, that's too bad. */ + n =3D phdr->p_filesz; + if (n > sizeof(note)) { + error_setg(errp, "PT_GNU_PROPERTY too large"); + return false; + } + if (n < sizeof(note.nhdr)) { + error_setg(errp, "PT_GNU_PROPERTY too small"); + return false; + } + + if (phdr->p_offset + n <=3D BPRM_BUF_SIZE) { + memcpy(¬e, bprm_buf + phdr->p_offset, n); + } else { + ssize_t len =3D pread(image_fd, ¬e, n, phdr->p_offset); + if (len !=3D n) { + error_setg_errno(errp, errno, "Error reading file header"); + return false; + } + } + + /* + * The contents of a valid PT_GNU_PROPERTY is a sequence + * of uint32_t -- swap them all now. + */ +#ifdef BSWAP_NEEDED + for (int i =3D 0; i < n / 4; i++) { + bswap32s(note.data + i); + } +#endif + + /* + * Note that nhdr is 3 words, and that the "name" described by namesz + * immediately follows nhdr and is thus at the 4th word. Further, all + * of the inputs to the kernel's round_up are multiples of 4. + */ + if (note.nhdr.n_type !=3D NT_GNU_PROPERTY_TYPE_0 || + note.nhdr.n_namesz !=3D NOTE_NAME_SZ || + note.data[3] !=3D GNU0_MAGIC) { + error_setg(errp, "Invalid note in PT_GNU_PROPERTY"); + return false; + } + off =3D sizeof(note.nhdr) + NOTE_NAME_SZ; + + datasz =3D note.nhdr.n_descsz + off; + if (datasz > n) { + error_setg(errp, "Invalid note size in PT_GNU_PROPERTY"); + return false; + } + + have_prev_type =3D false; + prev_type =3D 0; + while (1) { + if (off =3D=3D datasz) { + return true; /* end, exit ok */ + } + if (!parse_elf_property(note.data, &off, datasz, info, + have_prev_type, &prev_type, errp)) { + return false; + } + have_prev_type =3D true; + } +} + /* Load an ELF image into the address space. =20 IMAGE_NAME is the filename of the image, to use in error messages. @@ -2467,6 +2620,10 @@ static void load_elf_image(const char *image_name, i= nt image_fd, goto exit_errmsg; } *pinterp_name =3D g_steal_pointer(&interp_name); + } else if (eppnt->p_type =3D=3D PT_GNU_PROPERTY) { + if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &er= r)) { + goto exit_errmsg; + } } } =20 --=20 2.25.1 From nobody Wed May 15 05:50:09 2024 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 From nobody Wed May 15 05:50:09 2024 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=1603303059; cv=none; d=zohomail.com; s=zohoarc; b=FeslguOb76uJsCtWsENXgWAiGPBV5BMAC9pBA1sylr1Wq7LeieZfiR3tfMhm+Jh8eBgBoYxLVtCEGKBxNHlnUm0yAnzOPPj/n7meNct4EaJ5jHtpGXlwZqXb5RI0O3FCvc/pfxX7mWkRDABZti6dW8QXB7+/2Aoiwyf2fYse/j0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603303059; h=Content-Type: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=Td4xnEopiuXb/lCMaNeaOEMvPn5CHL5rQwcFgq+Y09c=; b=ROB2eJKSddRVHhKqwcXOKyae96qsUUrbGliZPCUnzuvUHNLf0/jtrBzj/Gsxk7achhU1sccVPUpiLPX/eWn890jKns6qnsaJ04/CsKAl48SkmpPFWYiiaDB/PGtKyxmP/aNrwAZOU6cRuqZPM7OZqo5OY3i3sfXHlr23yif0ujk= 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 1603303059462458.83114120195364; Wed, 21 Oct 2020 10:57:39 -0700 (PDT) Received: from localhost ([::1]:57506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIMk-0002XC-3i for importer@patchew.org; Wed, 21 Oct 2020 13:57:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI3y-0006iy-L6 for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:14 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:44725) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI3v-0006Ux-He for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:38:14 -0400 Received: by mail-pf1-x431.google.com with SMTP id f19so1880807pfj.11 for ; Wed, 21 Oct 2020 10:38:10 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id h5sm2928829pfh.9.2020.10.21.10.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:38:08 -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=Td4xnEopiuXb/lCMaNeaOEMvPn5CHL5rQwcFgq+Y09c=; b=ZQtRcWluwkxpIVkZkuU0ZPIagqQqZ+2FSA7EVbdPcgrQndDjNf9CimCOo9Hpmocb58 T+M03012kOtfo/Esmki1yBjk4QgKyI9fN61O6s+bOkgFWIWmEG+OKy7eEoj98upAkItz ZskUPe4KaeTzVyCR2L1wQheys3g/k+ZHEq+X4h5f1O4JZcN1TdcNKc9Ghat7j1ygKiuQ yYHefAI2IK8C5SIR3Jny150e9TEP85MFZP73zyX6tCFgMhrDZdPRCKGThCXVIOgsSA79 8Lk6072J1sv0FdfOy5so3HR9CAL/BhlqWKSrdyZ9mvGg/QqqoaKBxZiPMyTlk9iUNk65 wgLg== 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=Td4xnEopiuXb/lCMaNeaOEMvPn5CHL5rQwcFgq+Y09c=; b=k11JV25fQjXe2cPEsKayvq5mUUMixmRe11AvLfqh0ImlmW3SGJCme00WgqnpknhJ13 JzFGZqhHKZQx88b0q2eFmtc2QNUjqW9CaMAJWnkX/4BFtYv2Sjeurt7L/tZ8Keik8tYp oyv/yttxx7RhN+VzbDaRu7mE6teXFCahDVjhT9RCH2MmVRRaPP8NPQ3AI2kSeymPw6x6 Yj6UEFMhNPXT9/tbV/FlimCtl6bA2QstLWP6Y2oGZwpDfBAmAgJNvVs/f6fGsU/5aCaH +nJzCL5aSoJG7z1n4Dh6FlLe9SwalmWMPIbyujhD7c/1w8lKg/4TopgBJ8lNj2onBSoj z0LQ== X-Gm-Message-State: AOAM5320C6xZd0R8Vy0jjv0Cx+XWAPl9MGgyDX6CkwWl3eCJPZGfaXHD 3lSzmEInpootVgajdM7ogUln/QxjVoGxuQ== X-Google-Smtp-Source: ABdhPJwqE6njMrAajljLOyjDdYrgXlazu06ppVJBfIHBMBtoqGjIvxwdl5fgWxSXs+G52fI7MlX2pA== X-Received: by 2002:a62:e81a:0:b029:152:97f9:9775 with SMTP id c26-20020a62e81a0000b029015297f99775mr4550029pfi.29.1603301889395; Wed, 21 Oct 2020 10:38:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v12 12/12] tests/tcg/aarch64: Add bti smoke tests Date: Wed, 21 Oct 2020 10:37:49 -0700 Message-Id: <20201021173749.111103-13-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-Type: text/plain; charset="utf-8" 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::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) The note test requires gcc 10 for -mbranch-protection=3Dstandard. The mmap test uses PROT_BTI and does not require special compiler support. Acked-by: Alex Benn=C3=A9e Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v9: Expect and require gcc 10. v11: Squash mmap smoke test. v12: Work around linker bug in bti-2. --- tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ tests/tcg/aarch64/Makefile.target | 10 +++ tests/tcg/configure.sh | 4 ++ 5 files changed, 243 insertions(+) create mode 100644 tests/tcg/aarch64/bti-1.c create mode 100644 tests/tcg/aarch64/bti-2.c create mode 100644 tests/tcg/aarch64/bti-crt.inc.c diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c new file mode 100644 index 0000000000..61924f0d7a --- /dev/null +++ b/tests/tcg/aarch64/bti-1.c @@ -0,0 +1,62 @@ +/* + * Branch target identification, basic notskip cases. + */ + +#include "bti-crt.inc.c" + +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) +{ + uc->uc_mcontext.pc +=3D 8; + uc->uc_mcontext.pstate =3D 1; +} + +#define NOP "nop" +#define BTI_N "hint #32" +#define BTI_C "hint #34" +#define BTI_J "hint #36" +#define BTI_JC "hint #38" + +#define BTYPE_1(DEST) \ + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16") + +#define BTYPE_2(DEST) \ + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x16", "x30") + +#define BTYPE_3(DEST) \ + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ + : "=3Dr"(skipped) : : "x15") + +#define TEST(WHICH, DEST, EXPECT) \ + do { WHICH(DEST); fail +=3D skipped ^ EXPECT; } while (0) + + +int main() +{ + int fail =3D 0; + int skipped; + + /* Signal-like with SA_SIGINFO. */ + signal_info(SIGILL, skip2_sigill); + + TEST(BTYPE_1, NOP, 1); + TEST(BTYPE_1, BTI_N, 1); + TEST(BTYPE_1, BTI_C, 0); + TEST(BTYPE_1, BTI_J, 0); + TEST(BTYPE_1, BTI_JC, 0); + + TEST(BTYPE_2, NOP, 1); + TEST(BTYPE_2, BTI_N, 1); + TEST(BTYPE_2, BTI_C, 0); + TEST(BTYPE_2, BTI_J, 1); + TEST(BTYPE_2, BTI_JC, 0); + + TEST(BTYPE_3, NOP, 1); + TEST(BTYPE_3, BTI_N, 1); + TEST(BTYPE_3, BTI_C, 1); + TEST(BTYPE_3, BTI_J, 0); + TEST(BTYPE_3, BTI_JC, 0); + + return fail; +} diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c new file mode 100644 index 0000000000..65e8e857dd --- /dev/null +++ b/tests/tcg/aarch64/bti-2.c @@ -0,0 +1,116 @@ +/* + * Branch target identification, basic notskip cases. + */ + +#include +#include +#include +#include +#include + +#ifndef PROT_BTI +#define PROT_BTI 0x10 +#endif + +static void skip2_sigill(int sig, siginfo_t *info, void *vuc) +{ + ucontext_t *uc =3D vuc; + uc->uc_mcontext.pc +=3D 8; + uc->uc_mcontext.pstate =3D 1; +} + +#define NOP "nop" +#define BTI_N "hint #32" +#define BTI_C "hint #34" +#define BTI_J "hint #36" +#define BTI_JC "hint #38" + +#define BTYPE_1(DEST) \ + "mov x1, #1\n\t" \ + "adr x16, 1f\n\t" \ + "br x16\n" \ +"1: " DEST "\n\t" \ + "mov x1, #0" + +#define BTYPE_2(DEST) \ + "mov x1, #1\n\t" \ + "adr x16, 1f\n\t" \ + "blr x16\n" \ +"1: " DEST "\n\t" \ + "mov x1, #0" + +#define BTYPE_3(DEST) \ + "mov x1, #1\n\t" \ + "adr x15, 1f\n\t" \ + "br x15\n" \ +"1: " DEST "\n\t" \ + "mov x1, #0" + +#define TEST(WHICH, DEST, EXPECT) \ + WHICH(DEST) "\n" \ + ".if " #EXPECT "\n\t" \ + "eor x1, x1," #EXPECT "\n" \ + ".endif\n\t" \ + "add x0, x0, x1\n\t" + +asm("\n" +"test_begin:\n\t" + BTI_C "\n\t" + "mov x2, x30\n\t" + "mov x0, #0\n\t" + + TEST(BTYPE_1, NOP, 1) + TEST(BTYPE_1, BTI_N, 1) + TEST(BTYPE_1, BTI_C, 0) + TEST(BTYPE_1, BTI_J, 0) + TEST(BTYPE_1, BTI_JC, 0) + + TEST(BTYPE_2, NOP, 1) + TEST(BTYPE_2, BTI_N, 1) + TEST(BTYPE_2, BTI_C, 0) + TEST(BTYPE_2, BTI_J, 1) + TEST(BTYPE_2, BTI_JC, 0) + + TEST(BTYPE_3, NOP, 1) + TEST(BTYPE_3, BTI_N, 1) + TEST(BTYPE_3, BTI_C, 1) + TEST(BTYPE_3, BTI_J, 0) + TEST(BTYPE_3, BTI_JC, 0) + + "ret x2\n" +"test_end:" +); + +int main() +{ + struct sigaction sa; + void *tb, *te; + + void *p =3D mmap(0, getpagesize(), + PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (p =3D=3D MAP_FAILED) { + perror("mmap"); + return 1; + } + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction =3D skip2_sigill; + sa.sa_flags =3D SA_SIGINFO; + if (sigaction(SIGILL, &sa, NULL) < 0) { + perror("sigaction"); + return 1; + } + + /* + * ??? With "extern char test_begin[]", some compiler versions + * will use :got references, and some linker versions will + * resolve this reference to a static symbol incorrectly. + * Bypass this error by using a pc-relative reference directly. + */ + asm("adr %0, test_begin; adr %1, test_end" : "=3Dr"(tb), "=3Dr"(te)); + + memcpy(p, tb, te - tb); + + return ((int (*)(void))p)(); +} diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.in= c.c new file mode 100644 index 0000000000..47805f4e35 --- /dev/null +++ b/tests/tcg/aarch64/bti-crt.inc.c @@ -0,0 +1,51 @@ +/* + * Minimal user-environment for testing BTI. + * + * Normal libc is not (yet) built with BTI support enabled, + * and so could generate a BTI TRAP before ever reaching main. + */ + +#include +#include +#include +#include + +int main(void); + +void _start(void) +{ + exit(main()); +} + +void exit(int ret) +{ + register int x0 __asm__("x0") =3D ret; + register int x8 __asm__("x8") =3D __NR_exit; + + asm volatile("svc #0" : : "r"(x0), "r"(x8)); + __builtin_unreachable(); +} + +/* + * Irritatingly, the user API struct sigaction does not match the + * kernel API struct sigaction. So for simplicity, isolate the + * kernel ABI here, and make this act like signal. + */ +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) +{ + struct kernel_sigaction { + void (*handler)(int, siginfo_t *, ucontext_t *); + unsigned long flags; + unsigned long restorer; + unsigned long mask; + } sa =3D { fn, SA_SIGINFO, 0, 0 }; + + register int x0 __asm__("x0") =3D sig; + register void *x1 __asm__("x1") =3D &sa; + register void *x2 __asm__("x2") =3D 0; + register int x3 __asm__("x3") =3D sizeof(unsigned long); + register int x8 __asm__("x8") =3D __NR_rt_sigaction; + + asm volatile("svc #0" + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory= "); +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index e7249915e7..d7d33e293c 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -25,6 +25,16 @@ run-pauth-%: QEMU_OPTS +=3D -cpu max run-plugin-pauth-%: QEMU_OPTS +=3D -cpu max endif =20 +# BTI Tests +# bti-1 tests the elf notes, so we require special compiler support. +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) +AARCH64_TESTS +=3D bti-1 +bti-1: CFLAGS +=3D -mbranch-protection=3Dstandard +bti-1: LDFLAGS +=3D -nostdlib +endif +# bti-2 tests PROT_BTI, so no special compiler support required. +AARCH64_TESTS +=3D bti-2 + # Semihosting smoke test for linux-user AARCH64_TESTS +=3D semihosting run-semihosting: semihosting diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index be51bdb5a4..e1b70e25f2 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -240,6 +240,10 @@ for target in $target_list; do -march=3Darmv8.3-a -o $TMPE $TMPC; then echo "CROSS_CC_HAS_ARMV8_3=3Dy" >> $config_target_mak fi + if do_compiler "$target_compiler" $target_compiler_cflags \ + -mbranch-protection=3Dstandard -o $TMPE $TMPC; then + echo "CROSS_CC_HAS_ARMV8_BTI=3Dy" >> $config_target_mak + fi ;; esac =20 --=20 2.25.1