mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-09 00:07:57 -06:00
tests/tcg/arm: account for pauth randomness
Pointer authentication isn't guaranteed to always detect a clash between different keys. Take this into account in the test by running several times and checking the percentage hit rate of the test. Cc: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
This commit is contained in:
parent
8a2af7a70c
commit
b640728151
1 changed files with 20 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
asm(".arch armv8.4-a");
|
asm(".arch armv8.4-a");
|
||||||
|
|
||||||
|
@ -8,16 +9,29 @@ asm(".arch armv8.4-a");
|
||||||
#define PR_PAC_APDAKEY (1 << 2)
|
#define PR_PAC_APDAKEY (1 << 2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TESTS 1000
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int x;
|
int x, i, count = 0;
|
||||||
void *p0 = &x, *p1, *p2;
|
void *p0 = &x, *p1, *p2;
|
||||||
|
float perc;
|
||||||
|
|
||||||
|
for (i = 0; i < TESTS; i++) {
|
||||||
asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
|
asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
|
||||||
prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
|
prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
|
||||||
asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
|
asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
|
||||||
|
|
||||||
assert(p1 != p0);
|
if (p1 != p0) {
|
||||||
assert(p1 != p2);
|
count++;
|
||||||
|
}
|
||||||
|
if (p1 != p2) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
perc = (float) count / (float) (TESTS * 2);
|
||||||
|
printf("Ptr Check: %0.2f%%", perc * 100.0);
|
||||||
|
assert(perc > 0.95);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue