Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Issue 1185703004: Add constant blinding/pooling option for X8632 code translation (Closed)

Created:
5 years, 6 months ago by qining
Modified:
5 years, 6 months ago
CC:
native-client-reviews_googlegroups.com
Base URL:
https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Add constant blinding/pooling option for X8632 code translation. GOAL: The goal is to remove the ability of an attacker to control immediates emitted into the text section. OPTION: The option -randomize-pool-immediates is set to none by default (-randomize-pool-immediates=none). To turn on constant blinding, set -randomize-pool-immediates=randomize; to turn on constant pooling, use -randomize-pool-immediates=pool. Not all constant integers in the input pexe file will be randomized or pooled. The signed representation of a candidate constant integer must be between -randomizeOrPoolImmediatesThreshold/2 and +randomizeOrPoolImmediatesThreshold/2. This threshold value can be set with command line option: "-randomize-pool-threshold". By default this threshold is set to 0xffff. The constants introduced by instruction lowering (e.g. constants in shifting, masking) and argument lowering are not blinded in this way. The mask used for sandboxing is not affected either. APPROACH: We use GAS syntax in these examples. Constant blinding for immediates: Original: add 0x1234, eax After: mov 0x1234+cookie, temp_reg lea -cookie[temp_reg], temp_reg add temp_reg, eax Constant blinding for memory addressing offsets: Original: mov 0x1234(eax, esi, 1), ebx After: lea 0x1234+cookie(eax), temp_reg mov -cookie(temp_reg, esi, 1), ebx We use "lea" here because it won't affect flag register, so it is safer to transform immediate-involved instructions. Constant pooling for immediates: Original: add 0x1234, eax After: mov [memory label of 0x1234], temp_reg add temp_reg, eax Constant pooling for addressing offsets: Original: mov 0x1234, eax After: mov [memory label of 0x1234], temp_reg mov temp_reg, eax Note in both cases, temp_reg may be assigned with "eax" here, depends on the liveness analysis. So this approach may not require extra register. IMPLEMENTATION: Processing: TargetX8632::randomizeOrPoolImmediate(Constant *Immediate, int32_t RegNum); TargetX8632::randomizeOrPoolImmediate(OperandX8632Mem *Memoperand, int32_t RegNum); Checking eligibility: ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); ISSUES: 1. bool Ice::TargetX8632::RandomizationPoolingPaused is used to guard some translation phases to disable constant blinding/pooling temporally. Helper class BoolFlagSaver is added to latch the value of RandomizationPoolingPaused. Known phases that need to be guarded are: doLoadOpt() and advancedPhiLowering(). However, during advancedPhiLowering(), if the destination variable has a physical register allocated, constant blinding and pooling are allowed. Stopping blinding/pooling for doLoadOpt() won't hurt our randomization or pooling as the optimized addressing operands will be processed again in genCode() phase. 2. i8 and i16 constants are collected with different constant pools now, instead of sharing a same constant pool with i32 constants. This requires emitting two more pools during constants lowering, hence create two more read-only data sections in the resulting ELF and ASM. No runtime issues have been observed so far. BUG= R=stichnot@chromium.org Committed: https://gerrit.chromium.org/gerrit/gitweb?p=native_client/pnacl-subzero.git;a=commit;h=253dc8a870cbd144ba217a44efbd07e6bcd71e97

Patch Set 1 #

Patch Set 2 : reformat #

Total comments: 87

Patch Set 3 : remove parameter-unused warning in shouldBeRandomizedOrPooled() #

Patch Set 4 : Fix the issues in the last commit #

Patch Set 5 : reformat #

Total comments: 20

Patch Set 6 : remove the MemOperand->getBase()->setWeightInfinite() in randomizeOrPoolImmediate() #

Patch Set 7 : Avoid calling randomizationOrPoolImmediate() multiple times on a same operand" #

Total comments: 39

Patch Set 8 : Add bool flag: Randomized to OperandX8632Mem class, fix comments, rebased to master:b0a8c24ecd98f4b… #

Total comments: 9

Patch Set 9 : #

Patch Set 10 : add command line option for immediates randomization/pooling threshold #

Patch Set 11 : minor #

Patch Set 12 : Fix the default randomization/pooling threshold to be 0xffff #

Total comments: 15

Patch Set 13 : fix the lit tests and some issues #

Total comments: 6

Patch Set 14 : change the default sz-seed back to 1. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+706 lines, -64 lines) Patch
M src/IceClFlags.h View 1 2 3 4 5 6 7 8 9 2 chunks +20 lines, -0 lines 0 comments Download
M src/IceClFlags.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 3 chunks +28 lines, -1 line 0 comments Download
M src/IceDefs.h View 1 2 3 4 5 6 7 1 chunk +3 lines, -0 lines 0 comments Download
M src/IceELFObjectWriter.cpp View 1 2 3 4 5 6 7 8 3 chunks +5 lines, -2 lines 0 comments Download
M src/IceGlobalContext.h View 1 2 3 4 5 6 7 8 9 10 11 12 4 chunks +20 lines, -1 line 0 comments Download
M src/IceGlobalContext.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 3 chunks +12 lines, -1 line 0 comments Download
M src/IceInstX8632.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 2 chunks +8 lines, -0 lines 0 comments Download
M src/IceInstX8632.cpp View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M src/IceOperand.h View 1 2 3 4 5 6 7 8 9 10 11 12 4 chunks +25 lines, -1 line 0 comments Download
M src/IceOperand.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +18 lines, -0 lines 0 comments Download
M src/IceTargetLoweringX8632.h View 1 2 3 4 5 6 7 1 chunk +8 lines, -0 lines 0 comments Download
M src/IceTargetLoweringX8632.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 24 chunks +425 lines, -57 lines 0 comments Download
A tests_lit/llvm2ice_tests/randomize-pool-immediate-basic.ll View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +133 lines, -0 lines 0 comments Download

Messages

Total messages: 26 (2 generated)
qining
5 years, 6 months ago (2015-06-12 18:08:39 UTC) #2
Jim Stichnoth
Nice start! This touches and messes with some very fundamental assumptions and machinery in Subzero, ...
5 years, 6 months ago (2015-06-12 23:48:18 UTC) #3
qining
Reply test https://codereview.chromium.org/1185703004/diff/20001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/1185703004/diff/20001/src/IceTargetLoweringX8632.cpp#newcode450 src/IceTargetLoweringX8632.cpp:450: RandomizationPoolingPaused = false; On 2015/06/12 23:48:17, stichnot ...
5 years, 6 months ago (2015-06-13 00:41:26 UTC) #4
qining
Reply test
5 years, 6 months ago (2015-06-13 00:41:28 UTC) #5
qining
https://codereview.chromium.org/1185703004/diff/20001/src/IceClFlags.cpp File src/IceClFlags.cpp (right): https://codereview.chromium.org/1185703004/diff/20001/src/IceClFlags.cpp#newcode261 src/IceClFlags.cpp:261: clEnumValN(Ice::RandomizeImmediates, "constant-blinding", On 2015/06/12 23:48:16, stichnot wrote: > I ...
5 years, 6 months ago (2015-06-17 04:28:55 UTC) #6
JF
Should the randomization immediate be per-program (as it is now) or at a smaller granularity ...
5 years, 6 months ago (2015-06-17 11:29:18 UTC) #8
qining
Thanks a lot for your comments, JF. The purpose of constant blinding and pooling is ...
5 years, 6 months ago (2015-06-17 18:20:37 UTC) #9
JF
On Wed, Jun 17, 2015 at 8:20 PM, <qining@google.com> wrote: > Thanks a lot for ...
5 years, 6 months ago (2015-06-18 13:35:07 UTC) #10
qining
Prevent memory operands being randomized twice by adding a bool flag to OperandX8632Mem. https://codereview.chromium.org/1185703004/diff/140001/src/IceInstX8632.cpp File ...
5 years, 6 months ago (2015-06-19 16:23:21 UTC) #11
Jim Stichnoth
https://codereview.chromium.org/1185703004/diff/80001/src/IceClFlags.cpp File src/IceClFlags.cpp (right): https://codereview.chromium.org/1185703004/diff/80001/src/IceClFlags.cpp#newcode110 src/IceClFlags.cpp:110: cl::init(1)); On 2015/06/17 04:28:54, qining wrote: > Initialize the ...
5 years, 6 months ago (2015-06-19 16:51:03 UTC) #12
Jim Stichnoth
https://codereview.chromium.org/1185703004/diff/140001/src/IceInstX8632.h File src/IceInstX8632.h (right): https://codereview.chromium.org/1185703004/diff/140001/src/IceInstX8632.h#newcode92 src/IceInstX8632.h:92: bool Randomized; Make this private, with getter/setter methods. https://codereview.chromium.org/1185703004/diff/140001/tests_lit/llvm2ice_tests/randomize-pool-immediate-basic.ll ...
5 years, 6 months ago (2015-06-19 16:57:23 UTC) #13
qining
Updated in patch set 9. https://codereview.chromium.org/1185703004/diff/120001/src/IceClFlags.cpp File src/IceClFlags.cpp (right): https://codereview.chromium.org/1185703004/diff/120001/src/IceClFlags.cpp#newcode260 src/IceClFlags.cpp:260: // cl::init(Ice::RPI_Randomize), On 2015/06/19 ...
5 years, 6 months ago (2015-06-19 20:22:26 UTC) #14
Jim Stichnoth
https://codereview.chromium.org/1185703004/diff/120001/src/IceOperand.cpp File src/IceOperand.cpp (right): https://codereview.chromium.org/1185703004/diff/120001/src/IceOperand.cpp#newcode497 src/IceOperand.cpp:497: static const uint32_t X86_INT_IMMEDIATE_RANDOMIZATION_THRESHOLD = 0x1; On 2015/06/19 20:22:25, ...
5 years, 6 months ago (2015-06-19 23:12:15 UTC) #15
qining
Add command line option for randomization/pooling threshold in patch set 11. Thanks, https://codereview.chromium.org/1185703004/diff/120001/src/IceOperand.cpp File src/IceOperand.cpp ...
5 years, 6 months ago (2015-06-20 00:22:29 UTC) #16
Jim Stichnoth
https://codereview.chromium.org/1185703004/diff/220001/src/IceGlobalContext.cpp File src/IceGlobalContext.cpp (right): https://codereview.chromium.org/1185703004/diff/220001/src/IceGlobalContext.cpp#newcode270 src/IceGlobalContext.cpp:270: // Initialize the randomization cookie for diversification. Maybe say ...
5 years, 6 months ago (2015-06-20 17:42:16 UTC) #17
Jim Stichnoth
I just noticed that "make -f Makefile.standalone check-lit" is failing on the 3 randomization tests. ...
5 years, 6 months ago (2015-06-20 17:52:21 UTC) #18
qining
Fixed the three randomization tests. The problem was caused by the initialization of RandomizationCookie in ...
5 years, 6 months ago (2015-06-20 23:32:37 UTC) #19
Jim Stichnoth
I took a really brief look at the generated code, and the spec2k performance with ...
5 years, 6 months ago (2015-06-21 00:05:27 UTC) #20
qining
Yes, you are right. This blinding/pooling only applies to constants that appear in pexe and ...
5 years, 6 months ago (2015-06-21 00:30:48 UTC) #21
Jim Stichnoth
To modify the description, click the "Edit Issue" link in the upper left, then modify ...
5 years, 6 months ago (2015-06-21 00:40:10 UTC) #22
Jim Stichnoth
On 2015/06/21 00:30:48, qining wrote: > I think I should also measure the overhead of ...
5 years, 6 months ago (2015-06-21 00:47:22 UTC) #23
qining
Updated the description of this issue. And changed back the default value of sz-seed to ...
5 years, 6 months ago (2015-06-21 01:30:52 UTC) #24
Jim Stichnoth
lgtm
5 years, 6 months ago (2015-06-21 07:18:38 UTC) #25
qining
5 years, 6 months ago (2015-06-22 17:10:28 UTC) #26
Message was sent while issue was closed.
Committed patchset #14 (id:260001) manually as
253dc8a870cbd144ba217a44efbd07e6bcd71e97 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698