diff --git a/libafl_extras/syx-snapshot/device-save.c b/libafl_extras/syx-snapshot/device-save.c index 637ec996a7..10b81071b5 100644 --- a/libafl_extras/syx-snapshot/device-save.c +++ b/libafl_extras/syx-snapshot/device-save.c @@ -19,6 +19,20 @@ extern void save_section_footer(QEMUFile *f, SaveStateEntry *se); // iothread must be locked device_save_state_t* device_save_all(void) { + return device_save_kind(DEVICE_SNAPSHOT_ALL, NULL); +} + +static int is_in_list(char* str, char** list) { + while (*list) { + if (!strcmp(str, *list)) { + return 1; + } + list++; + } + return 0; +} + +device_save_state_t* device_save_kind(device_snapshot_kind_t kind, char** names) { device_save_state_t* dss = g_new0(device_save_state_t, 1); SaveStateEntry *se; @@ -39,6 +53,20 @@ device_save_state_t* device_save_all(void) { if (!strcmp(se->idstr, "globalstate")) { continue; } + switch (kind) { + case DEVICE_SNAPSHOT_ALLOWLIST: + if (!is_in_list(se->idstr, names)) { + continue; + } + break; + case DEVICE_SNAPSHOT_DENYLIST: + if (is_in_list(se->idstr, names)) { + continue; + } + break; + default: + break; + } // SYX_PRINTF("Saving section %s...\n", se->idstr); diff --git a/libafl_extras/syx-snapshot/device-save.h b/libafl_extras/syx-snapshot/device-save.h index 12ac3220a4..684c342630 100644 --- a/libafl_extras/syx-snapshot/device-save.h +++ b/libafl_extras/syx-snapshot/device-save.h @@ -10,6 +10,14 @@ typedef struct device_save_state_s { size_t save_buffer_size; } device_save_state_t; +// Type of device snapshot +typedef enum device_snapshot_kind_e { + DEVICE_SNAPSHOT_ALL, + DEVICE_SNAPSHOT_ALLOWLIST, + DEVICE_SNAPSHOT_DENYLIST +} device_snapshot_kind_t; + device_save_state_t* device_save_all(void); +device_save_state_t* device_save_kind(device_snapshot_kind_t kind, char** names); void device_restore_all(device_save_state_t* device_save_state); void device_free_all(device_save_state_t* dss); diff --git a/libafl_extras/syx-snapshot/syx-snapshot.c b/libafl_extras/syx-snapshot/syx-snapshot.c index 9ef2b752f8..f4413f3630 100644 --- a/libafl_extras/syx-snapshot/syx-snapshot.c +++ b/libafl_extras/syx-snapshot/syx-snapshot.c @@ -45,10 +45,10 @@ uint64_t syx_snapshot_handler(CPUState* cpu, uint32_t cmd, target_ulong target_o return (uint64_t) -1; } -syx_snapshot_t* syx_snapshot_create(bool track) { +syx_snapshot_t* syx_snapshot_create(bool track, device_snapshot_kind_t kind, char** devices) { syx_snapshot_t* snapshot = g_new0(syx_snapshot_t, 1); - snapshot->root_snapshot = syx_snapshot_root_create(); + snapshot->root_snapshot = syx_snapshot_root_create(kind, devices); snapshot->last_incremental_snapshot = NULL; snapshot->dirty_list = syx_snapshot_dirty_list_create(); @@ -74,12 +74,12 @@ void syx_snapshot_free(syx_snapshot_t* snapshot) { g_free(snapshot); } -syx_snapshot_root_t syx_snapshot_root_create(void) { +syx_snapshot_root_t syx_snapshot_root_create(device_snapshot_kind_t kind, char** devices) { syx_snapshot_root_t root = {0}; RAMBlock* block; uint64_t nb_blocks = 0; - device_save_state_t* dss = device_save_all(); + device_save_state_t* dss = device_save_kind(kind, devices); RAMBLOCK_FOREACH(block) { nb_blocks++; @@ -150,13 +150,13 @@ void syx_snapshot_stop_track(syx_snapshot_tracker_t* tracker, syx_snapshot_t* sn abort(); } -void syx_snapshot_increment_push(syx_snapshot_t* snapshot, CPUState* cpu) { +void syx_snapshot_increment_push(syx_snapshot_t* snapshot, device_snapshot_kind_t kind, char** devices) { syx_snapshot_increment_t* increment = g_new0(syx_snapshot_increment_t, 1); increment->parent = snapshot->last_incremental_snapshot; snapshot->last_incremental_snapshot = increment; increment->dirty_page_list = syx_snapshot_dirty_list_to_dirty_page_list(&snapshot->dirty_list); - increment->dss = device_save_all(); + increment->dss = device_save_kind(kind, devices); syx_snapshot_dirty_list_flush(&snapshot->dirty_list); } diff --git a/libafl_extras/syx-snapshot/syx-snapshot.h b/libafl_extras/syx-snapshot/syx-snapshot.h index 2c7d6a5399..87ea480ff2 100644 --- a/libafl_extras/syx-snapshot/syx-snapshot.h +++ b/libafl_extras/syx-snapshot/syx-snapshot.h @@ -5,13 +5,6 @@ #include "sysemu/sysemu.h" #include "../syx-misc.h" -/** - * SYX Snapshot parameters - */ -typedef struct syx_snapshot_init_params_s { - uint64_t page_size; -} syx_snapshot_init_params_t; - /** * Saved ramblock */ @@ -112,7 +105,7 @@ uint64_t syx_snapshot_handler(CPUState* cpu, uint32_t cmd, target_ulong target_o // Snapshot API // -syx_snapshot_t* syx_snapshot_create(bool track); +syx_snapshot_t* syx_snapshot_create(bool track, device_snapshot_kind_t kind, char** devices); void syx_snapshot_free(syx_snapshot_t* snapshot); // void syx_snapshot_load(syx_snapshot_t* snapshot); @@ -121,7 +114,7 @@ void syx_snapshot_free(syx_snapshot_t* snapshot); // Root snapshot API // -syx_snapshot_root_t syx_snapshot_root_create(void); +syx_snapshot_root_t syx_snapshot_root_create(device_snapshot_kind_t kind, char** devices); void syx_snapshot_root_restore(syx_snapshot_t* snapshot); void syx_snapshot_root_free(syx_snapshot_root_t* root); @@ -139,7 +132,7 @@ void syx_snapshot_stop_track(syx_snapshot_tracker_t* tracker, syx_snapshot_t* sn // Snapshot increment API // -void syx_snapshot_increment_push(syx_snapshot_t* snapshot, CPUState* cpu); +void syx_snapshot_increment_push(syx_snapshot_t* snapshot, device_snapshot_kind_t kind, char** devices); void syx_snapshot_increment_pop(syx_snapshot_t* snapshot); void syx_snapshot_increment_restore_last(syx_snapshot_t* snapshot); syx_snapshot_increment_t* syx_snapshot_increment_free(syx_snapshot_increment_t* increment);