rep_lodsb 3 days ago

Modern processors[1] cause an exception on invalid opcodes, instead of performing some undocumented function. They also have control bits to enable/disable features like being able to read certain "system" registers from userspace.

User code generally can't directly violate security (like writing to memory in the kernel or a more privileged process) by just running some instruction, however there are timing side channels that can be used to leak information. The terms to search for are "Spectre" and "Meltdown".

The timestamp counter is one of the registers that an OS can prevent software from reading, but mainstream ones still don't do this AFAIK. Perhaps it would be better to only enable it for processes that have a legitimate reason to need a high-resolution timer.

And of course, x86 has accumulated enough legacy features that you could use to confuse a person reading your code, my user name is one such instruction ;)

[1] pretty much everything newer than the original 8086

1
rbanffy 3 days ago

They no longer have stable undocumented instructions like the Z80 had (the 6502 lost it on the 65C02) but they still have sizable errata published explaining what legal instructions don't work as expected in which conditions. Also, I remember this tool: https://github.com/Battelle/sandsifter