5 years, 4 months ago
(2015-08-05 21:45:53 UTC)
#5
lgtm
bradnelson
lgtm
5 years, 4 months ago
(2015-08-05 21:46:04 UTC)
#6
lgtm
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
Is it really necessary to rerun the validation? That doubles the validation
time! We should be able to just restart the validation from the last
instruction.
5 years, 4 months ago
(2015-08-05 21:59:56 UTC)
#8
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
File src/trusted/validator_ragel/dfa_validate_common.c (right):
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:64: if (memcmp(begin + 1,
"\x0f\x2b", 2) == 0) {
Couldn't you rewrite this using a switch statement rather than using the
complicated nested if statements?
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:103: if
(RewriteUnsupportedInstruction(begin, end)) {
You could merge the nested if statement with the outer one to make the code
simpler, i.e.:
if (!(data->flags & NACL_DISABLE_NONTEMPORALS_X86) &&
RewriteUnsupportedInstruction(begin, end)) {
data->did_rewrite = 1;
return TRUE;
}
return FALSE;
In fact, you could go even further and merge the `return FALSE;` with the
outermost loop and have just a single `return FALSE;` statement.
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
On 2015/08/05 21:51:32, Petr Hosek wrote:
> Is it really necessary to rerun the validation? That doubles the validation
> time! We should be able to just restart the validation from the last
> instruction.
Re-validation doubles the validation time, if the supplied code contains
non-temporal instructions. I expect the majority of webstore nexes would
not contain non-temporals. So the questions are:
1) How much performance gain can we get if we use "smart" re-validation?
Does it really matter if we validate twice occasionally?
2) How effective is that optimization? It probably needs more hooks for
the validation, does the benefit outweigh code simplicity?
Considering this is a security fix, I suppose the optimization could be
implemented in future when collected data suggests necessity?
5 years, 4 months ago
(2015-08-06 04:53:18 UTC)
#10
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
File src/trusted/validator_ragel/dfa_validate_common.c (right):
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:64: if (memcmp(begin + 1,
"\x0f\x2b", 2) == 0) {
On 2015/08/05 21:59:56, Petr Hosek wrote:
> Couldn't you rewrite this using a switch statement rather than using the
> complicated nested if statements?
Done.
https://codereview.chromium.org/1269113003/diff/250001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:103: if
(RewriteUnsupportedInstruction(begin, end)) {
On 2015/08/05 21:59:56, Petr Hosek wrote:
> You could merge the nested if statement with the outer one to make the code
> simpler, i.e.:
>
> if (!(data->flags & NACL_DISABLE_NONTEMPORALS_X86) &&
> RewriteUnsupportedInstruction(begin, end)) {
> data->did_rewrite = 1;
> return TRUE;
> }
> return FALSE;
>
> In fact, you could go even further and merge the `return FALSE;` with the
> outermost loop and have just a single `return FALSE;` statement.
Done.
5 years, 4 months ago
(2015-08-10 00:57:15 UTC)
#13
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
File src/trusted/validator_ragel/dfa_validate_common.c (right):
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:54: /* movntq => movq */
On 2015/08/08 00:33:11, khimg wrote:
> Why movntq is not rewritten in 64bit mode?
As the CL description says, we only rewrite non-temporal instructions that are
found in current nexes of the webstore so that we do not break them. For future
nexes, they will fail validation if they contain (other) non-temporal
instructions.
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:67: /* movntps => movaps */
On 2015/08/08 00:33:11, khimg wrote:
> Why movntps is not rewritten in 32bit mode?
ditto.
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:71: /* movnti => mov */
On 2015/08/08 00:33:11, khimg wrote:
> Why movnti is not rewritten in 32bit moed?
ditto.
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:73: memmove(ptr + 2, ptr + 3,
end - begin - 3);
On 2015/08/08 00:33:11, khimg wrote:
> You can't do that. Use the following approach:
> ptr[2] = 0x89;
> ptr[1] = ptr[0];
> ptr[0] = 0x90;
The nop has to be put at the end because before the non-temporal store
instruction, there can be an instruction that clears the upper 32-bits of a
register. That instruction followed with this non-temporal store will pass the
validation, but not if they are separated.
https://codereview.chromium.org/1269113003/diff/300001/src/trusted/validator_...
src/trusted/validator_ragel/dfa_validate_common.c:77: /* prefetchnta => nop */
On 2015/08/08 00:33:11, khimg wrote:
> Why prefetchnta is not rewritten in 32bit mode?
> You can replace it with a singular nop:
> ptr[2] = 0x1F;
> ptr[3] &= 0xC7;
ditto.
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
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
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
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
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/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.
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
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.
Mark Seaborn
On 24 August 2015 at 12:48, <QiaoRuiwhu@gmail.com> wrote: > > > https://codereview.chromium.org/1269113003/diff/450001/src/trusted/validator_ragel/dfa_validate_64.c > File src/trusted/validator_ragel/dfa_validate_64.c ...
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.
Issue 1269113003: Rewrite non-temporal instructions
Created 5 years, 4 months ago by ruiq
Modified 5 years, 4 months ago
Reviewers: Mark Seaborn, bradn, bradnelson, Petr Hosek, gdeepti, khimg, QiaoRuiwhu
Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Comments: 71