cachepc

Prime+Probe cache-based side-channel attack on AMD SEV-SNP protected virtual machines
git clone https://git.sinitax.com/sinitax/cachepc
Log | Files | Refs | Submodules | README | sfeed.txt

commit 9cce829d8a794848b0699c3f9a84b2a057221a90
parent 297900bdb5d58224bb1d65f5632a179de825c11d
Author: Louis Burda <quent.burda@gmail.com>
Date:   Thu, 29 Sep 2022 00:32:30 +0200

Adapt kernel module for sev-snp machine

Diffstat:
Mkmod/cachepc.c | 4++--
Mkmod/kvm.c | 21+++++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/kmod/cachepc.c b/kmod/cachepc.c @@ -16,14 +16,14 @@ static void build_randomized_list_for_cache_set(cache_ctx *ctx, cacheline **cach static cacheline **allocate_cache_ds(cache_ctx *ctx); static uint16_t get_virt_cache_set(cache_ctx *ctx, void *ptr); -void +void __attribute__((optimize(1))) // prevent instruction reordering cachepc_prime_vcall(uintptr_t ret, cacheline *cl) { cachepc_prime(cl); asm volatile ("mov %0, %%rax; jmp *%%rax" : : "r"(ret) : "rax"); } -void +void __attribute__((optimize(1))) // prevent instruction reordering cachepc_probe_vcall(uintptr_t ret, cacheline *cl) { cachepc_probe(cl); diff --git a/kmod/kvm.c b/kmod/kvm.c @@ -69,6 +69,26 @@ cachepc_kvm_proc_write(struct file *file, const char *buf, size_t buflen, loff_t return 0; } +loff_t +cachepc_kvm_proc_lseek(struct file *file, loff_t off, int mode) +{ + switch (mode) { + case SEEK_SET: + file->f_pos = off; + break; + case SEEK_CUR: + file->f_pos += off; + break; + case SEEK_END: + file->f_pos = cachepc_msrmts_count * sizeof(uint16_t) + off; + break; + default: + return -EINVAL; + } + + return file->f_pos; +} + void cachepc_kvm_prime_probe_test(void *p) { @@ -355,6 +375,7 @@ cachepc_kvm_init(void) cachepc_proc_ops.proc_open = cachepc_kvm_proc_open; cachepc_proc_ops.proc_read = cachepc_kvm_proc_read; cachepc_proc_ops.proc_write = cachepc_kvm_proc_write; + cachepc_proc_ops.proc_lseek = cachepc_kvm_proc_lseek; cachepc_proc_ops.proc_release = cachepc_kvm_proc_close; cachepc_proc_ops.proc_ioctl = cachepc_kvm_ioctl; proc_create("cachepc", 0644, NULL, &cachepc_proc_ops);