From 8b1975c4e8a19c14800fbba2f636bc96dd1d6be9 Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 20 Mar 2024 09:55:58 +0800 Subject: [PATCH] Check memory page flag --- fuzz/fuzz_targets/snapshot2.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fuzz/fuzz_targets/snapshot2.rs b/fuzz/fuzz_targets/snapshot2.rs index b34fc5d3..35d92462 100644 --- a/fuzz/fuzz_targets/snapshot2.rs +++ b/fuzz/fuzz_targets/snapshot2.rs @@ -4,8 +4,8 @@ use ckb_vm::{ machine::VERSION2, memory::{round_page_down, round_page_up, FLAG_EXECUTABLE, FLAG_FREEZED}, snapshot2::{DataSource, Snapshot2Context}, - Bytes, CoreMachine, DefaultMachine, DefaultMachineBuilder, Error, Memory, DEFAULT_MEMORY_SIZE, - ISA_A, ISA_B, ISA_IMC, ISA_MOP, RISCV_PAGESIZE, + Bytes, CoreMachine, DefaultMachine, DefaultMachineBuilder, Error, Memory, SupportMachine, + DEFAULT_MEMORY_SIZE, ISA_A, ISA_B, ISA_IMC, ISA_MOP, RISCV_PAGESIZE, }; use ckb_vm_definitions::asm::AsmCoreMachine; use libfuzzer_sys::fuzz_target; @@ -183,6 +183,7 @@ fuzz_target!(|data: [u8; 96]| { .memory_mut() .load_bytes((i * RISCV_PAGESIZE) as u64, RISCV_PAGESIZE as u64) .unwrap(); + if mem1 != mem2 { eprintln!("mem1[0..32] = {:?}", &mem1[0..32]); eprintln!("mem2[0..32] = {:?}", &mem2[0..32]); @@ -196,5 +197,12 @@ fuzz_target!(|data: [u8; 96]| { } panic!("The memory restored by operation resume is not same as snapshot operation at page {}", i); } + + let flag1 = machine1.memory_mut().fetch_flag(i as u64); + let flag2 = machine2.memory_mut().fetch_flag(i as u64); + + if flag1 != flag2 { + panic!("Flag at page {}", i); + } } });