From nobody Sat Apr 27 07:24:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553909413477685.6757512074613; Fri, 29 Mar 2019 18:30:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:41822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA2oq-0005dd-6H for importer@patchew.org; Fri, 29 Mar 2019 21:30:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA2Ky-00078P-4R for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hA2Kx-0001c8-5h for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:08 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hA2Kw-0001bi-UW for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id c207so1812056pfc.7 for ; Fri, 29 Mar 2019 17:59:06 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-72-255.hawaii.res.rr.com. [66.75.72.255]) by smtp.gmail.com with ESMTPSA id e1sm2229900pfn.187.2019.03.29.17.59.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 17:59: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; bh=kqHe5v2q79iXufkRdD9H4UM2SE/bcUFqYqqxTH4VdfM=; b=S4w3Un0Rq4/9VpjfA1fLt75IUql4Dro1RWJPoZGa3FRa3WqDEzfHTRFUSChykiwO9i 0Rairegi/5eRJ9ZATbJ1YX4L8vHTTPnopbhlKsLcGKrLk5OedOESEtNrNZfw/3YO7G8y vTQE13tZ2lQZVTBqU+CGGI4Isht/V7sVdE+YVe0CjwHdkOe/KxKknw45OWVdeQODuDZu dgvjKsH1cBN3x+jncxa7vYo1n0ovWVhw5RfcrRu+cZlvpDt8ysid7Wx2bNhLCQVh3x55 v3JC5llq73ppsdxNEu2twqZpz1kfch3d6xCvWopli2+3uevcDdgSp49aYP8mHE80EheB U22g== 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; bh=kqHe5v2q79iXufkRdD9H4UM2SE/bcUFqYqqxTH4VdfM=; b=pn4iKXOl50IbZ7GoVSbjsv/Mnl8ON3KjopRu3Z/JlUVFc7JRARZZ2mTo8ErdTxrHJ5 hlemYAOzKCaj3qBFs7BQ/Qn1yAzRivJEmkSMZzdlK+GtD2LRX08dg77m8eCd8477golg Woqcr9IlbbaebBdqJdElLwVYAClISRDeUeSl9KlnmVne9U2tizPysARc7pn3uY/z9OMF N4/iiTSxsx6SmmFjuxd3E/xhcTxpB6b+VJiqzxTfJpPX26pVSd1ljLi0ckcYKusDQaBb Dap2twmvYGqsbHbovGUe0gAzG2TbzTx8ZyoTSquitWSFcCJP45/xR4TWSJpMNMXCIu3g /JkA== X-Gm-Message-State: APjAAAUIzKeniD1GxH5WSTsXbuC/Ae8tQkf1OVEahH/BrI6yABohV6rd 5eoJiFVj1EnJFrdHreeLKjt2ECIc6hk= X-Google-Smtp-Source: APXvYqwX/KtlMBP92Wvj+DfXEhllZPGeS3zi8KREC/iIABxYFgjS0gBFfahQDoCqmeltHY9eDeHj1w== X-Received: by 2002:a63:1a1b:: with SMTP id a27mr40889978pga.59.1553907545626; Fri, 29 Mar 2019 17:59:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 14:58:57 -1000 Message-Id: <20190330005900.17282-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190330005900.17282-1-richard.henderson@linaro.org> References: <20190330005900.17282-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 1/4] linux-user/aarch64: Reset btype for syscalls and signals X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, ramana.radhakrishnan@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The value of btype for syscalls is CONSTRAINED UNPREDICTABLE, so we need to make sure that the value is 0 before clone, fork, or syscall return. The value of btype for signals is defined, but it does not make sense for a SIGILL handler to enter with the btype set as for the indirect branch that caused the SIGILL. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v4: Do not clear btype in signal frame. --- linux-user/aarch64/cpu_loop.c | 7 +++++++ linux-user/aarch64/signal.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..f5cce4769d 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -85,6 +85,13 @@ void cpu_loop(CPUARMState *env) =20 switch (trapnr) { case EXCP_SWI: + /* + * The state of BTYPE on syscall entry is CONSTRAINED + * UNPREDICTABLE. The real kernel will need to tidy this up + * as well. Do this before syscalls so that the value is + * correct on return from syscall (especially clone & fork). + */ + env->btype =3D 0; ret =3D do_syscall(env, env->xregs[8], env->xregs[0], diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index f84a9cf28a..078873c4a5 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -506,10 +506,11 @@ 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; + env->btype =3D 0; if (info) { tswap_siginfo(&frame->info, info); env->xregs[1] =3D frame_addr + offsetof(struct target_rt_sigframe,= info); --=20 2.17.1 From nobody Sat Apr 27 07:24:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553916900544894.7560154780322; Fri, 29 Mar 2019 20:35:00 -0700 (PDT) Received: from localhost ([127.0.0.1]:49797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA4le-0006gO-Eq for importer@patchew.org; Fri, 29 Mar 2019 23:34:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA2L0-00078Q-1i for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hA2Ky-0001dR-Kc for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:09 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46190) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hA2Ky-0001cl-By for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:08 -0400 Received: by mail-pf1-x444.google.com with SMTP id 9so1798838pfj.13 for ; Fri, 29 Mar 2019 17:59:08 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-72-255.hawaii.res.rr.com. [66.75.72.255]) by smtp.gmail.com with ESMTPSA id e1sm2229900pfn.187.2019.03.29.17.59.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 17:59: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; bh=+BPmCxbz0CPP0QJi6QmliFS0UpMvpjSbAC3AIaHbJHo=; b=UbcO9oUle46EuG2Mr4m1za7OVs5vE9EMkaCeFufWRpL4GSwxVU7GKtaPSn8Am/MLoG cq/eVp1RwVp4jnCmDlaiZqf7r6lpwpvRwaB4EkwFoRNPZrRgZ11g+vQdE+5XEMEZlZKu Y00Wmg1fu2irDvQ8uXvlflAh9aSFmHV4UPDy1kCvpEDKWzDWNo2laaZDfCcg5DtN7iA6 ZB0mIfNHGOwlRp+hrEhuqkI9zwOuMYmIwl8ZZWWEE9CoPR4/JcOJlORVwx12g5z7fXiT nXtDNhP8dsR/lrHHWVKejJW4NdjP2PHnJ1ab5IMbePgvn/aluMKLBkD9lJOCgjJXYuMn 4RZA== 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; bh=+BPmCxbz0CPP0QJi6QmliFS0UpMvpjSbAC3AIaHbJHo=; b=rSFEerqWmotaULVHu8V6vn/fLnrZ1VXskF4pb/TE83Xvk4XLBzzxkm3vNrRpJ/gww1 fV5aHsxBLEgP1MkJk4DlAR5NTdgLVxZ4OOHHyRimDPKf1KwGE8YTh3yAsegPFn0Kkp+R dJpEhrPybbeNqK40KvcQxUi1ihHqolYQ3F/Ib1Xtz5Qwsbj+qp2bfw2Bb8uhgvwvstId L0QDnHACKReIlTHf8nzfwCoWS4fW5N1cHX/GoSvvYNfflu8n7l20bwjJl1aSw9JHEaoy N+XsAXajzMXiy9qzOngpqHUZGg34WAZElKz5GFHAkMVad3e2FmGuphw02Vd/3Iz3r7TJ 96AQ== X-Gm-Message-State: APjAAAUz6BoGagMfEzWkYTtEmsP9rTNObg6zo377zTV7bl833YjohIRL kD66QtElLTgU0lxhih8F0REJzkF0Hjc= X-Google-Smtp-Source: APXvYqz8Ep9qUgd/Der2WHyU7+39oqiV6ZeoX8XZuNBG2TYYcSQliWAXpytofSuLP1WEk8u5keqhvg== X-Received: by 2002:a65:4008:: with SMTP id f8mr36780976pgp.253.1553907547120; Fri, 29 Mar 2019 17:59:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 14:58:58 -1000 Message-Id: <20190330005900.17282-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190330005900.17282-1-richard.henderson@linaro.org> References: <20190330005900.17282-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v4 2/4] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, ramana.radhakrishnan@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is agreement that there will be a mmap/mprotect bit, although no word yet on the value or the name. Invent a name to make forward progress. The PAGE_TARGET_1 bit, is qemu internal, and allows the target something to query from the guest page tables. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 12 +++++++++--- linux-user/syscall_defs.h | 5 +++++ linux-user/mmap.c | 13 ++++++++++++- target/arm/translate-a64.c | 6 +++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index b16c9ec513..fb38467ed1 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -242,13 +242,19 @@ extern intptr_t qemu_host_page_mask; /* original state of the write flag (used when tracking self-modifying code */ #define PAGE_WRITE_ORG 0x0010 -/* Invalidate the TLB entry immediately, helpful for s390x - * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs= () */ -#define PAGE_WRITE_INV 0x0040 #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) /* FIXME: Code that sets/uses this is broken and needs to go away. */ #define PAGE_RESERVED 0x0020 #endif +/* + * Invalidate the TLB entry immediately, helpful for s390x + * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs= () + */ +#define PAGE_WRITE_INV 0x0040 +/* + * Some 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 12c8407144..563f752081 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1090,6 +1090,11 @@ struct target_winsize { #define TARGET_PROT_SEM 0x08 #endif =20 +#ifdef TARGET_AARCH64 +/* FIXME: Placeholder while waiting on the official ABI. */ +#define TARGET_PROT_BTI 0x1000 +#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 e0249efe4f..48b4d9ea02 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -362,6 +362,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, int flags, int fd, abi_ulong offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; + int page_flags; =20 mmap_lock(); #ifdef DEBUG_MMAP @@ -451,6 +452,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, i= nt prot, } } =20 + page_flags =3D (prot & PAGE_BITS) | PAGE_VALID; + +#ifdef TARGET_AARCH64 + /* Remember the BTI bit for page_get_flags, but don't pass to host. */ + if (prot & TARGET_PROT_BTI) { + page_flags |=3D PAGE_TARGET_1; + prot &=3D ~TARGET_PROT_BTI; + } +#endif + if (!(flags & MAP_FIXED)) { unsigned long host_start; void *p; @@ -562,7 +573,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); the_end: #ifdef DEBUG_MMAP printf("ret=3D0x" TARGET_ABI_FMT_lx "\n", start); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index dcdeb80176..5b7bdc3926 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14144,10 +14144,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.17.1 From nobody Sat Apr 27 07:24:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553911777691911.9105121282682; Fri, 29 Mar 2019 19:09:37 -0700 (PDT) Received: from localhost ([127.0.0.1]:43891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA3Qw-0000hy-0u for importer@patchew.org; Fri, 29 Mar 2019 22:09:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA2L1-00078U-A2 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hA2L0-0001eK-5D for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:11 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44040) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hA2Kz-0001dv-UG for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:10 -0400 Received: by mail-pf1-x443.google.com with SMTP id y13so1801418pfm.11 for ; Fri, 29 Mar 2019 17:59:09 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-72-255.hawaii.res.rr.com. [66.75.72.255]) by smtp.gmail.com with ESMTPSA id e1sm2229900pfn.187.2019.03.29.17.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 17:59: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; bh=z4WDNajKPnmHVMuD6PXewZbG8jDBRC/myV7ZolbBuM0=; b=y/vWxKAibAbeGtOJzGh7Ri8j9kKVy+vvb1M/YtWIjyXX3+2rw9KstdOY26eNqCjQ4l AgNOEg6bzPMSJDregUM08NHTWnhGCDIhMtTNwBezD/4eqnD0l5uG0J9uVkan4XCAemFI X15J1mZrzfUM7J6WMRNqCVS+stgTkw8WY+A0cS7196sXxjvgKv3c+YE7aodss6tZkXgv Gtz7QnW1ucX7CYBf851cqweEqiBmvAuA7PALrIakPHbIcnd6swneQH2Cy2TWW8hvw00p wErHcM6n8XigPXXMG4MKZwaN377eNac2wjbqFKX12qgIWtSzR2bHhwsUrwRKFsRIdBMR xvcw== 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; bh=z4WDNajKPnmHVMuD6PXewZbG8jDBRC/myV7ZolbBuM0=; b=XqDLT7wSyChpaKEed3rwpxjuPvwACs6lyp3Bzm3Dfup1/IH7Nvbme4ttoNyoiTkNH4 7YZSowkWAjVMNUsB5NhokHXTG5+Dbj80sQIhsRwRSufl4x5Z+Fw1XXLQbaihYzdtW1Ko e7tSpEn/O3Inr3AoDrKnw6qow65sfmnJathie62Iv+IZaXv2z/MFgxeJJljwaclyY2et jRGAKqSJ/I7fWsTHi2kWQfkFDyZy77U0uiFx8O2oWscMoJWJ4i4SpktFUg32Rrt85rjw UAjgbSFzFH/hnGN03atiInmZXFZdmVYrbn4nrr3Q7dmSFYWkp0bTh9Ws57uqIDhZIKqH fHzQ== X-Gm-Message-State: APjAAAWulDZpEc/eaCHpNRNcItWg2ycNxu9pDvJd/vXfpPSM6loIZWYw NHKK1WRI7FCy/W+cYGA5TzGVBoDIeew= X-Google-Smtp-Source: APXvYqzUYZC6qxe4iECTaoRdMv9RVDNZbnjfwDvvmKYekqRC5+JTu5tUMc6vJK2z0s65HkKSH6BUDA== X-Received: by 2002:a62:12c8:: with SMTP id 69mr50972449pfs.184.1553907548635; Fri, 29 Mar 2019 17:59:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 14:58:59 -1000 Message-Id: <20190330005900.17282-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190330005900.17282-1-richard.henderson@linaro.org> References: <20190330005900.17282-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v4 3/4] linux-user: Parse NT_GNU_PROPERTY_TYPE_0 notes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, ramana.radhakrishnan@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 Reviewed-by: Peter Maydell --- linux-user/elfload.c | 79 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..12ee96e5d4 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -116,6 +116,10 @@ typedef abi_uint target_gid_t; #endif typedef abi_int target_pid_t; =20 + +#define TARGET_NT_GNU_PROPERTY_TYPE_0 5 + + #ifdef TARGET_I386 =20 #define ELF_PLATFORM get_elf_platform() @@ -543,6 +547,10 @@ static const char *get_elf_platform(void) # define ELF_PLATFORM "aarch64" #endif =20 +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) +#define TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { @@ -2252,7 +2260,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 =3D PROT_EXEC; const char *errmsg; =20 /* First of all, some simple consistency checks */ @@ -2287,17 +2295,66 @@ 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; - if (a < loaddr) { - loaddr =3D a; + struct elf_phdr *eppnt =3D phdr + i; + + switch (eppnt->p_type) { + case PT_LOAD: + { + abi_ulong a =3D eppnt->p_vaddr - eppnt->p_offset; + if (a < loaddr) { + loaddr =3D a; + } + a =3D eppnt->p_vaddr + eppnt->p_memsz; + if (a > hiaddr) { + hiaddr =3D a; + } + ++info->nsegs; + info->alignment |=3D eppnt->p_align; } - a =3D phdr[i].p_vaddr + phdr[i].p_memsz; - if (a > hiaddr) { - hiaddr =3D a; + break; + case PT_NOTE: + { + uint32_t note[7]; + uint32_t gnu0; + + if (eppnt->p_filesz < sizeof(note)) { + break; + } + 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_offset); + if (retval !=3D sizeof(note)) { + goto exit_perror; + } + } +#ifdef BSWAP_NEEDED + for (i =3D 0; i < ARRAY_SIZE(note); ++i) { + bswap32s(note + i); + } +#endif +#ifdef HOST_WORDS_BIGENDIAN + gnu0 =3D 'G' << 24 | 'N' << 16 | 'U' << 8; +#else + gnu0 =3D 'G' | 'N' << 8 | 'U' << 16; +#endif + + if (note[0] !=3D 4 || /* namesz */ + note[1] < 12 || /* descsz -- may include padding */ + note[2] !=3D TARGET_NT_GNU_PROPERTY_TYPE_0 || /* type= */ + note[3] !=3D gnu0) { /* name */ + break; + } +#ifdef TARGET_AARCH64 + if (note[4] =3D=3D TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_A= ND && + note[5] =3D=3D 4 && + (note[6] & TARGET_GNU_PROPERTY_AARCH64_FEATURE_1_BTI))= { + prot_exec |=3D TARGET_PROT_BTI; + } +#endif } - ++info->nsegs; - info->alignment |=3D phdr[i].p_align; + break; } } =20 @@ -2359,7 +2416,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, =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_X) elf_prot |=3D prot_exec; =20 vaddr =3D load_bias + eppnt->p_vaddr; vaddr_po =3D TARGET_ELF_PAGEOFFSET(vaddr); --=20 2.17.1 From nobody Sat Apr 27 07:24:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553915997070574.4982363374074; Fri, 29 Mar 2019 20:19:57 -0700 (PDT) Received: from localhost ([127.0.0.1]:47826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA4Wx-0007OL-C5 for importer@patchew.org; Fri, 29 Mar 2019 23:19:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hA2L3-00078w-0D for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hA2L1-0001eu-RP for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:12 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:38494) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hA2L1-0001eX-KX for qemu-devel@nongnu.org; Fri, 29 Mar 2019 20:59:11 -0400 Received: by mail-pg1-x543.google.com with SMTP id j26so1982967pgl.5 for ; Fri, 29 Mar 2019 17:59:11 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-72-255.hawaii.res.rr.com. [66.75.72.255]) by smtp.gmail.com with ESMTPSA id e1sm2229900pfn.187.2019.03.29.17.59.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 17:59: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; bh=ZWpQIT9YQySoKjzsWYha6BN9w4EITOUpOlIb69f+q0c=; b=vBsbT/5SgkzQwN36hGVORZmKZdaZ+X+wKaldsJy+Xu0hKjO5m7aB1AQbTmlwbkHZPJ 2KfPwPXZ79dCGNjbz4RzdD3eYCKT023PRifJi/zQGM2Nlk7cjkj0tF5+kRcD/O+NQCkQ 9LIpNBxJOFZjAF2edPZZQBFJdTYC6fR/Ju8jx2l5X1PrqAPr3m5vYRmDvGrhBP+G7Diy jC/c7fpfxclOrMLKTrQfGTYao8yCo4y2BQtp1DiJHp2gD4OU9bQOuFh31qVhipMCCVyq OlTIMa6UB9T2TX5Vi7AqcJ+VHsirzDMY+7Y1O+RAx23DcUcPa6Kz6839XMZycgauIvI7 UThw== 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; bh=ZWpQIT9YQySoKjzsWYha6BN9w4EITOUpOlIb69f+q0c=; b=Kn0xpU//Dzh9PnOI36s7sVvmvV9p68mn2FLEV/3NewgupDP5ixeC3cJA0wS/hp/+FK YZa2XA2UQx55so5+AjSWZxmfEoMuOVbSfaya+NjoY2NR54gDUGy9Y19K4LoRnOW8/bKj Kkuk4hJo6Ipo4wcNmI1BU5v4mPXE6dW5+HTh/C6JtXDqMVs1fAYFXjiehYML5chTsBz0 PpB2qdbA5QH5MXs4bjZwT0ETD8gp8FLiaMqqSelatOizOKZxynoQbWIwh5iH/lT47wUu ykA5FkjGFfjlT+tvUYOst33Y0jpdE5ycQfrw1HuybcMmcPJcDFpqnA4qnpKyXamlu9q8 naWA== X-Gm-Message-State: APjAAAXDX9/ij8EnLuIDMx0diNIetTn7BXMKQiznPwEk84ECjvpT+ro6 vCRfdtF1x34rbjPL9OO4a4KaTDQnYW4= X-Google-Smtp-Source: APXvYqze3iFSiYzNSs8BF2ZEbY9zRsCe2NS2XtQOA2wIUuUPiJ9GddvOEcrgptBCAs7yzgjrDMuD0A== X-Received: by 2002:a63:84c7:: with SMTP id k190mr48616373pgd.255.1553907550171; Fri, 29 Mar 2019 17:59:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 14:59:00 -1000 Message-Id: <20190330005900.17282-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190330005900.17282-1-richard.henderson@linaro.org> References: <20190330005900.17282-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v4 4/4] tests/tcg/aarch64: Add bti smoke test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, ramana.radhakrishnan@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tests/tcg/aarch64/bti-1.c | 62 +++++++++++++++++++++++++++ tests/tcg/aarch64/bti-crt.inc.c | 69 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 3 ++ 3 files changed, 134 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..bb363853de --- /dev/null +++ b/tests/tcg/aarch64/bti-crt.inc.c @@ -0,0 +1,69 @@ +/* + * Minimal user-environment for testing BTI. + * + * Normal libc is not 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= "); +} + +/* + * Create the PT_NOTE that will enable BTI in the page tables. + * This will be created by the compiler with -mbranch-protection=3Dstandar= d, + * but as of 2019-03-29, this is has not been committed to gcc mainline. + * This will probably be in GCC10. + */ +asm(".section .note.gnu.property,\"a\"\n\ + .align 3\n\ + .long 4\n\ + .long 16\n\ + .long 5\n\ + .string \"GNU\"\n\ + .long 0xc0000000\n\ + .long 4\n\ + .long 1\n\ + .align 3\n\ + .previous"); diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 2bb914975b..21da3bc37f 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -18,4 +18,7 @@ run-fcvt: fcvt AARCH64_TESTS +=3D pauth-1 run-pauth-%: QEMU +=3D -cpu max =20 +AARCH64_TESTS +=3D bti-1 +bti-1: LDFLAGS +=3D -nostartfiles -nodefaultlibs -nostdlib + TESTS:=3D$(AARCH64_TESTS) --=20 2.17.1