Skip to content

Guard the substring calls in StateMachine parser to avoid bounds issues - #4202

Merged
1 commit merged into
masterfrom
dev/miniksa/fail_tests
Jan 14, 2020
Merged

1 commit merged into
masterfrom
dev/miniksa/fail_tests

Conversation

@miniksa

@miniksa Michael Niksa (miniksa) commented Jan 13, 2020 •

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Perform checking on std::basic_string_view<T>.substr() calls to
prevent running out of bounds and sporadic Privileged Instruction throws
during x86 tests.

PR Checklist

Detailed Description of the Pull Request / Additional comments

It appears that not all std::basic_string_view<T>.substr() calls are
created equally. I rooted around for other versions of the code in our
source tree and found several versions that were less careful about
checking the start position and the size than the one that appears when
building locally on dev machines.

My theory is that one of these older versions is deployed somewhere in
the CI. Instead of clamping down the size parameter appropriately or
throwing correctly when the position is out of bounds, I believe that
it's just creating a substring with a bad range over an
invalid/uninitialized memory region. Then when the test operates on
that, sometimes it turns out to trigger the privileged instruction
NTSTATUS error we are seeing in CI.

Test Procedure

  1. Fixed the thing
  2. Ran the CI and it worked
  3. Reverted everything and turned off all of the CI build except just
    the parser tests (and supporting libraries)
  4. Ran CI and it failed
  5. Put the fix back on top (cherry-pick)
  6. It worked.
  7. Ran it again.
  8. It worked.
  9. Turn all the rest of the CI build back on

@miniksa
Michael Niksa (miniksa) force-pushed the dev/miniksa/fail_tests branch 2 times, most recently from 8548d55 to 4fd3de5 Compare January 13, 2020 23:21
@german-one

Steffen (german-one) commented Jan 13, 2020 •

Copy link
Copy Markdown
Contributor

Michael Niksa (@miniksa) After resolving a conflict, #4105 was merged in. Then I faced the trouble with the x86 tests.
//EDIT Sorry for confusing more than being helpful.

@DHowett-MSFT

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@miniksa

Copy link
Copy Markdown
Contributor Author

Dustin L. Howett (MSFT) (@DHowett-MSFT), seems fine (TM)

@miniksa

Copy link
Copy Markdown
Contributor Author

k, push forced back to just the change on master.

@miniksa
Michael Niksa (miniksa) marked this pull request as ready for review January 14, 2020 00:20
@miniksa Michael Niksa (miniksa) changed the title stab in the dark to fix x86 tests. Guard the substring calls in StateMachine parser to avoid bounds issues Jan 14, 2020
@DHowett-MSFT

Copy link
Copy Markdown
Contributor

@msftbot merge this in 5 minutes

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 14, 2020
@ghost

Copy link
Copy Markdown

Hello Dustin L. Howett (MSFT) (@DHowett-MSFT)!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Tue, 14 Jan 2020 00:45:33 GMT, which is in 5 minutes

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost
ghost merged commit 4129ceb into master Jan 14, 2020
@ghost
ghost deleted the dev/miniksa/fail_tests branch January 14, 2020 00:46
Dustin L. Howett (MSFT) (DHowett-MSFT) pushed a commit that referenced this pull request Jan 24, 2020
## Summary of the Pull Request
Perform checking on `std::basic_string_view<T>.substr()` calls to
prevent running out of bounds and sporadic Privileged Instruction throws
during x86 tests.

## PR Checklist
* [x] Closes the x86 tests failing all over the place since #4125 for no
  apparent reason
* [x] I work here
* [x] Tests pass

## Detailed Description of the Pull Request / Additional comments
It appears that not all `std::basic_string_view<T>.substr()` calls are
created equally. I rooted around for other versions of the code in our
source tree and found several versions that were less careful about
checking the start position and the size than the one that appears when
building locally on dev machines.

My theory is that one of these older versions is deployed somewhere in
the CI. Instead of clamping down the size parameter appropriately or
throwing correctly when the position is out of bounds, I believe that
it's just creating a substring with a bad range over an
invalid/uninitialized memory region. Then when the test operates on
that, sometimes it turns out to trigger the privileged instruction
NTSTATUS error we are seeing in CI.

## Test Procedure
1. Fixed the thing
2. Ran the CI and it worked
3. Reverted everything and turned off all of the CI build except just
   the parser tests (and supporting libraries)
4. Ran CI and it failed
5. Put the fix back on top (cherry-pick)
6. It worked.
7. Ran it again.
8. It worked.
9. Turn all the rest of the CI build back on

(cherry picked from commit 4129ceb)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge Marked for automatic merge by the bot when requirements are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants