summary refs log tree commit diff stats
path: root/gitlab/issues/target_arm/host_missing/accel_TCG/998.toml
diff options
context:
space:
mode:
authorChristian Krinitsin <mail@krinitsin.com>2025-05-21 21:21:26 +0200
committerChristian Krinitsin <mail@krinitsin.com>2025-05-21 21:21:26 +0200
commit4b927bc37359dec23f67d3427fc982945f24f404 (patch)
tree245449ef9146942dc7fffd0235b48b7e70a00bf2 /gitlab/issues/target_arm/host_missing/accel_TCG/998.toml
parentaa8bd79cec7bf6790ddb01d156c2ef2201abbaab (diff)
downloadqemu-analysis-4b927bc37359dec23f67d3427fc982945f24f404.tar.gz
qemu-analysis-4b927bc37359dec23f67d3427fc982945f24f404.zip
add gitlab issues in toml format
Diffstat (limited to 'gitlab/issues/target_arm/host_missing/accel_TCG/998.toml')
-rw-r--r--gitlab/issues/target_arm/host_missing/accel_TCG/998.toml70
1 files changed, 70 insertions, 0 deletions
diff --git a/gitlab/issues/target_arm/host_missing/accel_TCG/998.toml b/gitlab/issues/target_arm/host_missing/accel_TCG/998.toml
new file mode 100644
index 000000000..3e10d3dfe
--- /dev/null
+++ b/gitlab/issues/target_arm/host_missing/accel_TCG/998.toml
@@ -0,0 +1,70 @@
+id = 998
+title = "AArch64: SCTLR_EL1.BT0 set incorrectly in user mode"
+state = "closed"
+created_at = "2022-04-22T15:22:46.821Z"
+closed_at = "2022-05-05T17:53:48.578Z"
+labels = ["Closed::Fixed", "accel: TCG", "linux-user", "target: arm"]
+url = "https://gitlab.com/qemu-project/qemu/-/issues/998"
+host-os = "Ubuntu 20.04"
+host-arch = "ARM"
+qemu-version = "v7.0.0-rc4"
+guest-os = "Fedora 34"
+guest-arch = "ARM"
+description = """PACIASP normally acts as a BTI landing pad, but not in every situation. When SCTLR_EL1.BT is set, PACIASP checks that the indirect branch originates from X16 or X17 when the indirect branch is taken from a BTI guarded area. Linux sets this bit, ideally QEMU-user should too. This sample program should crash with a SIGILL if QEMU is working correctly, otherwise it will crash with a SIGSEGV.
+
+    #include <stdint.h>
+    #include <stdlib.h>
+    #include <unistd.h>
+    #include <string.h>
+    #include <stdio.h>
+    #include <sys/mman.h>
+
+    // PACIASP is a valid BTI landing pad, but there are some conditions
+    // under Linux which sets SCTLR_ELx.BT0 = 1. In this mode, a branch
+    // onto a PACIASP landing pad is only valid if it originates from
+    // x16 or x17 (i.e. br x17 is OK, br x3 is not).
+    // More info on page D5-4851 of the Arm Architecture Reference Manual (ARM DDI 0487H.a).
+
+    // Sample function which starts with a paciasp instruction
+    // (comes from -mbranch-protection=pac-ret+leaf)
+    void indirect_fn(int i) {
+        // paciasp instruction inserted here - should crash with SIGILL here if everything's operating OK.
+        i = i+1;
+        // Can't access this function from the copied location, so will segfault.
+        fprintf(stderr, "reachable\\n");
+    }
+
+    int main(int argc, char **argv) {
+        // It's difficult to get a whole binary BTI compatible without the appropriate crtbegin etc
+        // so instead map a page and copy the sample function there.
+        void *e = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+        if (e == MAP_FAILED) {
+            return 1;
+        }
+        memcpy(e, (void*)indirect_fn, 64);
+        mprotect(e, getpagesize(), PROT_READ | PROT_EXEC | PROT_BTI);
+
+        // paciasp is a valid landing pad if the branch comes from an unprotected area,
+        // so to ensure that we're protected - assemble an intermediate shim that's also PROT_BTI.
+        void *f = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+        if (f == MAP_FAILED) {
+            return 1;
+        }
+        uint32_t *x = (uint32_t*)f;
+        x[0] = 0xd503245fuL; // bti c
+        x[1] = 0xd61f0060uL; // br x1 - n.b. must be BR
+        mprotect(f, getpagesize(), PROT_READ | PROT_EXEC | PROT_BTI);
+
+        // Jump to the shim
+        asm volatile (
+            "mov x3, %0\\n"
+            "mov x2, %1\\n"
+            "blr x2\\n"
+        : : "p"(e), "p"(f) : "x2", "x3");
+
+        // Execution should not reach here
+        return 1;
+    }"""
+reproduce = """1. Compile with `clang-12 -g --sysroot=/work/home/fedora-rootfs/fedora_aarch64 -o sample --target=aarch64-linux-gnu -mbranch-protection=pac-ret+leaf -march=armv8-a -O1 -g sample.c` or similar.
+2. Run with `../qemu/build/qemu-aarch64 --cpu max -L ~/fedora-rootfs/fedora_aarch64 sample`"""
+additional = """n/a"""