News for hackers. Stuff that matters.
Re:x86 finds its way into the iPhone by Symmetry on Friday September 14, 2018 @01:45PM (#17989241)
There isn't anything to really indicate that this processor has many more instructions than a 8086, befitting its role as an embedded device. I'm not aware of any difference in x86 and ARM semantics in embedded that might cause a problem.

Now, the fact that an x86 instruction stream isn't self-synchronizing can represent a danger in theory. That is, you can craft a sequence of x86 instruction such that if you start executing form 0x0000 they're safe and friendly but if you start executing from 0x0001 you'll see a different, equally valid, stream of instructions that might do something malicious. But that doesn't seem like a credible attack vector in this case given the embedded nature of the code.

Re:x86 finds its way into the iPhone by dfox on Friday September 14, 2018 @02:06PM (#17989403)
Well, the disassembly in the article contains LGDT, so it is certainly significantly more complex core than 8086.
Re:x86 finds its way into the iPhone by smolsky on Friday September 14, 2018 @04:41PM (#17990755)
Not just that, the second listing used "e" registers, so 32-bit mode (and not just 8086).
Re:x86 finds its way into the iPhone by dfox on Friday September 14, 2018 @05:45PM (#17991244)
Given how the i386 instruction encoding works that is not significant as in 16b mode mov ax, bx has same encoding as mov eax, ebx in 32b mode (in reality it is somewhat more complex, but this is the gist of it) and thus how it gets disassembled depend on the configuration of the disassembler. One thing that would certainly point on the code being for 32b mode would be stores into control registers (eg. mov cr0, eax instead of smsw ax, which have different encodings, and slightly different effect, with the second one being somewhat nonsencial in 32b mode).
Re:x86 finds its way into the iPhone by dfox on Friday September 14, 2018 @05:53PM (#17991297)
On the other hand the 32b mode code in the disassembly snippet containing lgdt looks reasonable, if it would be 16b code disassembled as 32b it would lead to non-sense as it combines 16b and 32b instructions in meaningful way.
Re:x86 finds its way into the iPhone by monocasa on Friday September 14, 2018 @05:39PM (#17991198)
Sure, lgdt implies 32 bit protected mode.
Re:x86 finds its way into the iPhone by dfox on Friday September 14, 2018 @05:48PM (#17991264)
LGDT is valid even for 286-style 16b protected mode.
Re:x86 finds its way into the iPhone by monocasa on Friday September 14, 2018 @06:09PM (#17991443)
Oh, you're totally right.
Re:x86 finds its way into the iPhone by monocasa on Friday September 14, 2018 @01:56PM (#17989325)
I'll throw out there that unaligned, unintended instructions can give an attacker more options from an ROP perspective. But it's only a small benefit for the attacker. And for something like this 30MB binary it's six of one, half dozen of another practically speaking.
Re:x86 finds its way into the iPhone by mehrdadn on Friday September 14, 2018 @02:33PM (#17989651)
What does "self-synchronizing" mean in this context? I've never heard of a self-synchronizing instruction stream. Does it just mean "memory-aligned"?
Re:x86 finds its way into the iPhone by kmeisthax on Friday September 14, 2018 @03:47PM (#17990314)
No.

Memory-aligned means that instructions can only exist on certain addresses. (It also implies a minimum instruction length.) On most RISC architectures, instructions are also a constant size, with the same alignment. For example, a MIPS instruction stream consists of 4-byte instructions aligned to every fourth byte in memory. Memory alignment and constant instruction size ensure that any given instruction stream can only be executed as itself, or part of itself. Note that this is not self-synchronization - if you removed a byte from an instruction stream, you would get a wildly different instruction stream.

(I said MIPS because ARM instruction streams can be THUMB, which permits a different instruction interpretation for the same stream, and thus defeats the security advantages of memory alignment requirements.)

Self-synchronizing means that each subdivided unit (usually byte) of a stream also indicates if it is the start of a new symbol within that stream. For example, UTF-8 is an example of a self-synchronizing byte stream. In UTF-8, encoded codepoints have variable-length representations. However, the upper bits of each byte clearly indicate not only if the byte is the start of a new codepoint, but how many bytes follow to complete the codepoint. This means that a deleted or altered byte will only delete or alter the symbol it's a part of, and not any other part of the stream.

Self-synchronization and alignment requirements address the same problem - ambiguous instruction streams - by different methods. Memory alignment prohibits you from reinterpreting the stream; while self-synchronization makes doing so less valuable.

Re:x86 finds its way into the iPhone by Dylan16807 on Friday September 14, 2018 @04:18PM (#17990587)
But do any self-synchronizing instruction sets exist? (And are in commercial silicon?) It seems like it would be very annoying for density and constant-encoding reasons with 8 bit code units, and none of the variable 16/32 bit encodings I can name do it either.
Re:x86 finds its way into the iPhone by dezgeg on Saturday September 15, 2018 @03:57AM (#17993461)
The PIC18 instruction set has this property. Most instructions take up a single 16-bit instruction word, but the few ones that take up 2 words all have the 0b1111 in the high bits of the second word, which would execute as a NOP if branched into.

This encoding is presumably a consequence of the instruction set containing conditional skip instructions. That is, the skip instructions don't have to parse the instruction stream for 2-word instructions but can always just skip a single instruction word and let the second word execute as a NOP.

Re:x86 finds its way into the iPhone by mehrdadn on Friday September 14, 2018 @04:52PM (#17990839)
Ohh, thanks! Now I recall I'd heard the term regarding UTF-8 at some point but completely forgotten about it.

It reminds me very much of prefix-freeness. Is it fair to say that that's what we really need (without alignment)? It seems self-synchronizing is a bit stronger (no pun intended) but not necessarily necessary to ensure you can't jump into the middle of an instruction?