From nobody Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676168; cv=none; d=zohomail.com; s=zohoarc; b=GxYXNJXE3apq2q1YivKdBaaCvT/cv4DbSbLIE2Us9JxTqRNNIphBJXdXI6bZE0fExwgxU5qq1J4cLjfAwGca71G5n6n9x4pR5dSkkbFOMh4GblsnbaFCs+qhF2YQSvjHMvFb0Cx6gVQuSwRo+r0i0KToE5BsMMdHoQzEUj7eol8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676168; 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=n+unt1wGrYBszr6y8v0Kn+iVs3SDDnW5rmvPLPLRzaYDj09LtzAQcdIqrZ1af02sK5f+/ogCiPSShd1CFXgws5jikVMax6o3wLN8wu1TTkVqAN/zNQCorvDYy0GVYF0dJwTrxL1ame+uYs8Fb3rz6OBxcOhR03PQ+FQODPC0WWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676168719942.5121108198667; Fri, 2 Oct 2020 15:02:48 -0700 (PDT) Received: from localhost ([::1]:57400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOT8Z-0004pf-DK for importer@patchew.org; Fri, 02 Oct 2020 18:02:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT5v-0002Ud-Ik for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:03 -0400 Received: from mail-oo1-xc41.google.com ([2607:f8b0:4864:20::c41]:43183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT5s-0007Lv-Ks for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:03 -0400 Received: by mail-oo1-xc41.google.com with SMTP id w25so734987oos.10 for ; Fri, 02 Oct 2020 15:00:00 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.14.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 14:59: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=zVLgn+OX/nTD/oUAFauTpXTtA86xiUG6+rSs26rONZM=; b=mZf3ei3K0SiIqpW+c5uWCNbm2ueVTT5/vAmHbsu2rR/KjUJHZrOXhkwRax/5I7x3oP 2Dl9Sq4f1iRROEp8QgfSJRu/U4uv8opg6mRo3zyQEmOhbwMDys6EQ8Ev28eQ/uxCBu0x mRjvNGcUgDhRh3e9Fs7J8NaS49+rPfrnWw5DKG19+vLajb+4aOX5SVOLjXLOhbJI++kJ V8G6AlBwsILhn3kLOe8ozGtt/3WYwcsjvtleVvnGiKiLNp3nRNcx4V9teyKyHPu/AHhO egLqObZdC0c1DJU+oQVQa59HqvYOisS2HkT2AvOb1zjZRHQvPliP57PLHkAF1gZTK0R8 maZA== 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=ORwW6NKJtkcvNRg75osZkFJLGKn244V6xVOH9BtTN8h9wCv/vcjTFiJVP4V4KRBFxE gd+BI6qcfyYA4rFQaI7IZ5PQxsafGq3BHNWdPRH/qufnCfk73iHAhM7aR2BORwvwhRYx TjAPaeZ8iJY4RGm/pKhrcg+jhS6OTJn7ggCZfz2QCuBKxBAVqg6vXTrq+eFNGBagDB/f 12RUDau5SsVnWvA4uO/+adZyIe/2t1W15ZxwWKH+w4wREbl6/moRxPg+tuPGpyaMIZlx sPHpL5bDnRy4KvOBH9Lo5CwKzjYvdVWvZHasHkr7hydyU6ndDyRb/DOfoTazNcHYBlT3 N5ow== X-Gm-Message-State: AOAM5324g8F9zii25jXUW1A0Bozii/wi5PV9weSFe1M0st2cTF6s3tt1 quBEPIoXqaWf7CvXz3uZOi7OSmx5xjy49cUk X-Google-Smtp-Source: ABdhPJxJAFr0JUaS6cov/1LQ671Bk+7vDG2Ga/BMZ0JmrVqdOhTUGXlMYCYdV/jZkdtiFba6kZf34Q== X-Received: by 2002:a4a:b40a:: with SMTP id y10mr3402836oon.71.1601675999237; Fri, 02 Oct 2020 14:59:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 1/8] linux-user/aarch64: Reset btype for signals Date: Fri, 2 Oct 2020 16:59:48 -0500 Message-Id: <20201002215955.254866-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c41; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc41.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676193; cv=none; d=zohomail.com; s=zohoarc; b=fkgFGl4MsMD9r2cxjYaHYcePZfzgNBZ7jKqxFITIwlX7zTRrNYmJ5r8Orfv7rSkGUup0ODFqlX6TPRm+L2FIk2RJ5O9JRD+XQ+TshEKd1Ot0U1NfYARVRSzp2igHuJGgq0HHxdzmX95o68oyyg7Lbk+fp9ceIFN4j5CaxCM3XiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676193; 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=1sPywZydkzNx8f/80GoSubL6qkbD2bze0L3zxjjn9Qg=; b=l5sb5+8UQzuWnz3ootdJor3cn+GmA1LVVS2fLL1ovmf/dVQ+ff83Mw0WsU+9dLiclCQh+6iRva5n8IWpn9XBVUdLae98Qt64p/3US56T8N+fvL4dhiKUI8hCFvUTNbh0mlliTqSHvwr6wleh+tmDdphtzaWmNssNgUZJA+rLXz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676193314477.1497997261275; Fri, 2 Oct 2020 15:03:13 -0700 (PDT) Received: from localhost ([::1]:59168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOT8y-0005am-4Q for importer@patchew.org; Fri, 02 Oct 2020 18:03:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT5w-0002XP-Tw for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:05 -0400 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:43018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT5u-0007MD-LK for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:04 -0400 Received: by mail-ot1-x342.google.com with SMTP id n61so2857489ota.10 for ; Fri, 02 Oct 2020 15:00:01 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.14.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00: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=1sPywZydkzNx8f/80GoSubL6qkbD2bze0L3zxjjn9Qg=; b=sXKo8YEznddVXahGBBUB8MPdd7uVD5frA0ogbMV72F3DEGzKYBnPZOI4QkE9G+i145 /3TrWuQ7jrfBdZMCf8dHn4VJk3pxhcFX02O2cwDbbY7gwhQFOB715Hqv/Yba9kTkx4Sx Apz+hHB5vkWNEE3YQZKFPcxiamos5mcTUro5/3sxq9HiLThhY12IaAGoWLfTxrERIOWI JwHtKDttDDQ/irqqhlj1nJdpRwBM37k59LRnFhDx84JWMnhMTmh/KxFWi2fBz7hebHsm bVK5lIiVhhMuj7qWDb/p87AfIrtnwfsrkT8whKj36rAbABAA43tFvfE7BgclYkR3inT+ 0YAw== 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=1sPywZydkzNx8f/80GoSubL6qkbD2bze0L3zxjjn9Qg=; b=a5/wqgQ4j9SUSAJWrb0wangKl2KOnmzvpyfctC4cs156WBNVPFDdzTK0ZlrCCEcvC8 gMn9eSjjNBStimhasRTuZ1ILNlc6WlKu/SgS11vnizcov1QV+KBGkx2Qrz/Wcw2gBxc2 N+3Avu0pMiDAxho4RFcqmEJx7zHF6mqSIFnJjMc+KLxD9TjunAhbaRENJH+hRGvjCcJb rIs3+vmmK/3PhqfPB62g69bNVk2NCILJmUqdL/WmGab4EwvmyXaq+eTjXn+9piz2/xzu 9ZHW0kNqiiPX1X8fn3l8BHKHNPOhiiPbbdnpt7Z7J5hfX9hUI0IcbXiGpWsA1B4LVfQG wlEg== X-Gm-Message-State: AOAM532I4zLJ+hZkHc+kxJ5FuO0iZAMcgy4fFGFu974v2ko27wfNNiOb 9N6m4dU+Nsj633tA21L1pIyJphAZVcf6qqWG X-Google-Smtp-Source: ABdhPJzCn8lS566R5abRvl4jGA/N7I2ltVyfzG+DhtvxKIxOk3KwL9jk1anM2AM7sFxF55YOrSkK6A== X-Received: by 2002:a9d:5cc2:: with SMTP id r2mr3346514oti.63.1601676000681; Fri, 02 Oct 2020 15:00:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 2/8] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Date: Fri, 2 Oct 2020 16:59:49 -0500 Message-Id: <20201002215955.254866-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::342; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 f6439c4705..ba80c46c95 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 e4549a8cc0..a07d605c2f 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3439,6 +3439,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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676232; cv=none; d=zohomail.com; s=zohoarc; b=JC147W6p2nOWgzpMCh0f7jB72i1eQn3VExrUx/N9mLGB4W5JZ+7TNxTgQUZI2TuA4gdSz1KtsEWYAo2wcXDktsIau7cUV0WcsDrGMm/9BgkqiUte+IgoM8EJpoEu3yV4p3ZmKGWwAH7M67Dbroc+HVweB9jHTneRi2yeDYqeIb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676232; 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=b582sVKB4NI/6pbEcxflY4fbmZV5eSShsMwBazm8vfe1niM81RPbfTYVFzLvNQdfoF1mEZPZGOxfAqOPeYgQJNsyDM9FS8r0ZN4rN9h318Wgfw9MsMCWihRR9JQ4t2/JtGmTdJfR+WSh0wLR2i52WKsnUQ2dIvdSXQup7rqR/BY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676232355614.6192378012857; Fri, 2 Oct 2020 15:03:52 -0700 (PDT) Received: from localhost ([::1]:32826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOT9b-0006Mm-2L for importer@patchew.org; Fri, 02 Oct 2020 18:03:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT5x-0002ZD-Uw for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:05 -0400 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:41956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT5v-0007NH-OT for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:05 -0400 Received: by mail-ot1-x342.google.com with SMTP id q21so2871347ota.8 for ; Fri, 02 Oct 2020 15:00:03 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00: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=8JkogZW08o4QbERarC4qat0jsqD9fmDjl7gKGBrUP6I=; b=c3RN+aji6elqAzxQuRf0rQc9a0thf5PgQZjIrZc/eCTeEInfcnBayDCUPLQdNLtcR1 6GS+qYB4TQU2KQ5QtrmvAGS/witbEbPSItSYWJwL9W5g9NYEbG3PrhB/80XN9msaE8UI LHvkKV3KoWXYHgrzoateQGCnURj4VBRz1izfuNx6AKYcZOGI2ta8749jvX9mFgvv3rhM 7vfZipBVPVe7MZHEPvQgPofnUuVdCnnwdZAmp8XAH9FAig0lVO9VDz6Qn6yy44mBdLQ6 TVLNluaFsaDjmbFNatPCApTYCmcf9/kLvjQi1/jQ3T+FQqsGa8wNcfLgZgMwIDtmOAJf Oe9Q== 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=tQksylTTfUGzpsaQ7Qhzs+4I5baquN3e41n6dP6sspP7n9SOfhbFspVEgQ1ruxE/Yg Y7u3xTVv5jUf4YsmN9xI/ddxTZkN3xkAEmwpr1IQjCb8FLRw0mM2lsFieyeZ760ANNyx GAfzV3WZTcBNpjwXJ7jvrOS6SMIzbWAMtLejSfkrNgQZGPUEg9oxcszjfSPso1t9iCTb /UwZQvFuR4VOYY6ifE/CsceoDXa0NLToT3FF/Rt2IG0rTM+CuXwOPgmcz/iFqXfnTU+H HXWtvg0iysjnndkhsnr2X8jHTmwDe0KMKzqhRYEl/8q6rlGzon4SGevbAhJgANQXDJOV EYMA== X-Gm-Message-State: AOAM533xXU2qxhYVPa2jbrIdNV2xOfy0oyaoHjOxMS0hESXhf1AHsyLH FRFDJHbu46xqF7z2+Hus/IcT9kS54vvt7FUy X-Google-Smtp-Source: ABdhPJwP9J3brY/GoD1M9WbIcvO7jrfA7Gsjh4ejWLvR0DZsLiV8lIDKBxcu9oEVC8I/GFI0WBQaqg== X-Received: by 2002:a9d:1442:: with SMTP id h60mr3387353oth.35.1601676002120; Fri, 02 Oct 2020 15:00:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 3/8] include/elf: Add defines related to GNU property notes for AArch64 Date: Fri, 2 Oct 2020 16:59:50 -0500 Message-Id: <20201002215955.254866-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::342; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676297; cv=none; d=zohomail.com; s=zohoarc; b=Tw9j7qljU83pZ0PLzPlAaIQofjSyvj6gIm11/CwEhdJh/NckYyAC62gU/iOk0YLGTVVndFz3QKjYMzMHZLw4xeyCly16YI744I4Ezehp9YSLbASSw37+kze6COPV7JkPlLviIDXiZ9LwI4NcerqvwYwwxNHbL3G/gpWLhEKndvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676297; 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=Qqi4bkkjlO0OmQq7eFe7VQbO2qUT9g9kE2iVHKsaR1Y=; b=E710e5qcQGcVEQOPxCUEFTP0Z4YI9vG09ucaBN7dR8+HSpnLapQppRYo2euVGLJb+4wliXmyTFTxhoVjg4YzvxHnVtJglu39oRU0BiuHEwGTm437IAq3aKTUsJnHW+OeSiDSTX7lx223sTt8iKmxlNimxG4crAuPLFUwd5uBCT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676297430865.19444460026; Fri, 2 Oct 2020 15:04:57 -0700 (PDT) Received: from localhost ([::1]:36626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTAc-0007zI-1k for importer@patchew.org; Fri, 02 Oct 2020 18:04:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT5z-0002bm-GR for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:07 -0400 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:40119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT5x-0007Ok-L1 for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:07 -0400 Received: by mail-ot1-x341.google.com with SMTP id c2so2882297otp.7 for ; Fri, 02 Oct 2020 15:00:05 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00:03 -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=Qqi4bkkjlO0OmQq7eFe7VQbO2qUT9g9kE2iVHKsaR1Y=; b=D/tYdAfSWu0ZA5cfpaVheM9LeiEXdHESrKwiijJO4u4y4Hzr7YKDhdI6POpbmRmMDT HYJ+tI9rpda5rPj6D+yfeQAcIc4GawSxyqowSJmLtGFLMMiCjCGpuPQXsGYSyx9y2od+ sTkbuVKwsBtlUkgL0tSE/zdtYlTqC9a6cFgnft1PcNoHUkMrE7PpmcpzyBHW2WhicfsR V/ucHr8VACjlh46A+RsaH7BGekU8rE1V96T+HF9grOOwVNyC7BI1VhlmZA7940RHRTY4 JnP8fzh6SCp8HMLP8Wozvu7MLeObRKKRX6Ex0EPFA8uShLnuise4tc7NbXS1OhzG0X5x aXrw== 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=Qqi4bkkjlO0OmQq7eFe7VQbO2qUT9g9kE2iVHKsaR1Y=; b=Rkb4e7yRFVqSWHe2BVWDP6PbdlMRQxliEGMmLKnGZsnmTT7DUVFMUx70mKAnYeYYeH Ntz2hklMsvkZAs9q6dJZWWpwJc2F/gdmE0m0XZZoluAql7Zq3RrecvMvf6eCz5ugsfyw 4pgE9dGJef5FcpMSVvLHbmu8DtObj1R3T0Ofy5W5P7OSBHOeYnNmS0rk1IRxfHbg1qVO N18BNvpgTZq+0zsFJIulOedt2It5Ors9KQ0aHmR5Wn1xM6ssUjkJwE6hwop+A96We3Yd VeJTTlHORwXJBro05FV16Z7jeygXI/LALfLlC2yDjU2vzfUY2YGcUKZGKvZpgzcpgaM8 cA8w== X-Gm-Message-State: AOAM533OCHg/WGtR+OkbpaDpAaPszM6v4kOM3+o4ue3CMSeOebjejdAN PKixokk1oUqGp93aIiCh5XKwt5Mar+ziTTtQ X-Google-Smtp-Source: ABdhPJwOMMrY2zqmaVeVWtgvqkV+NEiKiqKLMo/z8+xqSqfWlq9BoXCLN0wwVWtoAfApe2gWmoCnnA== X-Received: by 2002:a9d:4c0a:: with SMTP id l10mr3189312otf.166.1601676004063; Fri, 02 Oct 2020 15:00:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 4/8] linux-user/elfload: Fix coding style in load_elf_image Date: Fri, 2 Oct 2020 16:59:51 -0500 Message-Id: <20201002215955.254866-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::341; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x341.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, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fixing this now will clarify following patches. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 f6022fd704..7572a32a30 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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676425; cv=none; d=zohomail.com; s=zohoarc; b=D3WJoOmBt1FWw5JT6+Sm2JpUTgsL6JYQ3MrUoamKyTZNHjD838u9UDnZYIsYwIuswiJZbXsWFshR+f862pjLETQt9oj17WbGZ+/cjc954PjMTuo1xz4iv+cGuEXksgje/xnsg5vu22+YxW9IyHUNqW4mIIyfTjCZZXQVFu+eAXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676425; 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=alZjlQJXj3PE/fgiElfGG8lmZ092HOwXFHnkKr7NfsI=; b=eWY/hwbPW67cZnHmvV9svG+NJnHlD08yXeboawknZL1+hnVV5h/Jd8GnzgwHnucaVFeacY0/Z/XkwUGVmVaS/ECMyzPFcFZ9JEwkgZ+KihtUDK1hVva75MXWWApt+qVRQfm+OeMwLstz0yLX50ULpjwoMNGqspChT+FpMbJshH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160167642573284.75879435127729; Fri, 2 Oct 2020 15:07:05 -0700 (PDT) Received: from localhost ([::1]:43044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTCi-0002IS-AO for importer@patchew.org; Fri, 02 Oct 2020 18:07:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT60-0002e1-Qg for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:08 -0400 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:38063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT5y-0007P2-UV for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:08 -0400 Received: by mail-ot1-x342.google.com with SMTP id y5so2877440otg.5 for ; Fri, 02 Oct 2020 15:00:06 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00: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=alZjlQJXj3PE/fgiElfGG8lmZ092HOwXFHnkKr7NfsI=; b=eUcdYUiSmOLmvla2rtrnuoi1pzh744TEe44bOlVtAgw8+NvZVdc2bXArY7DuelD04O w7HJZP/pzKf6r1dsQao0tiJrRHLfWnjkwC9uc3QH67sWTA86DEYlJz067luFaKvLq7OL sJ1ClV6tg7+8TeKee3hbBrH/fLpIIPmY6Zeo/R/f0JhoCXqpgxfDXWJAvoKdLQ06RDim m73XpI/AbFBU4Mr7JYbL3np7yJrPRPg7UP/+8b2ALXAS/iZrJuAi1RHCcwiVmpEPZU35 LYwO5bryl+f5gtz3u5Hz5jn2ilyeBJbwm4qOrtsRlwOIzApbvwuEgkaXL3KKJut8s7Tm sBSQ== 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=alZjlQJXj3PE/fgiElfGG8lmZ092HOwXFHnkKr7NfsI=; b=tGGXb+55+HQounVAC+A23dnzfpv/8FqyVfWCvgL0/1drXc7oNL0IXvenSP0nm4s/lC 0kRbFwWowUj7LecjtuzWETq8Hsc/efvO4+slii2ZMkV6jIpguKLkKEIbKYuWCeAb0Ulz 2Q+cyNpWjKqQ79JOfE7dprOJ0o3ovotpUkiMKGqnVEtFkmQnWVMLzt/N82491EemwFpT NiPeR9agBom5elwM2FMK1fDPdFVhxr60DA4pFW60qg6yYMjlZOWpgr2ElSHt5Dtw/AAj WGXffOpiRv/a+vaTqIpj7R0wkTYz2zGXp6CcNRWwsyianNADBMgyuWTwwUu7teJu2GLe oiKw== X-Gm-Message-State: AOAM533peehMGX1sN5PLBYU7c18YAy/BN/hz3/D84kUcOkwy1ggjHVci ghpZTsaO+fEHL1LoqO+C18EBb9tCQMGrm3QA X-Google-Smtp-Source: ABdhPJzAwkqMnyDkaRt2Hhi7hKZSwOFDBLSrdfxuy2ZLAyLSRw3vxCSGx7WK8zk2WM+41m87kzuNww== X-Received: by 2002:a9d:a24:: with SMTP id 33mr2921358otg.305.1601676005510; Fri, 02 Oct 2020 15:00:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 5/8] linux-user/elfload: Adjust iteration over phdr Date: Fri, 2 Oct 2020 16:59:52 -0500 Message-Id: <20201002215955.254866-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::342; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 7572a32a30..735ebfa190 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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676315; cv=none; d=zohomail.com; s=zohoarc; b=hJtVYQCx8x7WAHnkGuaHvqt+uzVtlDHiOBQlxlwc1ZyfovkeJG6fTNoqoiMj2NRsDp5qpiKMWoknS6xc7Mck6l2hLPkdNEJ9ka2+HVQngGz5YW+gIjSd5E80h/IYgUmwvqHej+1WkZaJ/HdRTo5QYvYKVSmCZuQA5P/srsiQ+ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676315; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=KYhfHNn//10KIR5L4tIJgRMzKL8TABQoExSxCWZe2WWAUcf98wj8o2D4uW7UzaAkZnW8Fi4pqkwri563FBFX0tsOuoL6uYHI4UjY0LBf2JZObJsUpJvI5mD8sCOjrvuCsMqtX1rO7bOgbcdBLwiKD1xJVj8XZBnNMCma/cXwx5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676315883329.5017810366036; Fri, 2 Oct 2020 15:05:15 -0700 (PDT) Received: from localhost ([::1]:38232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTAw-0000E8-Iz for importer@patchew.org; Fri, 02 Oct 2020 18:05:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT63-0002hk-6x for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:11 -0400 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]:41305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT60-0007PM-GE for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:10 -0400 Received: by mail-oi1-x242.google.com with SMTP id x69so2722590oia.8 for ; Fri, 02 Oct 2020 15:00:08 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=JCe9wMsrZyC3phlm+nCPDYtTM2wgzzXqQeVhag4Fj3984KbhMy/YCPnTQjD5V683ek 80XUY8dr7UseqrBnHBh6eWTf2s/VIHtLkOqqLbF5zXwRbRMPZt0mBlRxO7efMVcAQzi6 BT6QjzAwGnJZ5BMr6zybhOFVpOJ5Q3JyM3ngN6Hb4FToUgKzO0ToJGOrnSow9pQ1qIBV u2MS0ZOQWRJK6mka+A/Gn2JTVkxEyq5C7OgpYg5ydfHRrUkpB/kkRV0zIyF+NsYt12G/ d5tMHQSvmeahqTNqfssPePXXKTVOgvZ+AMvDNA8R0j/3/ATySk3IYWEn4DIUFao9GG9x IRww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0BbDoe9J1HK0fsnnyytHHCY6uKzAPenEs5cQszBMvV4=; b=rlaeZZc912kXKWkaNcx4bfysLCDeEDhfeQ7XD5sELaHFxSEcVApx5BN+b/PujcqoMs EaYsZCpSfknpAijn4bOjzt2GNeKlHo4JmalHPEZx6a4jQ4nfGBAgIg0g6m0GyjdAB0cn GmvbNwb+/KIduSOeh15v0uCvMMgNPeGgyXvflplyhMje4wGQjCfUrGPJoLfByFEjPFNA MymDB2nkzihkTntL5Brd1WuANU6YE0uIAPc5j+lcasxTslwlOKK4rrpofC00BJL5FpKm pJ9SjbyVeyf+GzqWMu5IEEwYe5cPyxb8Q1iV3cBsVT+Ez9oRxadcYVzecYBVvrxscrPN jM0A== X-Gm-Message-State: AOAM532KTBpUUL/aGZMczJ3PNo89XbjXNW7AeJ+Kd+c+n5XnKQbg5VwO ioJaZ1ZMfIqbxt9Rm74piVddNJN8jstnt9YW X-Google-Smtp-Source: ABdhPJwGR+b4eiNsToawk3uOhGkWc/zWtEQm5DkyAXxEm9dRSKNuhaVjnQOtySeTyCt2zBPWkufzFg== X-Received: by 2002:a54:4d88:: with SMTP id y8mr2501987oix.97.1601676006853; Fri, 02 Oct 2020 15:00:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 6/8] linux-user/elfload: Move PT_INTERP detection to first loop Date: Fri, 2 Oct 2020 16:59:53 -0500 Message-Id: <20201002215955.254866-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::242; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x242.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For BTI, we need to know if the executable is static or dynamic, which means looking for PT_INTERP earlier. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 735ebfa190..6b422990ff 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2421,8 +2421,10 @@ static void load_elf_image(const char *image_name, i= nt image_fd, =20 mmap_lock(); =20 - /* Find the maximum size of the image and allocate an appropriate - amount of memory to handle that. */ + /* + * Find the maximum size of the image and allocate an appropriate + * amount of memory to handle that. Locate the interpreter, if any. + */ loaddr =3D -1, hiaddr =3D 0; info->alignment =3D 0; for (i =3D 0; i < ehdr->e_phnum; ++i) { @@ -2438,6 +2440,33 @@ static void load_elf_image(const char *image_name, i= nt image_fd, } ++info->nsegs; info->alignment |=3D eppnt->p_align; + } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { + char *interp_name; + + if (*pinterp_name) { + errmsg =3D "Multiple PT_INTERP entries"; + goto exit_errmsg; + } + interp_name =3D malloc(eppnt->p_filesz); + if (!interp_name) { + goto exit_perror; + } + + if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { + memcpy(interp_name, bprm_buf + eppnt->p_offset, + eppnt->p_filesz); + } else { + retval =3D pread(image_fd, interp_name, eppnt->p_filesz, + eppnt->p_offset); + if (retval !=3D eppnt->p_filesz) { + goto exit_perror; + } + } + if (interp_name[eppnt->p_filesz - 1] !=3D 0) { + errmsg =3D "Invalid PT_INTERP entry"; + goto exit_errmsg; + } + *pinterp_name =3D interp_name; } } =20 @@ -2590,33 +2619,6 @@ static void load_elf_image(const char *image_name, i= nt image_fd, if (vaddr_em > info->brk) { info->brk =3D vaddr_em; } - } else if (eppnt->p_type =3D=3D PT_INTERP && pinterp_name) { - char *interp_name; - - if (*pinterp_name) { - errmsg =3D "Multiple PT_INTERP entries"; - goto exit_errmsg; - } - interp_name =3D malloc(eppnt->p_filesz); - if (!interp_name) { - goto exit_perror; - } - - if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval =3D pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval !=3D eppnt->p_filesz) { - goto exit_perror; - } - } - if (interp_name[eppnt->p_filesz - 1] !=3D 0) { - errmsg =3D "Invalid PT_INTERP entry"; - goto exit_errmsg; - } - *pinterp_name =3D interp_name; #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; --=20 2.25.1 From nobody Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676400; cv=none; d=zohomail.com; s=zohoarc; b=gxCH8YN9kWblSmJ5+UNi5NPWfxkJfNLTVoRglH+RmXHcNufXGlcbt8L4+rm28NDRxRw29qlHnO5nSQoZNZLEqobv98R2x3Dg4dGa4M6eDkX8LST/8B9np97cggBNWBAEGUJYBTDcheufU9O/pBT7D1WaGgFn1/ZbvrGPpL0JG7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676400; 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=UmXRKUbKgXmhfW+77FLjDFzejAZSQt8OzgtpBP6qGqY=; b=RnOyT4ARs/+PHLGQfSmx156Z+wus35dCyrSbOVm9D9SPECGZ+QumZxNGAnIeSiKBHSjWolkY6teWgosNn5J7vVKXTKMJDNtpPDLNuvZQOBn5TMWp35mKxwubE86cE7yLtDKQ5XH5WuhRZjoRSO0fPhkqkWo8xbc2XTBUviPbwuo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160167640080283.6027226607282; Fri, 2 Oct 2020 15:06:40 -0700 (PDT) Received: from localhost ([::1]:41936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTCJ-0001pr-Fa for importer@patchew.org; Fri, 02 Oct 2020 18:06:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT64-0002lC-LQ for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:12 -0400 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:45134) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT62-0007Po-18 for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:12 -0400 Received: by mail-ot1-x344.google.com with SMTP id g96so2861603otb.12 for ; Fri, 02 Oct 2020 15:00:09 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00: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=UmXRKUbKgXmhfW+77FLjDFzejAZSQt8OzgtpBP6qGqY=; b=BP9MX9OcYQH2u/z17O9RrczsPMQ4PpIEB8DQmSSOx1zKmX/5WSpt/Ojh4Y3NO7nB63 33789GG/tht7XCnfIGeByLbuMdrT0jiwA2xd00qJOXP2VQUAXV7xKu9++1L3v2JdnfnE BPDkUWSorIPaPcYfTEJKlTNuM9gMcekeOl2C81xfdF4GBjCfqnzx2mQsWMognZHs9XwS OnPkQbzqYhla/23ucPpCmhpTGeVY2NUfrqop1MWtEImjf0sdleiQcYcC6XKVpivs8agz YDUNJ3VR+QHNKJygy857y4Yvt0omcIFPZyXeigtJh6LLOJxkgrfjcMv86zT+MhrFEDSm fZ3A== 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=UmXRKUbKgXmhfW+77FLjDFzejAZSQt8OzgtpBP6qGqY=; b=oZ8FXl8qEq0TYQjYQrCCLulSpViGFKWYsXBSixhPQixsdmIDCPXab2MrzoHlDKLbo9 zJGLKo29wdrKo5ybmt+X+RRFT8xn8SdHSLfp7TQJtEMfQ+NfOayCBvRTQqI0bjB+ouw/ iVNejvU6P5YwCUbRvfVd/mV5GGiAnkFVtBDiX0aVkj3iGlaqvnh8bi91MVDpSzT393bW x45rlRX5EkMjZ1Z7lXfN/y9LX9gX0qwLU3RANG2b2LNF/hDW8yVk7puq6zZg7QXZXdIJ G1nVzFwwe2qHiPTYM+Gx7tZXiJ7rphoctgUe35wSYLMnzrrmnbP8j47+oUy81V18RkiP nVcg== X-Gm-Message-State: AOAM532vfJB5yY+M6p2Ip79pjbwUp6pxL+rCd1K5k4lsT9mstm7pvJNl H1P/FFFi4N2G7YUuRonMeGijcZ4MRey5Dzgq X-Google-Smtp-Source: ABdhPJxWQWgHqeHeLP9AZ7TlKphAE28bQei1LUV6m367BQpAYasGUBryOfDcMJHgROyhEPcNsD9ZpA== X-Received: by 2002:a05:6830:1ac8:: with SMTP id r8mr3071904otc.70.1601676008387; Fri, 02 Oct 2020 15:00:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 7/8] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Date: Fri, 2 Oct 2020 16:59:54 -0500 Message-Id: <20201002215955.254866-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::344; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For aarch64, this includes the GNU_PROPERTY_AARCH64_FEATURE_1_BTI bit, which indicates that the image should be mapped with guarded pages. 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). --- linux-user/qemu.h | 4 +++ linux-user/elfload.c | 68 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-) 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 6b422990ff..3c6cbd35c3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2391,7 +2391,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; const char *errmsg; =20 /* First of all, some simple consistency checks */ @@ -2467,6 +2467,50 @@ static void load_elf_image(const char *image_name, i= nt image_fd, goto exit_errmsg; } *pinterp_name =3D interp_name; + } else if (eppnt->p_type =3D=3D PT_GNU_PROPERTY) { + /* Process NT_GNU_PROPERTY_TYPE_0. */ + const uint32_t gnu0_magic =3D const_le32('G' | 'N' << 8 | 'U' = << 16); + uint32_t note[7]; + + /* + * The note contents are 7 words, but depending on LP64 vs ILP= 32 + * there may be an 8th padding word at the end. Check for and + * read the minimum size. Further checks below will validate + * that the sizes of everything involved are as we expect. + */ + if (eppnt->p_filesz < sizeof(note)) { + continue; + } + if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { + memcpy(note, bprm_buf + eppnt->p_offset, sizeof(note)); + } else { + retval =3D pread(image_fd, note, sizeof(note), eppnt->p_of= fset); + if (retval !=3D sizeof(note)) { + goto exit_perror; + } + } +#ifdef BSWAP_NEEDED + for (i =3D 0; i < ARRAY_SIZE(note); ++i) { + bswap32s(note + i); + } +#endif + /* + * Check that this is a NT_GNU_PROPERTY_TYPE_0 note. + * Again, descsz includes padding. Full size validation + * awaits checking the final payload. + */ + if (note[0] !=3D 4 || /* namesz */ + note[1] < 12 || /* descsz */ + note[2] !=3D NT_GNU_PROPERTY_TYPE_0 || /* type */ + note[3] !=3D gnu0_magic) { /* name */ + continue; + } +#ifdef TARGET_AARCH64 + if (note[4] =3D=3D GNU_PROPERTY_AARCH64_FEATURE_1_AND && + note[5] =3D=3D 4) { + info->note_flags =3D note[6]; + } +#endif /* TARGET_AARCH64 */ } } =20 @@ -2555,6 +2599,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) { @@ -2568,7 +2632,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 Sun May 5 20:14:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601676462; cv=none; d=zohomail.com; s=zohoarc; b=JnOMASKLhMpPXmKAjaNgK2ujbOMfEiaaZ0C3G8n2AHo/KMI9Y7MW1splO7NRDe42z1Ivl9TzGIPtfWbYXkfhjCkTf5vtakbe99BP6xysQuPBxIeKvXZVq3n7vX1v0JMcDHVgkACThx/rlKcq/RaSI6RQEsMB0BmU2o1ESZxkrN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601676462; 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=S4v0KO82Wzlx0JZkhGIkBUAKLry2EN5cCldjJF9G/o4=; b=NIvbUMBJ8PWMWbOHP6QvbzyBTi2/T9CplrAkLEUh9xiwGUZkbXZdPCm7R2kzfPG+dqL+Afz27WnmOgfJE0W99LakRF+zQ0IwePL/Eto8A/MpWyl5qRIZQTM52iTxtAhgabRdmWP25yK06Yp7jpJLX0Naqv7rUuuww7jhJTmIdP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601676462766781.2933825339225; Fri, 2 Oct 2020 15:07:42 -0700 (PDT) Received: from localhost ([::1]:45374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOTDI-0003Ij-VZ for importer@patchew.org; Fri, 02 Oct 2020 18:07:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOT65-0002ng-OY for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:13 -0400 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:34285) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOT63-0007QF-Nn for qemu-devel@nongnu.org; Fri, 02 Oct 2020 18:00:13 -0400 Received: by mail-oi1-x243.google.com with SMTP id n2so2758170oij.1 for ; Fri, 02 Oct 2020 15:00:11 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id k10sm684268ots.60.2020.10.02.15.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:00:09 -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=S4v0KO82Wzlx0JZkhGIkBUAKLry2EN5cCldjJF9G/o4=; b=LwMqakNC2QpnD9J255X+mbTTPKvXL9QSu/A20IPVh7SQzOAMWEwVzamj4SeE9MgwU8 4OSWR+zBL4QscrJqidiP3RssFihuT5Ckfr3fH1/tXf3oe42SoIvXuCY+EIbIPq3u5vXc MXuyUJVwLj+DGfUcxbXC7O5q/kpaUzBC55jhnGsI6zYgeam8eGb2NHKBR1XkMc7OUnJK K5vME11cMvtUzJevkdaWMmzG+Rr6ilsWw0ArMYSTjtAFfQBwHIx1pJlRf4g8+T8gOY3O zwuuiHpIbKtwnFCCXqkGcJjeyWFDhvpPn7BNMpyiv53JWIvP7IFx/o0ntqmbyaFTFSjB SZOg== 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=S4v0KO82Wzlx0JZkhGIkBUAKLry2EN5cCldjJF9G/o4=; b=KEbKl8TCHdMMbWytBXRghByUSaPvgwXMy6GAVsB78DQrnfU8IhPGXMYl+ql59OnGbN jeWKTpXhWpQ7J0ZNOxIGirvwS7QFLw9/2k7haSDfeCj8fGra/WYmnRobnGFAWiu/BxoQ dqROmQGFsl5g1Dq9Ytt9OeNpeikpofV95+0ym03RaeHMf4QefdgHtyXxCOvGFd3x7Xdp ETSv+/3KLtbqH1yMbNNrCb6kRqs49Aa+9lx0h6UVuOCy8IneQztjFUOHT2nuuwJyz0p6 QFy6FmU4vJSTqk6xqsymcjLcYSEHQfhQYHar4gS+w59bhTikg674m5gPF4lJSxT+gAE2 PmpA== X-Gm-Message-State: AOAM533GBF/EvNoApgBa2Yn4vvgTWjCrrlFWbaOkuEjEcXcoRu7F4yXG iS8BcGMXGJhGHUSrZLLqsmop6hggwCbYNO3d X-Google-Smtp-Source: ABdhPJyDg5AYgtto1TjYwk96iEDlmR2uWk2IWKxajQsAfXzMXEG+9UxteMc+BygUv2Cdy4Ra8y6XbA== X-Received: by 2002:aca:5b09:: with SMTP id p9mr2381132oib.68.1601676010042; Fri, 02 Oct 2020 15:00:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v10 8/8] tests/tcg/aarch64: Add bti smoke test Date: Fri, 2 Oct 2020 16:59:55 -0500 Message-Id: <20201002215955.254866-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002215955.254866-1-richard.henderson@linaro.org> References: <20201002215955.254866-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::243; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x243.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This test requires gcc 10 for -mbranch-protection=3Dstandard. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v9: Expect and require gcc 10. --- tests/tcg/aarch64/bti-1.c | 62 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 7 ++++ tests/tcg/configure.sh | 4 ++ 4 files changed, 124 insertions(+) create mode 100644 tests/tcg/aarch64/bti-1.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-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..491683e91d 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -25,6 +25,13 @@ run-pauth-%: QEMU_OPTS +=3D -cpu max run-plugin-pauth-%: QEMU_OPTS +=3D -cpu max endif =20 +# BTI Tests +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) +AARCH64_TESTS +=3D bti-1 +bti-%: CFLAGS +=3D -mbranch-protection=3Dstandard +bti-%: LDFLAGS +=3D -nostdlib +endif + # 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