Closed
Bug 593517
Opened 16 years ago
Closed 8 years ago
Harden nanojit
Categories
(Tamarin Graveyard :: Baseline JIT (CodegenLIR), defect)
Tracking
(Not tracked)
RESOLVED
WONTFIX
Future
People
(Reporter: rreitmai, Unassigned)
References
Details
(Keywords: meta, sec-want, Whiteboard: [sg:want P3] Tracking)
This is a tracking bug for ongoing JIT hardening work.
Bugs will be opened for each work item that falls out of this effort, some prototype work for x86 is available at : asteam/hg/users/rreitmai/hardening
| Reporter | ||
Updated•16 years ago
|
Group: tamarin-security
| Reporter | ||
Comment 1•16 years ago
|
||
Original details outlining work:
Premise
======
(1) Non-JIT vulnerabilities in tamarin identified in the iSEC report (e.g. pcre, AbcParser.cpp) have already been addressed and will not be discussed.
(2) The dictionary attack (discussed in iSEC Appendix E2.1) has been addressed and will not be discussed.
(3) Advanced JIT hardening (i.e. above and beyond page protection bits) only needs to occur on x86 based platforms as most current exploits rely on executing a 'hidden' instruction stream that is accessed via a mis-aligned address. This property is only available on architectures with variable length instruction sets.
(4) The main attack vector is through manipulation of generated code. As tamarin already has heap protection for non-code segments (i.e. non-executable page protection bits are enabled for data) , only code pages used by the JIT are vulnerable.
Attacks
======
(A) Constant manipulation is a technique wherein the attacker utilizes a predicable output from a given set(s) of constants to encode instructions within the resultant code being generated.
Mitigation:
Constant folding (and reductions) help to reduce the effectiveness of this approach as a long sequence of constant operations will be reduced to a smaller set, in which it is much harder to encode meaningful sequences.
Additionally obfuscating and randomizing the constant values themselves provides an additional layer of protection.
The cost associated with this approach is that the constant must be decoded, resulting in a possible performance penalty.
Another way to inject non-determinism into the system would be to randomized the amount of constant folding that occurs. A simple algorithm such as using a random value to determine whether to constant fold or not, might provide the needed protection. For example, the JIT could compute a random value at initial execution and this value would be used as the # of constant values held in the cse table until a reset occurs.
Finally iSEC item E2.2 discusses the placement of constants into non-code pages. This technique might while sounding simple in principal will require an additional register (the Intel instruction set does not support pc-relative addressing) most likely having an adverse affect on performance.
if the above technique (re: cse randomization) does not cause performance regression, then its most likely sufficient and we will not have to resort to an off-page constant pool. (Also note, that this approach satisfies the recommendation iSEC E2.4)
(B) 'Sewing' attack - Fragments of generated code are stitched together via ret/jmp/call to produce a desired result
Mitigation:
Inject non-determinism in the instruction stream.
Random function alignment bounded by 'int 3' seems like an inexpensive and worthwhile means of protection.
The insertion of instruction(s) that have no effect on program execution (such mov eax,eax) at random points in the code, might also be worthwhile and mitigates the issue highlighted in iSEC E2.3
(C) Threaded rwx attacks (see iSEC E2.5)
This attack relies on being able to overwrite code generated by the JIT during the period in which the memory protection bits have not yet transition to r-x (i.e. they are still rw-).
One approach to foiling this type of attack would be to compute a CRC value as instructions are written to the page, making the page r-x and then recomputing the CRC (based on page contents) to ensure that it has not deviated.
Another defense against this type of attack is to shrink the time that the code is vulnerable, so setting page protections as each page is processed might be a valid approach.
Updated•16 years ago
|
Whiteboard: Tracking
Updated•16 years ago
|
Priority: -- → P2
Target Milestone: --- → flash10.1.x-Salt
| Reporter | ||
Comment 2•16 years ago
|
||
(A) Including notes from an email dialog discussing item (A) from above:
>> The cost associated with this approach is that the constant must
>> be decoded, resulting in a possible performance penalty.
> maybe. if we inlined the constant value XOR'd some constant-but-random-at-jit-time salt,
> then the cost would be 1 ALU up, and ~5 bytes of code space, which
> should be negligible.
Agreed we'll want to explore this approach and its affect on performance.
>> randomized the amount of constant folding that occurs.
> I worry that this can cascade. Not constant folding a value,
> could lead to not removing a branch, or not removing a redundant
> expression. If we randomly did this inside a hot inner loop, then
> we could have some major but nondeterministic slowdowns. Benign
> non-determinism that led to minor-but-flat slowdowns is preferrable
> to randomly killing performance in small random pieces of code
> (bumpy/uneven slowdowns).
I was thinking of a 'lighter' version in which we would introduce some amount of randomness at the LIns level with respect to re-using the LIns in the cse table or generate a new; the former is currently the case when cse is enabled.
Interestingly it turns out that on x86 this has almost no effect, as the back-end is sufficiently 'smart' and folds most constant values into the instruction anyway.
see bug 595043
>> placement of constants into non-code pages.
> We don't require PC-relative addressing to load from
> a constant table, since we know the address of the
> constant table. We can use an immediate-address load.
True, but the effect is similar in that we'll need to burn an additional register to make this happen.
opened bug 595045 for further discussion.
Comment 3•16 years ago
|
||
(In reply to comment #1)
>
> (3) Advanced JIT hardening (i.e. above and beyond page protection bits) only
> needs to occur on x86 based platforms as most current exploits rely on
> executing a 'hidden' instruction stream that is accessed via a mis-aligned
> address. This property is only available on architectures with variable
> length instruction sets.
ISTR that ARM makes the switch from the 32-bit instruction set to the 16-bit instruction set and back at call/return time, suggesting that there is a limited form of variable-length instructions also on ARM. Don't know how exploitable it is, of course, but in principle one could consider a JIT that produces one type of instruction stream being tricked into executing it as the other type.
Some MIPS implementations also have 16/32 instruction formats a la Thumb/ARM.
| Reporter | ||
Comment 4•16 years ago
|
||
(In reply to comment #3)
> Don't know how exploitable it is
Yes I didn't recall to include this in the write-up above, thanks for mentioning it.
And, as you point out, the large question is how exploitable is it?
Shouldn't this bug be filed under nanojit and discussed with the Mozilla team?
Also, we need to consider the needs of the FP9 backport -- we should discuss the value/risks of implementing for the FP9 JIT.
Assignee: nobody → rreitmai
Status: NEW → ASSIGNED
Flags: flashplayer-qrb+
| Reporter | ||
Updated•16 years ago
|
Group: tamarin-security
Updated•16 years ago
|
Whiteboard: Tracking → [sg:want P3] Tracking
Updated•14 years ago
|
Status: ASSIGNED → NEW
Updated•14 years ago
|
Assignee: rreitmai → nobody
Comment 6•8 years ago
|
||
Tamarin is a dead project now. Mass WONTFIX.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → WONTFIX
Comment 7•8 years ago
|
||
Tamarin isn't maintained anymore. WONTFIX remaining bugs.
You need to log in
before you can comment on or make changes to this bug.
Description
•