cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

pauth-1.c (729B)


      1#include <assert.h>
      2#include <sys/prctl.h>
      3#include <stdio.h>
      4
      5#ifndef PR_PAC_RESET_KEYS
      6#define PR_PAC_RESET_KEYS  54
      7#define PR_PAC_APDAKEY     (1 << 2)
      8#endif
      9
     10#define TESTS 1000
     11
     12int main()
     13{
     14    int x, i, count = 0;
     15    void *p0 = &x, *p1, *p2;
     16    float perc;
     17
     18    for (i = 0; i < TESTS; i++) {
     19        asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
     20        prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
     21        asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
     22
     23        if (p1 != p0) {
     24            count++;
     25        }
     26        if (p1 != p2) {
     27            count++;
     28        }
     29    }
     30
     31    perc = (float) count / (float) (TESTS * 2);
     32    printf("Ptr Check: %0.2f%%\n", perc * 100.0);
     33    assert(perc > 0.95);
     34    return 0;
     35}