qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about MTE and SyS_brk


From: Stephen Long
Subject: Question about MTE and SyS_brk
Date: Thu, 1 Apr 2021 03:57:48 +0000

Hi Richard, do you know if the following is supposed to work? I think it's 
aborting
with qemu because qemu is considering the page not anonymous

#include <sys/syscall.h>
#include <err.h>
#include "mte.h"

void pass(int sig, siginfo_t *info, void *uc)
{
    assert(info->si_code == SEGV_MTESERR);
    exit(0);
}

int main(void) {
    enable_mte(PR_MTE_TCF_SYNC);

    void *brk = (void *)syscall(SYS_brk, 0);
    void *new_brk = (void *)syscall(SYS_brk, brk+16);

    if (mprotect((void *)brk, 16, PROT_READ | PROT_WRITE | PROT_MTE)) {
        err(-1, "mprotect");
    }

    int *p0, *p1, *p2;
    p0 = brk;
    long excl = 1;

    asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
    asm("gmi %0,%1,%0" : "+r"(excl) : "r"(p1));
    asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
    asm("stg %0,[%0]" : : "r"(p1));

    *p1 = 0;

    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_sigaction = pass;
    sa.sa_flags = SA_SIGINFO;
    sigaction(SIGSEGV, &sa, NULL);

    *p2 = 0;

    abort();
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]