From 1def26f83e83556d767754581fa52081ffb54b09 Mon Sep 17 00:00:00 2001 From: Sergej Schumilo Date: Sat, 20 Jan 2024 21:26:18 +0100 Subject: [PATCH] fix non-ipt mode --- nyx/hypercall/hypercall.c | 13 +++++++++---- nyx/interface.c | 3 --- nyx/pt.c | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/nyx/hypercall/hypercall.c b/nyx/hypercall/hypercall.c index fa06af3201..7ee3025999 100644 --- a/nyx/hypercall/hypercall.c +++ b/nyx/hypercall/hypercall.c @@ -110,12 +110,17 @@ bool handle_hypercall_kafl_next_payload(struct kvm_run *run, REQUEST_SAVE_SNAPSHOT_ROOT_FIX_RIP); setup_snapshot_once = true; - for (int i = 0; i < INTEL_PT_MAX_RANGES; i++) { - if (GET_GLOBAL_STATE()->pt_ip_filter_configured[i]) { - pt_enable_ip_filtering(cpu, i, true, false); + /* At this point we need to check if PT mode is enabled + * and configured. Otherwise, libxdc_init() will fail. + */ + if(GET_GLOBAL_STATE()->nyx_pt && GET_GLOBAL_STATE()->cap_compile_time_tracing == false) { + for (int i = 0; i < INTEL_PT_MAX_RANGES; i++) { + if (GET_GLOBAL_STATE()->pt_ip_filter_configured[i]) { + pt_enable_ip_filtering(cpu, i, true, false); + } } + pt_init_decoder(cpu); } - pt_init_decoder(cpu); request_fast_vm_reload(GET_GLOBAL_STATE()->reload_state, REQUEST_LOAD_SNAPSHOT_ROOT); diff --git a/nyx/interface.c b/nyx/interface.c index 91ccd95986..6d1ced61b3 100644 --- a/nyx/interface.c +++ b/nyx/interface.c @@ -376,9 +376,6 @@ static void check_available_ipt_ranges(nyx_interface_state *s) } } } - else{ - nyx_abort("KVM-Nyx support is missing...\n"); - } close(kvm_fd); } diff --git a/nyx/pt.c b/nyx/pt.c index d78bc58522..33035ec671 100644 --- a/nyx/pt.c +++ b/nyx/pt.c @@ -227,6 +227,15 @@ void pt_init_decoder(CPUState *cpu) assert(GET_GLOBAL_STATE()->decoder == NULL); assert(GET_GLOBAL_STATE()->shared_bitmap_ptr != NULL); assert(GET_GLOBAL_STATE()->shared_bitmap_size != 0); + + + if (GET_GLOBAL_STATE()->pt_ip_filter_configured[0] == false && + GET_GLOBAL_STATE()->pt_ip_filter_configured[1] == false && + GET_GLOBAL_STATE()->pt_ip_filter_configured[2] == false && + GET_GLOBAL_STATE()->pt_ip_filter_configured[3] == false) { + nyx_abort("Intel PT mode cannot be enabled without any IP filters configured...\n"); + } + GET_GLOBAL_STATE()->decoder = libxdc_init(filters, (void *(*)(void *, uint64_t, bool *))page_cache_fetch2, GET_GLOBAL_STATE()->page_cache,