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

Issue 1269113003: Rewrite non-temporal instructions

Created:
5 years, 4 months ago by ruiq
Modified:
5 years, 4 months ago
CC:
native-client-reviews_googlegroups.com, qiaoruiwhu_gmail.com
Base URL:
https://chromium.googlesource.com/native_client/src/native_client.git@master
Target Ref:
refs/heads/master
Project:
nacl
Visibility:
Public.

Description

Rewrite non-temporal instructions For security hardening reasons, non-temporal instructions should not present in validated NaCl applications. They are either forbidden during validation, as in https://codereview.chromium.org/1234393005/, or rewritten, as in this CL. This CL rewrites non-temporal instructions identified in the nexes in Web Store. The result of the instruction scan https://docs.google.com/a/google.com/document/d/1AsQavtUqv3iUAVK5mKNV-B5NHKdHXTCGmZu94mIO_jk/edit?usp=sharing Some related discussions can be seen in this experimental CL: https://codereview.chromium.org/1276543006/ BUG=https://code.google.com/p/chromium/issues/detail?id=500026 TEST=trybots

Patch Set 1 #

Patch Set 2 : Rebase #

Patch Set 3 : Revalidate after rewriting #

Patch Set 4 : No change #

Patch Set 5 : Don't bother inline #

Patch Set 6 : Fixed validation flags passing; fixed comments. #

Patch Set 7 : Trivial fix #

Patch Set 8 : Trivial: fix comments #

Total comments: 8

Patch Set 9 : Restructured tests #

Patch Set 10 : Hack to support Mac compilation #

Patch Set 11 : Try fix #

Patch Set 12 : Linkage #

Patch Set 13 : Use macro #

Patch Set 14 : Use #if SUBARCH #

Total comments: 4

Patch Set 15 : Refine #

Patch Set 16 : Endianness #

Patch Set 17 : Simplify code #

Total comments: 10

Patch Set 18 : Merge experimental CL #

Patch Set 19 : Comments; clean up #

Patch Set 20 : Trivial #

Patch Set 21 : Trivial #

Total comments: 15

Patch Set 22 : Format #

Patch Set 23 : Adding more tests #

Patch Set 24 : Rebase #

Patch Set 25 : Turning off tests relying on tool chain #

Total comments: 34

Patch Set 26 : Address code review comments #

Patch Set 27 : Extra test for non-webstore movnt instruction #

Patch Set 28 : Using macro to simplify global symbol definition #

Patch Set 29 : Format #

Unified diffs Side-by-side diffs Delta from patch set Stats (+779 lines, -51 lines) Patch
M src/trusted/validator/build.scons View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1 chunk +26 lines, -0 lines 0 comments Download
M src/trusted/validator/validation_disable_nontemporals_test.cc View 1 2 chunks +18 lines, -7 lines 0 comments Download
A + src/trusted/validator/validation_rewrite_32_test.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 4 chunks +43 lines, -18 lines 0 comments Download
A src/trusted/validator/validation_rewrite_32_test_data.S View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +35 lines, -0 lines 0 comments Download
A src/trusted/validator/validation_rewrite_64_test.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 1 chunk +249 lines, -0 lines 0 comments Download
A src/trusted/validator/validation_rewrite_64_test_data.S View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +171 lines, -0 lines 0 comments Download
M src/trusted/validator_ragel/dfa_validate_32.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 chunks +13 lines, -4 lines 0 comments Download
M src/trusted/validator_ragel/dfa_validate_64.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 chunks +12 lines, -4 lines 0 comments Download
M src/trusted/validator_ragel/dfa_validate_common.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 chunks +6 lines, -0 lines 0 comments Download
M src/trusted/validator_ragel/dfa_validate_common.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 chunks +206 lines, -18 lines 0 comments Download

Messages

Total messages: 22 (3 generated)
ruiq
5 years, 4 months ago (2015-08-03 23:16:36 UTC) #2
bradn
https://codereview.chromium.org/1269113003/diff/60002/src/trusted/validator/build.scons File src/trusted/validator/build.scons (right): https://codereview.chromium.org/1269113003/diff/60002/src/trusted/validator/build.scons#newcode70 src/trusted/validator/build.scons:70: EXTRA_LIBS=['validators', 'nrd_xfer']) might be overkill to test cross arch, ...
5 years, 4 months ago (2015-08-04 22:03:30 UTC) #3
ruiq
https://codereview.chromium.org/1269113003/diff/60002/src/trusted/validator/validation_rewrite_32_test.cc File src/trusted/validator/validation_rewrite_32_test.cc (right): https://codereview.chromium.org/1269113003/diff/60002/src/trusted/validator/validation_rewrite_32_test.cc#newcode52 src/trusted/validator/validation_rewrite_32_test.cc:52: const char *code = "\x0f\xe7\x03"; On 2015/08/04 22:03:30, bradn ...
5 years, 4 months ago (2015-08-05 20:11:03 UTC) #4
bradn
lgtm
5 years, 4 months ago (2015-08-05 21:45:53 UTC) #5
bradnelson
lgtm
5 years, 4 months ago (2015-08-05 21:46:04 UTC) #6
Petr Hosek
Is it really necessary to rerun the validation? That doubles the validation time! We should ...
5 years, 4 months ago (2015-08-05 21:51:32 UTC) #7
Petr Hosek
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_ragel/dfa_validate_common.c#newcode64 src/trusted/validator_ragel/dfa_validate_common.c:64: if (memcmp(begin + 1, "\x0f\x2b", 2) == 0) { ...
5 years, 4 months ago (2015-08-05 21:59:56 UTC) #8
ruiq
On 2015/08/05 21:51:32, Petr Hosek wrote: > Is it really necessary to rerun the validation? ...
5 years, 4 months ago (2015-08-06 00:07:12 UTC) #9
ruiq
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_ragel/dfa_validate_common.c#newcode64 src/trusted/validator_ragel/dfa_validate_common.c:64: if (memcmp(begin + 1, "\x0f\x2b", 2) == 0) { ...
5 years, 4 months ago (2015-08-06 04:53:18 UTC) #10
khimg
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_ragel/dfa_validate_common.c#newcode54 src/trusted/validator_ragel/dfa_validate_common.c:54: /* movntq => movq */ Why movntq is not ...
5 years, 4 months ago (2015-08-08 00:33:11 UTC) #12
ruiq
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_ragel/dfa_validate_common.c#newcode54 src/trusted/validator_ragel/dfa_validate_common.c:54: /* movntq => movq */ On 2015/08/08 00:33:11, khimg ...
5 years, 4 months ago (2015-08-10 00:57:15 UTC) #13
Petr Hosek
https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c#newcode43 src/trusted/validator_ragel/dfa_validate_common.c:43: /* Similar to NaClDfaRewriteUnsupportedInstruction(), we don't consider Nit: the ...
5 years, 4 months ago (2015-08-11 18:22:36 UTC) #14
ruiq
https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c#newcode43 src/trusted/validator_ragel/dfa_validate_common.c:43: /* Similar to NaClDfaRewriteUnsupportedInstruction(), we don't consider On 2015/08/11 ...
5 years, 4 months ago (2015-08-11 21:08:34 UTC) #15
ruiq
https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c File src/trusted/validator_ragel/dfa_validate_common.c (right): https://codereview.chromium.org/1269113003/diff/380001/src/trusted/validator_ragel/dfa_validate_common.c#newcode153 src/trusted/validator_ragel/dfa_validate_common.c:153: memcmp(begin + 2, "\x0f\xe7", 2) == 0) { On ...
5 years, 4 months ago (2015-08-12 05:37:50 UTC) #16
Mark Seaborn
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator/build.scons File src/trusted/validator/build.scons (right): https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator/build.scons#newcode67 src/trusted/validator/build.scons:67: validation_rewrite_test_exe= gtest_env.ComponentProgram( Nit: there should be spaces before and ...
5 years, 4 months ago (2015-08-14 21:12:59 UTC) #17
ruiq
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator/build.scons File src/trusted/validator/build.scons (right): https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator/build.scons#newcode67 src/trusted/validator/build.scons:67: validation_rewrite_test_exe= gtest_env.ComponentProgram( On 2015/08/14 21:12:59, Mark Seaborn wrote: > ...
5 years, 4 months ago (2015-08-15 04:46:41 UTC) #18
Mark Seaborn
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_ragel/dfa_validate_64.c File src/trusted/validator_ragel/dfa_validate_64.c (right): https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_ragel/dfa_validate_64.c#newcode75 src/trusted/validator_ragel/dfa_validate_64.c:75: callback_data.bundle_begin_offset = (uintptr_t) data & kBundleMask; On 2015/08/14 21:12:59, ...
5 years, 4 months ago (2015-08-21 21:13:32 UTC) #19
QiaoRuiwhu
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_ragel/dfa_validate_64.c File src/trusted/validator_ragel/dfa_validate_64.c (right): https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_ragel/dfa_validate_64.c#newcode75 src/trusted/validator_ragel/dfa_validate_64.c:75: callback_data.bundle_begin_offset = (uintptr_t) data & kBundleMask; On 2015/08/21 21:13:32, ...
5 years, 4 months ago (2015-08-24 19:48:15 UTC) #21
Mark Seaborn
5 years, 4 months ago (2015-08-25 19:01:05 UTC) #22
On 24 August 2015 at 12:48, <QiaoRuiwhu@gmail.com> wrote:

>
>
>
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_...
> File src/trusted/validator_ragel/dfa_validate_64.c (right):
>
>
>
https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_...
> src/trusted/validator_ragel/dfa_validate_64.c:75:
> callback_data.bundle_begin_offset = (uintptr_t) data & kBundleMask;
> On 2015/08/21 21:13:32, Mark Seaborn wrote:
>
>> On 2015/08/14 21:12:59, Mark Seaborn wrote:
>> > I'm not sure I understand this parameter.  You're taking a trusted
>> address and
>
> > ANDing it with kBundleMask?  That seems like a very hacky thing to do.
>
>
> This will need to get addressed...
>>
>
> I will take over this change and do some further cleanups in order to get
>> it
>
> committed.
>>
>
> This is because the 'data' argument, which is the pointer to
> code_to_verify, is not necessarily kBundleSize aligned. At least some
> callers of ApplyDfaValidator_x86_64() function do not pass in an aligned
> pointer. Note that ValidateChunkAMD64() does not enforce 'data' argument
> to be kBundleSize aligned either, although it validates bundle by
> bundle, starting from 'data'.
>
> I suspect the decision of not enforcing 'data' to be kBundleSize aligned
> was made on purpose. This is useful, for example, when user supplies
> some code buffer (not aligned) which is used only for validation, and
> later the code can be copied to code region (aligned) for execution.
>
> If this is not true, we could potentially change all callers to align
> 'data' argument before passing in.
>
> An alternative of computing the offset inside a bundle (current
> approach) is to pass the offset in as an additional argument. However,
> this requires function interface change.
>
> Hopefuly above explanation clarifies a little bit.


Right, I understand the reason is to figure out where the bundle starts.

Here's a cleaner way to do it:
https://codereview.chromium.org/1309953002/diff2/1:20001/src/trusted/validato...
-- Pass in a pointer to the start of the code chunk being validated
(data->chunk_begin), and calculate:
bundle_begin = data->chunk_begin + ((begin - data->chunk_begin) &
~kBundleMask);

Cheers,
Mark

-- 
You received this message because you are subscribed to the Google Groups
"Native-Client-Reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to native-client-reviews+unsubscribe@googlegroups.com.
To post to this group, send email to native-client-reviews@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-reviews.
For more options, visit https://groups.google.com/d/optout.

Powered by Google App Engine
This is Rietveld 408576698