From 287155b4f41f910bac73b75c737e79d3fa11d56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkan=20Yal=C3=A7in?= Date: Sun, 15 Nov 2026 18:21:40 +0000 Subject: [PATCH] README.md aktualisiert --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index 5d461db..210ab2b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # VmdtStr Detect VMMs with faulty handling of STR exit
**NOTE:** This detection requires the VMM in question to exit on descriptor table access, otherwise it won't work! + # Showcase This is the output on a KVM with no nested VMM active: ![](BareKVM.png) @@ -19,6 +20,61 @@ In 64-bit mode, operation is the *same*. The size of the memory operand is fixed byte TR is *zero extended* if stored to a 64-bit register. ``` +This is what the exit handler of HVPP is doing on an exit with reason descriptor table access. +``` +oid vmexit_passthrough_handler::handle_ldtr_tr_access(vcpu_t& vp) noexcept +{ + auto instruction_info = vp.exit_instruction_info().ldtr_tr_access; + + cr3_guard _{ vp.guest_cr3() }; + + auto& low_word = + instruction_info.access_type == vmx::instruction_info_t::access_memory + ? *reinterpret_cast(vp.exit_instruction_info_guest_va()) + // instruction_info.access_type == vmx::instruction_info::access_register + : reinterpret_cast(vp.context().gp_register[instruction_info.register_1]); // notice how it only cares about the lower bits, i.e u16 + + switch (instruction_info.instruction) + { + case vmx::instruction_info_ldtr_tr_access_t::instruction_sldt: + low_word = vp.guest_segment_selector(context_t::seg_ldtr).flags; + break; + + case vmx::instruction_info_ldtr_tr_access_t::instruction_str: + low_word = vp.guest_segment_selector(context_t::seg_tr).flags; // no zero extension is happening here, it only writes the lower bits and doesn't differentiate between the destination. + break; + + case vmx::instruction_info_ldtr_tr_access_t::instruction_lldt: + vp.guest_segment_selector(context_t::seg_ldtr, segment_selector_t{ low_word }); + break; + + case vmx::instruction_info_ldtr_tr_access_t::instruction_ltr: + { + // + // After the segment selector is loaded in the task register, + // the processor uses the segment selector to locate the segment + // descriptor for the TSS in the global descriptor table(GDT). + // It then loads the segment limit and base address for the TSS + // from the segment descriptor into the task register. The task + // pointed to by the task register is marked busy, but a switch + // to the task does not occur. + // (ref: Vol2A[(LTR-Load Task Register)]) + // + // TL;DR: + // LTR instruction sets busy bit in the TSS and we need to + // emulate this behavior. + // + auto selector = segment_selector_t{ low_word }; + vp.guest_segment_selector(context_t::seg_tr, selector); + + auto& descriptor = vp.guest_gdtr()[selector]; + descriptor.access.type |= segment_access_t::type_tss_busy_flag; + } + break; + } +} +``` + # Disclaimer This has been tested using HVPP and some other public VMMs, in a KVM virtual machine.
Although i think the results on bare metal should be the same, more evaluation is required if this should be used legitimately.