578 points · by bfoks · 4y ago · 270 comments
Two Hidden Instructions Discovered in Intel CPUs Enable Microcode Modification
Is it even possible to fully decode that language with publicly available information/tools?
Given that microcode is an internal mechanism of CPUs, I would expect its language to be impossible to decode for regular people because there is zero knowledge on how it works?
And even if there is some knowledge on it, won't Intel change the machine language around a lot among CPU generations because the lack of public usage means it can be changed constantly, thus rendering the existing knowledge useless quickly?
The mirocode is generally a sequence of uOps. But in Intel's case, there seems to be a more complex mechanism, called XuCode, that generates the uOps sequence. The XuCode ISA seems to be based on x86-64, as Intel says [1]:
> XuCode has its own set of instructions based mostly on the 64-bit Instruction Set, removing some unnecessary instructions, and adding a limited number of additional XuCode-only instructions and model specific registers (MSRs) to assist with the implementation of Intel SGX.
PS: Decoding of the XuCode microcode can potentially give precious information about uops encoding
PS2: You can find more information on uops encoding in another work from the same team [2].
[1]: https://www.intel.com/content/www/us/en/developer/articles/t...
https://www.intel.com/content/www/us/en/developer/articles/t...
What this seems to be is:
- Intel CPUs with SGX have an additional CPU mode that understands and runs XuCode, "XuCode is implemented as a variant of 64-bit mode code, running from protected system memory, using a special execution mode of the CPU."
-- I know that "ring" terminology is used to describe CPU modes, e.g. calling a hypervisor setup ring -1, SMM ring -2, and the Intel management engine ring -3. Seems like this mode is something like ring -2.5.
- "It is authenticated and loaded as part of a microcode update and is installed into a Processor Reserved Memory (PRM) range, typically allocated by system firmware. The memory range itself is protected from software and direct memory accesses by the Processor Reserved Memory Range Registers (PRMRRs)."
So the BIOS steals a bit of your RAM (which the ME already does), sets it up to be the PRM, and a microcode update unpacks XuCode now contained in the microcode data, and puts it in this PRM. I guess some SGX instructions are essentially a specialized form of INT instructions that "exception out" specifically to this special CPU mode/PRM space.
So I'm under the impression XuCode is essentially called by the microcode when certain SGX instructions are encountered.
Weird ...
Each microinstruction is composed of many bit fields, which contain operation codes, immediate constants or register addresses.
The format of the microinstruction is changed at each CPU generation, so, for example, the microinstructions for Skylake, Tiger Lake, Gemini Lake or Apollo Lake have different formats.
Therefore, someone who discovers the microinstuction format for one of them has to repeat all the work in order to obtain the format for another CPU generation.
In the presentation from
https://www.youtube.com/watch?v=V1nJeV0Uq0M
the authors show the microinstruction format for Apollo Lake, which is a kind of VLIW (very long instruction word) format, encoding 3 simultaneous micro-operations, each of which can contain three 6-bit register addresses and a 13-bit immediate constant.
For Apollo Lake, the microinstruction encoding is somewhat similar to the encoding of an instruction bundle (containing 3 instructions) in the Intel Itanium processors.
It is likely that in the mainstream Intel Core or Xeon CPUs the micro-instruction format is significantly more complex than this.
The team which reverse-engineered the microinstruction format was able to do this because they have exploited a bug in the Intel Management Engine for Apollo Lake/Gemini Lake/Denverton to switch the CPU into a mode in which it allows JTAG debugging.
Using JTAG they could read the bits from some internal busses and from the microcode memory. The bits read were intially meaningless, but by executing many test programs and comparing what the CPU does, with the bits read at the same time via JTAG, they eventually succeeded to guess the meaning of the bits.
For most Intel CPUs, there is no chance to switch them into the debugging mode, unless you receive a secret password from an Intel employee (which probably is within the means of some 3-letter agencies).
Once switched into the debugging mode, it is possible to do things as complex as making the CPU to replace the normal execution of a certain instruction with the execution of an entire executable file hidden inside the microcode update (and you can also update the microcode directly, bypassing the normal signature verification step).
However, for most motherboards, it is likely that switching to the debugging mode also requires physical access to change the connection of some pin, not only the secret password, though exceptions are known, where the MB manufacturers have forgotten to disable the debugging mode on the PCB.
Phone calls are easier.
Changing things around is expensive, even if they don't have external compatibility obligations.
I have a couple of quarks, never used them.
Seems logical that it would be mostly be standard machine code, since there are instructions which translate 1:1 to microcode (I assume) no use translating everything, that’d require more space and be harder on everyone for little reason.
Though there might be privileged instructions which would only be available in microcode (would be rejected by the frontend), and which you would have to reverse-engineer separately.
Getting a dump means getting access to a memory controller of sorts and asking it to read you back the contents of addresses, right?
But you’re really getting what the memory controller decides to give you. There could be more indirection or sneakiness, right? Ie. I could design a memory controller with landmines, as in “if you ask for 0x1234 I will go into a mode where I send back garbage for all future reads until power is cycled.”
Is this a thing?
Yes, here the memory is read through a debug bus.
> I could design a memory controller with landmines, as in “if you ask for 0x1234 I will go into a mode where I send back garbage for all future reads until power is cycled.”
Yes, it basically looks like a backdoor, and you can do it the other way around: The memory read through the debug bus is exactly the content of the ROM, but the memory controller is made so that when the processor reads a specific address or data it doesn't return the value in memory but something else.
This way even a person who would use a visual or an intrusive memory extraction method would not notice the backdoor. The only way to discover it is to do a full inspection of the logic, which probably nobody will do.
> Is this a thing?
Yes, sometimes some addresses in a memory system are effectively not readable (write only). As for example with some memory-mapped configuration registers, a 0-value may be returned instead of the register contents.
But your question sounds to me more about mechanisms to hide a backdoor.
Regarding hardware backdoors, they are always theoretically and practically possible, and almost always undetectable. Since nothing prevents the designer from introducing logic that has malicious behaviour and it's nearly non-observable.
This is the problem with theories about backdoors in modern processors. Without evidence, these theories fall into the realm of conspiracy theories. But it's almost impossible to have evidence and no-one can say that it doesn't exist.
except for intel, if they publish how their hardware and microcode works internally? aka, opensourcing their internal design?
Of course, they can't since it will allow competitors to copy it, but would that work theoretically?
Even if they released absolutely everything, there's no way to verify that the chips they actually make and sell conform to a design that they release without inspecting the actual chip. If you're really paranoid, you'd have to inspect every chip, and that's usually a destructive operation.
However the way they obtained these dumps is by going deep into debugger mode of the cpu which makes me doubt anything spooky would be going on.
Someone screwing some C code and creating a vulnerability isn’t that interesting to me, but going on such low level and fundamental stuff makes me giddily, if not a bit scared.
Last time something like this caught my eye was that iMessage[1] NSO thing, not because they managed to escaped the sandbox, but because of the insanely clever way they did it.
[1] https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-i...
I was so excited to try out sandsifter I spent an entire night shift compiling everything on a raspberry pi or rockchip.
Sandsifter is an x86 instruction dumper. Sometimes I wonder if the head injuries I took as a teen affected me in a subtle way, because I did watch the entire sandsifter presentation where he repeatedly says x86.
He also has a cool presentation about ring -1, -2, and beyond, of which the reader for that stuff was what I figured was used to find the actual OP.
If I'm understanding correctly, this allows us to view (previously obfuscated) code that runs on certain (recent-ish) Intel processors?
What are the consequences of this?
Yes, but this "code" is the Intel microcode.
In a modern processor, instructions are translated in a sequence of micro-operations (uOps) before execution; These uOps are small instructions that the processor can execute with more ease. Ultimately, this allows to build more performant processors.
But some instructions require translation into a uOps sequence that is too complex to be handled like other instructions. Modern processors therefore feature a "microcode sequencer", and the "microcode" is the configuration of this component.
And this work allows us to interpret a previously misunderstood part of the microcode.
> What are the consequences of this?
There are no real direct consequences for users.
But this helps to better understand how modern Intel processors work; Especially security researchers will be able to better understand how some security instruction works (mainly the SGX extension). In the long term, they may find Intel errors (as has already happened previously) which will be fixed in next Intel processor generation.
Although security issues may be detected in Intel processors, this will probably have no impact for normal users, but it could affect some companies.
(*) first commercial architecture I know of...
There are a bunch of privilege levels in Intel CPUs (https://en.wikipedia.org/wiki/Protection_ring, relatively boring), used for memory protection and user/kernel mode separation (IIUC, I think I'm correct). They can be controlled by whatever code boots the CPU ("gets there first"), because the CPU boots in the most trusting state.
Over time the set of available levels proved insufficient for security and new levels were added with negative numbers so as not to disrupt the existing status quo. Ring -1 is used for virtualization and can also be controlled by whatever boots first (ie, outer code can create VMs and enter them, but the CPU faults if inner code attempts to access the virtualization instruction set), but Ring -2 and Ring -3 are used by the CPU itself.
Essentially, in the same way whatever the bootloader loads gets control over a bunch of interesting functionality because that code got there first, Ring -2 and -3 are controlled by code running directly on the CPU that gained control of the system before the bootloader and in some cases even UEFI was started. The significant elements are that a) this code can theoretically be altered by system (microcode) updates; b) these components run *completely* independently of the operating system - IIRC, the Management Engine is based on Minix running on a tiny 486-class core somewhere on the CPU die; and c) this invisible functionality has the ability to read and write all of system RAM. What's that? A glitch? A couple of bytes of RAM just got modified? That made the running Linux kernel suddenly think a process's effective UID is 0? Must have been the butterfly effect!
A bit of Googling found this overview of Ring -1 to -3 which I'd say is really good, definitely worth clearing your cookies to read if Medium is yelling at you about subscribing:
https://medium.com/swlh/negative-rings-in-intel-architecture...
I've been getting a lot of mileage out of "scribe.rip" that was posted a while back (https://news.ycombinator.com/item?id=28838053)
https://scribe.rip/swlh/negative-rings-in-intel-architecture...
As in, there may a possibility for almost every computer being vulnerable to a RCE that bypasses even the OS.
Intel microcode can be loaded at runtime. If there's a backdoor in the microcode then it can, by definition, be patched.
h0t_max’s research means that future attacks — once your local machine has been infiltrated by some other means — can do a lot more damage than simply encrypting your filesystem or sending spam. They can rewrite the way your CPU works.
When your OS gets attacked by malware it is attacking the layer above the bare metal on which your OS runs. The base hardware remains untouched. You can at least clean things up by installing a new OS on the bare metal.
If malware attacks the bare metal itself, then you are stuck out of luck.
If the malware shuts that patching off...
Old ones though are open book (of a sort).
The 6502 for the apple II was obviously hand generated so it microcode is weird, but the 68k for the original Mac was pretty normal microcode as we would think of it today.
Reality: nobody cares.
I'd like to talk about how we patch this pervading cynicism and replace it with a model that's actually useful.
It isn't true on face value. Consider the course of the Cov19 pandemic. Two things spread. One was a virus. The other was an idea, news about a virus. The latter spread much faster than the former. It spread because people love "doom". Any story about the impending "end of everything" is lapped up, relished and shared by the public.
There are well understood stages to information propagation. After "Is this real?" and "Am I affected?" comes the question of "what to do?"
I think this is where your assertion about "care" comes in. Some events will blow-up and burn out fast. People run around like headless chickens enjoying the drama about something remote to their lives, but ultimately nobody can do anything, so focus recedes. Wars and famines are like that. Curtis calls this "Oh Dearism".
Alternatively, if there is any residual effect, new events connected to the initial story, it feeds and grows. The initial "All the chips are broken!" story that would die after a 24 hour news cycle becomes an ongoing "situation". Then people care, because it's cool to care. It gets a catchy handle "Evil-Inside" and a news slogan "The chips are down". And then it won't go back in the bottle.
To reformulate your "Nobody cares" - as a question - "Do people have sensible cares that are proportionate to the threat?" No. But if the media tells them to care because cars are running off the road and there's a massive uptick in cybercrime, which nobody can ignore and is directly attributable to a single cause, then the "care" (hysteria) can get worse than the problem (which may have happened with Cov19 to some degree).
Finally, they may care, but about completely the wrong thing. One suspects, if it turns out there is indeed some serious drama in Intel chips, then Intel and the US government will try to paint the security researchers as irresponsible hackers who unleashed this upon the world.
I wouldn't be so sure...
After hearing that American nuclear launch codes were all zeroes for decades, nothing surprises me.
edit: there was this piece interesting headway mentioned elsewhere in comments: https://news.ycombinator.com/item?id=32149210
Nothing of that level on Intel so far.
Over time, these instructions have gotten more and more complicated. Now there are "instructions" like "Enter Virtual Machine Monitor" which actually complex manipulations of tons of different registers, memory translations, and subsystems inside of the CPU.
And, even simple, primitive instructions like call, jump, and return actually need to check the state of various pieces of the processor and edit lots of internal registers, especially when we start to consider branch prediction and issues like Spectre.
It wouldn't be very plausible to hard-wire all of these complex behaviors into the CPU's silicon, so instead, most instructions are implemented as meta-instructions, using "microcode." "Microcode" is just software that runs on the CPU itself and interprets instructions, breaking them down into simpler components or adding additional behaviors. Most CPUs are really emulators - microcode interprets a higher level set of instructions into a lower level set of instructions.
Historically, Intel and more recently AMD have encrypted this "microcode," treating it as a trade secret. This makes people who are worried about secret hidden backdoors _very_ worried, because their CPU's behavior is depending on running code which they can't analyze or understand. This has led to all sorts of mostly unfounded speculation about secret back doors, CPUs changing the behavior of critical encryption algorithms, and so on and so forth.
Decrypting this microcode will theoretically allow very skilled engineers to audit this functionality, understand the implementation of low-level CPU behaviors, and find bugs and back-doors in the CPU's interpretation of its own instructions.
Replacing this microcode silently would be absolutely catastrophic security-wise, because an attacker could silently change the way the CPU worked, right out from under running software. But, there is no evidence this is possible, as the microcode is digitally signed and the digital signature implementation, so far, seems to be correct.
Perhaps it is unwise to inhibit the spread of ideas which lead to auditable systems.
Edit: I'm also definitely not saying that paper voting is better than urna eletrônica. Both methods have big attack surfaces.
RC4 had already been busted wide open when the two generations of CPUs (Gemini Lake and Apollo Lake) this affects were released.
Why would they use a known insecure cipher?
"In a statement, Intel officials wrote: ... we do not rely on obfuscation of information behind red unlock as a security measure."
(BTW, I work on Linux at Intel, I'm not posting this in any official capacity)
Oh, great! Isn't there a way where intel could provide keys so we could get rid of IME even if it means we won't be able to play DRM'ed content?
Or do you mean.
- the TXE vulnerability and / or undocumented debugging mode (so microcode wouldn’t have been extracted)
- microcode encryption so the microcode would always have been completely readable
- x86
- Intel itself
?
I can see why they would sign/encrypt it so that things got safer, but then they should have done a much better job of it. If it was encrypted to hide something that could not stand the light of day then that's an entirely different matter altogether.
Time will tell.
Edit: I assume this threat has existed as long as updatable microcode has.
Basically, the easier route is usually to just find a way to bypass the check once, and use that to install a more permanent bypass.
It may be possible through power fault injection to flip the bits of the public key such that you could get it to accept microcode signed with your own private key, but I would be very surprised if the public key weren't burned into the structure of the CPU itself in a manner that renders it immune to such attacks.
Of course, power fault injection may still allow you to bypass the verification routine altogether instead of modifying the key it verifies with.
Especially considering how they gained this knowledge:
"Using vulnerabilities in Intel TXE we had activated undocumented debugging mode called red unlock and extracted dumps of microcode directly from the CPU. We found the keys and algorithm inside."
And looking further down, some X86 instructions (that people would usually call low-level) actually trigger execution of an entire ELF binary inside the CPU (implemented in XuCode). Just wow.
Let's be optimistic - say, after lengthy, rigorous expert analysis it turns out there are no backdoors or prepared traps for potential malware within Intel CPUs. That's a big boon for security everywhere, and for Intel's share price.
If on the other hand, it turns out against Intel, the evidence is literally baked into silicon within billions of devices in the wild which will become e-waste overnight.
With this TikTok thing in the wind the Chinese will ban Intel... etc.
The stakes are high. The problem was always lack of transparency. Putting encrypted microcode into consumer CPUs was always a dumb idea. And why? To protect the media conglomerates. Another reason we need to re-examine the role and value of "intellectual property" in society.
Not just e-waste, they can also become a huge liability. In a presentation, the authors mention that one of the CPU families which have this vulnerability were used in Tesla cars. Tesla apparently switched to AMD APUs around December 2021.
Serious question: which consumer CPUs have unencrypted microcode? AMD processors have had theirs encrypted for a decade, Intel for even longer, and nothing I've seen indicates that any ARM models have unencrypted microcode updates floating about.
While these are reasonably widespread in the cheapest personal computers and servers, the impact of examining their microcode is much less than if the decryption keys for some of the mainstream Core or Xeon CPUs would have been obtained.
In a more decent world, the manufacturers of CPUs would have been obliged to only sign their microcode updates, without also encrypting them, to enable the owners of the CPUs to audit any microcode update if they desire so, in order to ensure that the update does not introduce hidden vulnerabilities.
This XuCode execution engine is not a new or unknown thing - https://www.intel.com/content/www/us/en/developer/articles/t...
We can lament the state of computer security but that feeling is surely sunken, past tense.
This isn't a correct characterization of the suspicion that Intel microcode has backdoors in it. The suspicion isn't just based on distrust of authority, like flat Earth, etc, but also on the org having means, method, and opportunity to remotely modify the operation of a CPU. And it operates within the domain of the USG, who have demonstrated a keen interest in weaponizing 0-day exploits.
What better way to acquire a novel 0-day than to simply write one known only to you and distribute it from the source? This is a good plan, but it comes with a substantial risk to Intel, or any company who wishes to maintain a trust relationship with its customers.
That said, I don't think anyone doing this is stupid, and for safety they would not install microcode malware on everyone, just some. This means we will find nothing in general CPUs, and anecdotal reports finding "something" can easily be dismissed as malicious or noise.
The truly paranoid need not worry, even if the microcode is seen to be harmless, there is always the possibility that hardware you buy is interdicted, modified, and sent onward, such that your paranoia can remain intact.
In this thread, I see implications about big media controlling microcode (which doesn't seem to be impacting piracy — if anything, it's easier than ever before), about governments imminently finding backdoors and trashing an entire generation of chips, and other extreme outcomes that seem wholly out of step with reality. (Not in the "Everyone else is dumb but we few are smart" way; in the "I have not interacted with a business or government ever" way)
I'm sure the 2600 crowd will have their next "Yes but what about the *Long form* birth certificate"-style goalpost shift if there are no backdoors found.