From 1180f757b3f9c4c48ec63259132b5fd3f7e5872f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 2 Jan 2025 05:38:38 +0000 Subject: [PATCH] hypervisor: emulator: adjust iced-x86 feature flags The fastfmt feature and VEX support use techniques that appear to leak memory in the eye of LLVM's address sanitizer. While at it, disable a bunch of instruction set decoding support we never intend to support. Signed-off-by: Wei Liu --- hypervisor/Cargo.toml | 11 ++++++++++- .../src/arch/x86/emulator/instructions/mod.rs | 13 ------------- hypervisor/src/arch/x86/emulator/mod.rs | 17 ++++++++++------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/hypervisor/Cargo.toml b/hypervisor/Cargo.toml index bc377f83b..05d4c9947 100644 --- a/hypervisor/Cargo.toml +++ b/hypervisor/Cargo.toml @@ -43,7 +43,16 @@ vmm-sys-util = { workspace = true, features = ["with-serde"] } [target.'cfg(target_arch = "x86_64")'.dependencies.iced-x86] default-features = false -features = ["decoder", "fast_fmt", "instr_info", "op_code_info", "std"] +features = [ + "decoder", + "instr_info", + "no_d3now", + "no_evex", + "no_vex", + "no_xop", + "op_code_info", + "std", +] optional = true version = "1.21.0" diff --git a/hypervisor/src/arch/x86/emulator/instructions/mod.rs b/hypervisor/src/arch/x86/emulator/instructions/mod.rs index e63986cf6..e04a072f3 100644 --- a/hypervisor/src/arch/x86/emulator/instructions/mod.rs +++ b/hypervisor/src/arch/x86/emulator/instructions/mod.rs @@ -140,16 +140,3 @@ pub trait InstructionHandler { platform: &mut dyn PlatformEmulator, ) -> Result<(), EmulationError>; } - -macro_rules! insn_format { - ($insn:ident) => {{ - let mut output = String::new(); - let mut formatter = FastFormatter::new(); - formatter - .options_mut() - .set_space_after_operand_separator(true); - formatter.format(&$insn, &mut output); - - output - }}; -} diff --git a/hypervisor/src/arch/x86/emulator/mod.rs b/hypervisor/src/arch/x86/emulator/mod.rs index 2e2f2e9fe..160d07a45 100644 --- a/hypervisor/src/arch/x86/emulator/mod.rs +++ b/hypervisor/src/arch/x86/emulator/mod.rs @@ -599,8 +599,8 @@ impl Emulator<'_, T> { decoder.decode_out(&mut insn); if decoder.last_error() != DecoderError::None { return Err(EmulationError::InstructionFetchingError(anyhow!( - "{:#x?}", - insn_format!(insn) + "{:?}", + insn.code() ))); } } @@ -609,14 +609,17 @@ impl Emulator<'_, T> { Emulator::get_handler(insn.code()) .ok_or_else(|| { EmulationError::UnsupportedInstruction(anyhow!( - "{:#x?} {:?} {:?}", - insn_format!(insn), - insn.mnemonic(), - insn.code() + "{:?} {:x?}", + insn.code(), + insn_stream )) })? .emulate(&insn, &mut state, self.platform) - .context(anyhow!("Failed to emulate {:#x?}", insn_format!(insn)))?; + .context(anyhow!( + "Failed to emulate {:?} {:x?}", + insn.code(), + insn_stream + ))?; last_decoded_ip = decoder.ip(); num_insn_emulated += 1;