zydis icon indicating copy to clipboard operation
zydis copied to clipboard

Undefined x86 opcodes known to be used for syscall-like functionality

Open tremalrik opened this issue 3 years ago • 2 comments

There are a number of undefined x86 instruction encodings that have been used to provide syscall-like functionality through the #UD (int 6) invalid opcode exception handler. The ones I've been able to find are:

The question would then be - should Zydis recognize any of these encodings?

tremalrik avatar Aug 27 '21 00:08 tremalrik

Thanks for the issue! We have considered this before, but decided against it. We only support what is implemented in hardware by Intel, AMD and VIA.

With these software instructions, it's hard to decide where to draw the line. There are hundreds (if not thousands) of hobby-hypervisors. There are very old hypervisors that are mostly dead (e.g. VirtualPC). Some hypervisors even use valid privileged instructions that happen to cause an exit to the hypervisor. All of them would need dedicated decoder modes and filters. We also don't want to just enable them by default, because obfuscators could emit them and confuse users into thinking that a valid instruction is going to be executed. We simply don't think it's worth the hassle.

athre0z avatar Aug 27 '21 00:08 athre0z

I was looking through open issues. I thought I would just add a thought. I am not sure if it's been considered, but malware sometimes use instructions like these to detect if they are running in a VM. Then for instance and it will behave differently. This can make analysis more difficult.

But yea there are lots of random hypervisors, and yea it does make sense to not show any of these by default for users in case users think they are valid, for what end up often being sorta of a hack/unintended use. "LOCK NOP" is kinda of a fun example of a hack since it's LOCK is not permitted on NOP and will trigger a trap, but bad idea at the same time since future hardware could change that behavior and handle the non-permitted LOCK prefix byte in a different manner why L4 decided to use this is kinda funny to me. (Also not VM related)

Still issues like these are common enough that some how handling them seems useful to me. Where to draw the line that something is too obscure to include seems a challenge.

Keith-Cancel avatar Oct 29 '21 00:10 Keith-Cancel