From nobody Mon Feb 9 12:44:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589995786; cv=none; d=zohomail.com; s=zohoarc; b=d/MfO2KIgNGfsUVnzfJDbBj7npfkuWfBfxyFSbGdVIF/z9aOBNEyR43vZT65i/MGJxepSljY6xQ4t9qlSNRNbiMKkspuMvY29n6irf2YIK5yJ7kHT38UZphWcQhpfPn7Rc2Us6QKF/C6o1AcKzRe9iLAwFt0S6v7kxRkvjEQMNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589995786; 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=btSVOHjKygqtDtrb1dFrs4ZFhT9VU5bMtTLVHWgmpDQ=; b=lWpkVYdInRNQceTSd2qXqckgpzQI+ks+E5BKKX3AW5oS/img80KR3herjjOTFDXLsIE1uTqAjhZjPbU5xUAmcxN18rvqEfJQjvvjUmwNVUsf8q/pxlPCNek4DP/wkb3tZB9jD/YCoPxF73OSChty+b5N1nrg/9VsAvgJMHFeGuQ= 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 1589995786953790.9109826813473; Wed, 20 May 2020 10:29:46 -0700 (PDT) Received: from localhost ([::1]:39860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbSXJ-0004UR-Kl for importer@patchew.org; Wed, 20 May 2020 13:29:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbSVl-0001mD-EY for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:09 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:44386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbSVj-0004JB-Gq for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:09 -0400 Received: by mail-pf1-x444.google.com with SMTP id x13so1880900pfn.11 for ; Wed, 20 May 2020 10:28:04 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id k18sm2643672pfg.217.2020.05.20.10.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 10:28:02 -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=btSVOHjKygqtDtrb1dFrs4ZFhT9VU5bMtTLVHWgmpDQ=; b=IEexihwJhok6sSzixqByIreJXkjn5IhkGZ88k+gM3aw2vVfJKUyExUVNx6v1VW5WM0 nLtYfm1S4DtjJNX6SdfyI8B+6j88A5yR6JDlDxSdGe8iN47zv5K6mU6JPhxwF8YTcz1n oSkbiYceIvrfbUHWzBRQU2ecQxjez3VnSFPhVMXg1/PBuctO5egGfF+r27MSflCm5l+d Bv7gS1RgWLhSr8BdtSGr2fSVxDAoCNxPca9fjhaKKydJG3gewT601AJKgFZfYjh4afVN 7lsQ9uDjLC9+lbXGBEoS1hTapWluNDP8WV6tqe9KfGGxJ1gQEMZ3xWzQhbSqD8iGbYwO pNew== 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=btSVOHjKygqtDtrb1dFrs4ZFhT9VU5bMtTLVHWgmpDQ=; b=OOdVpRcp4Hqft4O21hZuOkwc+o6EJpekqFu9U1o9idbvJ+U0jtqyOsuUasy00g1/n4 q00m4aXCTyKxhNM5rm7lp6Pv6HfWRKBlL0Kos7EnQnn6Ll4ftUBd45Q58hcDJtU3GzgT IIjz4BA+3FLyZR4GzlPBKNCOJjOtyZxbVtAhIBnOwqgulAwPrKGhrswyGukczqE6m7Xt +1QUe968G+oDHiOF++UBxBAR5RAUbMbnhkUgK46bIUYRWCHSUnVvIxGQ1p0gxSWsAo8b 71HssbvBduxVI3YtRx2e+8XvekaRZHSzW1grk7FCW7YP9pluGAKHP8ze8e5pXI9gaFh7 a2oA== X-Gm-Message-State: AOAM531zgXUOnVcasdrjEcCwOTwPvRsMxeXq+3QNVeSUt7iDtnrb4mRp FfiDfwsGs5Dr0aFzPqqNAF4SHC9bb9A= X-Google-Smtp-Source: ABdhPJxcIGcJ7KmfWlS44oZQBEJTuhFKAsvLYU3nS5QefUJrP07lBVvX477CTWwm3jV3ZivzlpZThg== X-Received: by 2002:a62:1681:: with SMTP id 123mr164618pfw.306.1589995683431; Wed, 20 May 2020 10:28:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 1/5] linux-user/aarch64: Reset btype for signals Date: Wed, 20 May 2020 10:27:56 -0700 Message-Id: <20200520172800.8499-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520172800.8499-1-richard.henderson@linaro.org> References: <20200520172800.8499-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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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, alex.bennee@linaro.org, laurent@vivier.eu 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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 cd521ee42d..2c596a7088 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.20.1 From nobody Mon Feb 9 12:44:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589995744; cv=none; d=zohomail.com; s=zohoarc; b=Hlr23c75geZsvOuY32HcTv7K3uYJoFNxmpX1UjWpbHmVE19Pi8fKu/F4do2fI2iKFy3lrdKDw/fx5FMo5PaE1DmaEWAO0qllsOT6pbN0afflbLNCTkCMebR/zV31oJ9pnjRAy2ZY9nuk5LHI6vIwrenVu31b8FiPnaJsyIB36xU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589995744; 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=HKxQYKn1u7z/RK4+55flzx7HAaMyO56swf2SUfshigE=; b=YS/anytRGIBrOWEduv3TjUF2pHIcbBIaGdHUYoH3LlRKoWmVrMcLBG4r6Sq4WBkyE+sICOuVKPhOxoQO3wKsIbZu/6vMIQ1rnxrRWRMAwF+UdoV5zZqCPOV9aaz3agFwuzSHdKpyUVREO/ES8SHd05Hs96yliDUYTEbyu44fEQE= 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 1589995744565692.6466902202759; Wed, 20 May 2020 10:29:04 -0700 (PDT) Received: from localhost ([::1]:36848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbSWd-0002zH-Bx for importer@patchew.org; Wed, 20 May 2020 13:29:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbSVn-0001nY-1f for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:11 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:42795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbSVk-0004Jc-WF for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:10 -0400 Received: by mail-pg1-x542.google.com with SMTP id n11so1740960pgl.9 for ; Wed, 20 May 2020 10:28:08 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id k18sm2643672pfg.217.2020.05.20.10.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 10:28: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=HKxQYKn1u7z/RK4+55flzx7HAaMyO56swf2SUfshigE=; b=TbdUyK7yK4ZcXDwj/BP2LoxFLwTrffIjbVH2R87zzXBY4inMMo9OIT0QmwYuOHWI+j iUhoLI4y9ABCafwzhLWwHTUMPSlzaJ2S/p6Y/HpAwSsbGLtuJEUi/X4IOzHVS4M/bJk7 GVhzXN0KyoLy8LcqeCG69lOiNm9w8iGgHd4eD0UYpKvg3gUu0p9jjsRumNmkYr/Qz+32 jBbGLAzsRjbrpOSuRrQq1BspzqvDYYyaaqfeyQhgLfMt5sS/LdWT1VNLLVrXzoi/vVux abUkuZQEoNAXzFXHZ8UeCkiBEiQbtMMdtwGdV4RqcNhy+U3w2rqczZke3MWJGN1B/5FL JPXw== 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=HKxQYKn1u7z/RK4+55flzx7HAaMyO56swf2SUfshigE=; b=ck3qFS8pPBXgnltwhIslGkcaA2b3ClH4sgThGOEtfwPitFDYyUPim7/YIT8m+D9sHl RS+B28tOyaJjrcaWtgEJJAQqrBifeJJApBkiyVNThlAOhcMUb/m5cQBPXJXLnuzbcws9 9RBbmD8zEcmzq2rmcqGeQ0BDHhPqBRRLXpDZ9vnRqgCEA2PlstMsx2kahsHWn6QKgA2T w5ZzRyeqwLpirDZC+TuCgQs+VyPAZfjaw+TgfvOuW4LLg9uXqBXmjaVnUf5dzbhc4dFo lDMHQiAhUlmlPpzYw6NSn8GpmDDKTnLH9lew8YA62XdUCSh7BtwYe0FhTsMJjOWzE+p/ m5SQ== X-Gm-Message-State: AOAM531x7woEQf5nT7ZK3utnoSuKmnCmgEs7X0Hl6ElMkE7KjsRNNHdE 5SWV+I9yTTxdfNt+UWyNYAr2kR0EhEE= X-Google-Smtp-Source: ABdhPJwDz3hcN4rkbz1i6YDTJKsBJNNWBlfgjBvcZAV0bvYe2ww97crH+/5xchlgvVwRP+NBoQGr0A== X-Received: by 2002:a63:6447:: with SMTP id y68mr4849670pgb.395.1589995684724; Wed, 20 May 2020 10:28:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 2/5] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Date: Wed, 20 May 2020 10:27:57 -0700 Message-Id: <20200520172800.8499-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520172800.8499-1-richard.henderson@linaro.org> References: <20200520172800.8499-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::542; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x542.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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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, alex.bennee@linaro.org, laurent@vivier.eu 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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/cpu-all.h | 2 ++ linux-user/syscall_defs.h | 4 ++++ linux-user/mmap.c | 16 ++++++++++++++++ target/arm/translate-a64.c | 6 +++--- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index d14374bdd4..2bd023d692 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -276,6 +276,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 152ec637cb..36bdafb3f1 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1194,6 +1194,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/linux-user/mmap.c b/linux-user/mmap.c index 84662c3311..40f03e3174 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 as PAGE_TARGET_1. + */ + 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_TARGET_1; + } + } +#endif + return prot & ~valid ? 0 : page_flags; } =20 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 991e451644..59ae236c84 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13989,10 +13989,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_TARGET_1; +#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.20.1 From nobody Mon Feb 9 12:44:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589995820; cv=none; d=zohomail.com; s=zohoarc; b=BQ4uUYXeXSI8IR4ES7I/TeK+uZARI253VApr0oQiRwjxXdSvHrno6T+oGqyR0kuJ7WFHzHfI2aksOhU44xHLt8USVaEW9DYYohF1YjmqcC5i52N+f6najjgWO95RI68QbmfjL1UGxfD1k8/Hae5wnCGvUAgdHTgcuXO69eIumeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589995820; 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=pfOqd0W163btym5ANgJ/IhyJiwPH1qS8Yj0O7sKwHiQ=; b=XIKzR7pXh9l9YMQhyVCArvGsjQdostluO4COkkbbt2sTdn/1kJq1xvmz+CyRP3iJEU+7G7hWNnhZaBnSDL8oYZP5WjvMCxgncuCGfx2YLbsV81e756uoZewbb8QCGcx0kddac8DIY9T55hUTlrOG8iPcihJwdGN8dyzw5cik+ZY= 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 1589995820811660.2268630155216; Wed, 20 May 2020 10:30:20 -0700 (PDT) Received: from localhost ([::1]:42150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbSXr-00062N-Fb for importer@patchew.org; Wed, 20 May 2020 13:30:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbSVl-0001mP-Ts for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:09 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:33044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbSVj-0004JP-Vz for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:09 -0400 Received: by mail-pj1-x1042.google.com with SMTP id z15so195646pjb.0 for ; Wed, 20 May 2020 10:28:07 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id k18sm2643672pfg.217.2020.05.20.10.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 10:28:05 -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=pfOqd0W163btym5ANgJ/IhyJiwPH1qS8Yj0O7sKwHiQ=; b=LTlYbEmG0y9w9EEj+w6hceCghY+eIDoYDGfg/JlUnckhcOWWR4vb//edfXBLsAX4H6 MbWFzGQ1tK6iH7pLANWBKicrx4+sGRToe6CcND+eAt//xL5pC3Yim6blMXn8nEhdI1sb QAhiM29FPK80xRqpS9U8vIlWAzDBLdpw3IWpiCgEujQVDIKSLt5m16lNZIgOO/6EfFh+ iLEn/UuTIEDUdmlnwu9CndSRXkNmQ2PLiCv3XtrzpR24uG7HncBq2KCF3xxRrhDGHCUa QXXqUTTcDfjNzu25N/hnWyrrVS2D7JH0CrpT7ryM0uYRpY46Se/8u10tTZbfdviG+UKX CSxg== 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=pfOqd0W163btym5ANgJ/IhyJiwPH1qS8Yj0O7sKwHiQ=; b=pvd0SJNF0429hChATFj9UKwngfBX7DYRGKTwGdWG2yS7OLXS18TDdy6mm/nrbqOVXR ge7bf6E7r/SOhhi8bez8bJ51shRro7qPqOSXfkeLlm7LC6C8DKFFRVBeWgnNCrepDqVw pB/3nSu9HBaGjX/6gtWUXinHHJvdIxeVxH80nNIp+1zeRu3ALTkp0kJ1TWyVTm6JIEL3 FeFWuuAvYF9PouKA9YmJxAw1FCMfxrFBCyfOytJrAe4cJESRRnZDKW1YfEx0Qs84lVtJ au0WVaFIMpWvU3yR7vdgP+lzTpKnwZnEuFYP5v3vVuMAHXeX6X846gm9MFB3bKgqFRR6 GZ1g== X-Gm-Message-State: AOAM531jusEIeUG5HqFh0hFjHFXjrvqL7iJz+mZJhHpJSowUFV4mRijh QVta6GjC10FwpM9jqo4sj20QRxR25+Q= X-Google-Smtp-Source: ABdhPJxNqcIV0IUnioOdJpCgaG42lEsXeURUrgWovlLMMLcYh4tyeOlopLH2WF3LXDPiYdTdM3T5+A== X-Received: by 2002:a17:90a:6e4f:: with SMTP id s15mr3459723pjm.194.1589995686158; Wed, 20 May 2020 10:28:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 3/5] include/elf: Add defines related to GNU property notes for AArch64 Date: Wed, 20 May 2020 10:27:58 -0700 Message-Id: <20200520172800.8499-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520172800.8499-1-richard.henderson@linaro.org> References: <20200520172800.8499-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::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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, alex.bennee@linaro.org, laurent@vivier.eu 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 8fbfe60e09..9db4aae40c 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 @@ -1652,6 +1656,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.20.1 From nobody Mon Feb 9 12:44:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589995900; cv=none; d=zohomail.com; s=zohoarc; b=kWqOojf8B1IlqdgwXiFKG9UtnNLdY9pBP6xZPipAi3z0kssHjyNFNhjEIdD6PbcZEnvig+uhpT4yOcw2k+YIpmfPKD1F1mkJ8VEEY1UwT6TE8I0QoQcCA2cykWdb5iWervhjrYvYdBmtmsInSHdWXsfVOM0U5eJ3x+tkfQKh6yU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589995900; 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=kNZVz8klhhmHc+6CSnLmSvrnq7KlJ9l7rdqsf1uPN3I=; b=IzjUp6jflDCcufJ4urMo1u3d/KjxzTxsW7JqBG4yQNIGBmJjYS12790lTo2FJbRBjUEsyXH3s8V7hBbR4I+fgfaV59TcMKlta1qDRpFZyKrrZGRJXE1A0r+AFjExT0lJbP7ldzlTX6LxfCmULxEy/DF2kRCArxJ/jwGRDLhKVDI= 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 1589995900769735.2110946006884; Wed, 20 May 2020 10:31:40 -0700 (PDT) Received: from localhost ([::1]:44846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbSZ3-0007nS-EN for importer@patchew.org; Wed, 20 May 2020 13:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbSVm-0001mw-NS for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:10 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:38053) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbSVl-0004Jk-Kx for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:10 -0400 Received: by mail-pl1-x643.google.com with SMTP id m7so1616132plt.5 for ; Wed, 20 May 2020 10:28:09 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id k18sm2643672pfg.217.2020.05.20.10.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 10:28: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=kNZVz8klhhmHc+6CSnLmSvrnq7KlJ9l7rdqsf1uPN3I=; b=Qe1KLMgobeZhDjzsypCfxSLx4xtJO1IjMquCHfYfmVljfGRz1UNRKncmsT6HSil9kw Kr6L0LLBLCtwORj3VdMJjTUjT2orsw6x2bhhZjI/SUE8zkY1e3YjUlvbdqlQyXnBs/gq T1f2PgMb+hkI5R+wCLa9b3R9/danLQegAzbzlDqJRyWLBTjEHTrR861IT/MKBya89/nj NO7NAB2dfk2P3umwbIrUJdoaD+SN+ikzTFc3VT1zxu8nvB3pT56OVozkJ6Wlfe3jBgWN OyzxNHpvE+D15PS6gYhw/k9zN8o5FBjUm96atKcWeOFNsZJniosGyJF2rHFmGqsWPw5H aY7g== 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=kNZVz8klhhmHc+6CSnLmSvrnq7KlJ9l7rdqsf1uPN3I=; b=nE1OLXM5cC8R2HWdMeRqZNpb59NqR4i6gLZIBt4XhhDdZx3OJJOO8WgGa2NQAP7QD9 opvrvRS1VR/AR9Qq3cd0n9JszTNrs97HhcOHSaQmDvgXjMqatwc4aB35ZnUA6HnLEQM3 WGppuXKbQ3gwUCcAaeQA1A7ld6Zaa9sOR2ognr24te5rfEqW7vcDfSSHdRdLx3hYwI9p bx4Qa/breKVh9onB8d5OzKunyMWyAvabv7uU9cLTbqIKHSRFwx0TdQl12HuutqApk+2N r3IaJIKGZV0Y/7mZDM7+OAygotHBU852XP4t901PpyVTPZ4WHyfANfaIzPPLQeexNo9R 5Chw== X-Gm-Message-State: AOAM533Tws8Fnd/9hLEb3UnMsVrEahCwGhC0yifBwHnh1ByoMA/mDbQg xzWyCTOzRvgUcuX5bF7+ZawkTkeV3vU= X-Google-Smtp-Source: ABdhPJzUDUW653ntcxnWAaJbI6k0bsg4nQRHnUKCSp2ZpEDQ/kv2q3xNbryAgUAtNQcVEBkOdO30nQ== X-Received: by 2002:a17:902:fe0c:: with SMTP id g12mr2833090plj.316.1589995687542; Wed, 20 May 2020 10:28:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 4/5] linux-user: Parse NT_GNU_PROPERTY_TYPE_0 notes Date: Wed, 20 May 2020 10:27:59 -0700 Message-Id: <20200520172800.8499-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520172800.8499-1-richard.henderson@linaro.org> References: <20200520172800.8499-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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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, alex.bennee@linaro.org, laurent@vivier.eu 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 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. --- linux-user/qemu.h | 4 ++ linux-user/elfload.c | 143 ++++++++++++++++++++++++++++++++----------- 2 files changed, 112 insertions(+), 35 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index ce902f5132..d36b18b678 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 01a9323a63..c84c9991fd 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2319,7 +2319,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 */ @@ -2354,17 +2354,90 @@ 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; + } 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; + } 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 @@ -2453,15 +2526,42 @@ static void load_elf_image(const char *image_name, = int 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 executable is either the interpreter or the static + * binary. The interpreter is responsible for all pages of a + * dynamic executable. + * + * 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) { 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); @@ -2511,33 +2611,6 @@ static void load_elf_image(const char *image_name, i= nt image_fd, 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.20.1 From nobody Mon Feb 9 12:44:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589995958; cv=none; d=zohomail.com; s=zohoarc; b=WRL7vpl4mof1QsbI3WkE6Z8PJ94c/5tG/hxB7G+WMtMwL6pMwCxDSGqKvgGdbJIeKUCxGTBWCmp6snXG4q4l4YiZI2R8M+gHZljftn+92v01+oBtQHc7vTcEzo2UeZhnbi3PuSV+TWICJu/m0jKeqVs60V/yyCVZXdxWo9PPKgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589995958; 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=aq4v7IxgSTWwXHpmoImcRMGs5taMUuju/WMDtCLJnVA=; b=VsuozcaiBYsc2bM7+MZsvh0HmSvTHe/shQaojVflwV2GSck8n12SnCEI3VdUxMRDNpf2HD9EC4j38H4HCmIXmjTduU73gnH+erE814Q/QART7Y3Z/FNsgros35iJ0swohAlGsVUvDPe8cQR9ecmW+DmpJJFjeE1mor2TERRtUh0= 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 1589995958002665.719499228427; Wed, 20 May 2020 10:32:38 -0700 (PDT) Received: from localhost ([::1]:47462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbSa4-0001Pi-Oi for importer@patchew.org; Wed, 20 May 2020 13:32:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbSVn-0001oo-PM for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:11 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:38307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbSVm-0004L6-ND for qemu-devel@nongnu.org; Wed, 20 May 2020 13:28:11 -0400 Received: by mail-pg1-x541.google.com with SMTP id u5so1754805pgn.5 for ; Wed, 20 May 2020 10:28:10 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id k18sm2643672pfg.217.2020.05.20.10.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 10:28: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=aq4v7IxgSTWwXHpmoImcRMGs5taMUuju/WMDtCLJnVA=; b=saSDNi8LLrzwncRHhVgKiAnvV6o6W6isX/L1jINEzyABAeYqIjH1tkDCYxx3VPzYrS 9tx+PDxN1q/SLgr7iRi/G8IYZ+XUQMOLKWXwQ+5xl42AwwnWcfBq94YfD9yVSNpbWmsS nImuU9bYXZScWvN3V0hCWs6NKAXOfkWAjTPmNaQC0BSZuIj6UQ4gKZfiHOrsTEDPMU1O b9TlLZz4P9Y49MGA9O1C2wo/2lo3tesIblGA3y3y/UDKmUXh1x+mxh0ROxNY7JrjNxXc 9ZwggUrXq9BF9bndaeDkR22YyvwcUG/GruD/ad84xP5OFFbMLKQUNrHMzC2k70vkoECQ QfKw== 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=aq4v7IxgSTWwXHpmoImcRMGs5taMUuju/WMDtCLJnVA=; b=QsKXx0XUwAKR5VdPTWKNNyWn0m+1TcEtqrzlvYpz4qEejQvIwIL7DdIPO93YivSxML KLkpjUj9ctkZW/opMIOIvTMMtCPp6XOcHGHd1q8nu7bqPAdc0ipt84mPoCszuPnNQPHa uPQHkKrZRpFPLT6QrIG8zyjk1U48rH3pAKJtMFvLMbXBIbPOXh8LOC/NVeHsV4SpK7KS JOdgYETdNP5RKxF3+e0YiRVcXcI7gE7kY0YARiBNrRduSoiopI60NPiux66GnNmlx55O uxuewA9bFT9PrMph4SodnFff1nVh72O7zNchUMKhHUN9kFmmJk1MktUYtl3uUq3VmBnS lSyg== X-Gm-Message-State: AOAM530nf2U1CZhDLGow6GOF5FzKsE2t3Bc9Vuch3ZgnkI+I9LjgODwk bBwZRDbjfrs+Q33jDmP35N6iI/rzUeA= X-Google-Smtp-Source: ABdhPJytpQpJyLk8QpzKXjHqT4osu8XJDovHXj7qF88e1k2EQ8SBPveN25S0RpC7OaZibu5VDI8vGg== X-Received: by 2002:a62:4dc3:: with SMTP id a186mr5204501pfb.269.1589995688856; Wed, 20 May 2020 10:28:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v9 5/5] tests/tcg/aarch64: Add bti smoke test Date: Wed, 20 May 2020 10:28:00 -0700 Message-Id: <20200520172800.8499-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520172800.8499-1-richard.henderson@linaro.org> References: <20200520172800.8499-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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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, alex.bennee@linaro.org, laurent@vivier.eu 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 test requires gcc 10 for -mbranch-protection=3Dstandard. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 312f36cde5..cf84787eb6 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -24,6 +24,13 @@ run-pauth-%: QEMU_OPTS +=3D -cpu max pauth-%: CFLAGS +=3D -march=3Darmv8.3-a 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 2326f97856..ebfe3e2ce5 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -231,6 +231,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.20.1