Closed chiefmasterR closed 1 year ago
Sorry, the documentation for hypercalls is very bad. I'm still working on it. install_ept_hook
actually takes in a PFN as the parameter, not a physical address. This forces the caller to acknowledge that EPT hooks work on a page-by-page basis, whereas something like install_mmr
works with physical addresses. So try something like this and see if it works:
hv::install_ept_hook(orig_phys >> 12, exec_phys >> 12);
Sorry, the documentation for hypercalls is very bad. I'm still working on it.
install_ept_hook
actually takes in a PFN as the parameter, not a physical address. This forces the caller to acknowledge that EPT hooks work on a page-by-page basis, whereas something likeinstall_mmr
works with physical addresses. So try something like this and see if it works:hv::install_ept_hook(orig_phys >> 12, exec_phys >> 12);
yeah this one seemed to work, thanks
I made sure to lock both original and executable pages before installing a hook and I checked that physical pages are non-zero, and it still was not working. I logged each step of setting a hook in hv, and it seems like it is failing in
get_ept_pte()
where it checks forif (addr.pml4_idx != 0)
. Here is my code, you can try it yourself.By the way, I tried your example for setting monitored memory region in usermode, and it worked for me, so this is a bit confusing. I analyzed the code for hooking and setting MMR, the only difference I found is that in
install_ept_hook()
you do a bitwise left shift (auto const pte = get_ept_pte(ept, original_page_pfn << 12, true);
), but when you set a MMR you don't do this (auto const pte = get_ept_pte(cpu->ept, addr, true);
)