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

Issue 1139673004: Harden writer of munged bitcode for fuzzing (Closed)

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

Description

Harden writer of munged bitcode for fuzzing Hardens the writer of munged bitcode. Does this by adding error recovery that guarantees the bitstream writer will not fail on assertions. Also cleans up error recovery in general and adds tests to show what errors are reported by the writer, as well as what error recovery is applied. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4169 R=jvoung@chromium.org Committed: https://chromium.googlesource.com/native_client/pnacl-llvm/+/e5c16c87eb22c2529bec44cf2e77529450956011

Patch Set 1 #

Patch Set 2 : Fix nits. #

Total comments: 30

Patch Set 3 : Fix issues in last patch. #

Patch Set 4 : Added more tests. #

Total comments: 17

Patch Set 5 : Fix issues in last patch. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+741 lines, -250 lines) Patch
M include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h View 1 2 3 4 6 chunks +59 lines, -6 lines 0 comments Download
M include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h View 1 chunk +6 lines, -0 lines 0 comments Download
M lib/Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp View 1 6 chunks +33 lines, -14 lines 0 comments Download
M lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeUtils.cpp View 2 chunks +8 lines, -1 line 0 comments Download
M lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp View 1 2 3 4 9 chunks +212 lines, -79 lines 0 comments Download
M unittests/Bitcode/CMakeLists.txt View 1 chunk +1 line, -1 line 0 comments Download
D unittests/Bitcode/NaClAbbrevErrorTests.cpp View 1 chunk +0 lines, -144 lines 0 comments Download
A unittests/Bitcode/NaClMungeWriteErrorTests.cpp View 1 2 3 4 1 chunk +404 lines, -0 lines 0 comments Download
M unittests/Bitcode/NaClMungedIoTest.cpp View 2 chunks +18 lines, -5 lines 0 comments Download

Messages

Total messages: 11 (3 generated)
Karl
5 years, 7 months ago (2015-05-11 22:59:59 UTC) #2
dsansome
I think you added the wrong reviewer, I've never seen this code before :)
5 years, 7 months ago (2015-05-12 01:23:45 UTC) #4
Karl
5 years, 7 months ago (2015-05-12 05:02:52 UTC) #6
jvoung (off chromium)
re: "BUG= https://code.google.com/p/nativeclient/issues/detail?id=4164" Seems like this is more for bitcode fuzzing than for "Extend PNaCl ...
5 years, 7 months ago (2015-05-13 00:58:17 UTC) #7
Karl
I fixed the description and corresponding bug to reflect that this is for fuzzing. https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp ...
5 years, 7 months ago (2015-05-13 21:39:25 UTC) #8
jvoung (off chromium)
Otherwise LGTM https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp File lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp (right): https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp#newcode259 lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp:259: exitBlock(Writer); btw: I was about to suggest ...
5 years, 7 months ago (2015-05-13 22:24:06 UTC) #9
Karl
Committed patchset #5 (id:80001) manually as e5c16c87eb22c2529bec44cf2e77529450956011 (presubmit successful).
5 years, 7 months ago (2015-05-14 17:07:43 UTC) #10
Karl
5 years, 7 months ago (2015-05-14 17:08:12 UTC) #11
Message was sent while issue was closed.
https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUt...
File lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp (right):

https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUt...
lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp:259: exitBlock(Writer);
On 2015/05/13 22:24:05, jvoung wrote:
> btw: I was about to suggest adding LLVM_ATTRIBUTE_UNUSED_RESULT to the new
> methods with bool results, to get a warning if the return value is mistakenly
> ignored to help catch some of these + the previous case where you had
> enterBlock() without the return and just a fallthrough.
> 
> Not sure number of false positives vs the benefit, though, so up to you.

Added and fixed code (3 cases). In all three, they shouldn't happen, but forced
a non-recoverable error should they fail for some reason. This makes the code
safer, in case code gets modified and the conditions are no longer assured.

https://codereview.chromium.org/1139673004/diff/20001/lib/Bitcode/NaCl/TestUt...
lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp:270: &&
Writer.getMaxCurAbbrevIndex() >=  getCurAbbrevIndexLimit()) {
On 2015/05/13 22:24:06, jvoung wrote:
> On 2015/05/13 21:39:23, Karl wrote:
> > On 2015/05/13 00:58:17, jvoung wrote:
> > > ">=  "
> > > ">= " 
> > 
> > Done.
> 
> Ping =) >=

Done.

https://codereview.chromium.org/1139673004/diff/60001/lib/Bitcode/NaCl/TestUt...
File lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp (right):

https://codereview.chromium.org/1139673004/diff/60001/lib/Bitcode/NaCl/TestUt...
lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp:57: // The miniumum number
of bits allowed to be specified in a block.
On 2015/05/13 22:24:06, jvoung wrote:
> miniumum -> minimum

Done.

https://codereview.chromium.org/1139673004/diff/60001/lib/Bitcode/NaCl/TestUt...
lib/Bitcode/NaCl/TestUtils/NaClBitcodeMungeWriter.cpp:110: if
(ScopeStack.empty())
On 2015/05/13 22:24:06, jvoung wrote:
> how about
> 
> if (atOutermostScope())
>   return false;
> 
> Then it matches the comment, and also leaves the sentinel node there.
Otherwise
> if you pop that, the assert(!ScopeStack.empty()) that you have in a bunch of
> places can fail.
> 
> 

Done.

https://codereview.chromium.org/1139673004/diff/60001/unittests/Bitcode/NaClM...
File unittests/Bitcode/NaClMungeWriteErrorTests.cpp (right):

https://codereview.chromium.org/1139673004/diff/60001/unittests/Bitcode/NaClM...
unittests/Bitcode/NaClMungeWriteErrorTests.cpp:149:
EXPECT_FALSE(Munger.runTest("TooManyEnterBlocks"));
On 2015/05/13 22:24:06, jvoung wrote:
> CantWriteTooManyEnterBlocks -- I wasn't too sure these strings were too
helpful?
> gtest should tell you which test is running based on the X and Y in "TEST(X,
Y)
> { ... }", and the EXPECT_* should tell you which line failed if there are
> multiple EXPECT_*? Anyway, not asking for any action, just saying you might be
> able to save some work syncing stuff.

I agree that these names are no longer useful. Changing API to allow this
parameter to be skipped, and then remove them from runTest. Will fix other test
files in a separate CL.

https://codereview.chromium.org/1139673004/diff/60001/unittests/Bitcode/NaClM...
unittests/Bitcode/NaClMungeWriteErrorTests.cpp:196:
TEST(NaClMungerWriteErrorTests, CantWriteBlockWithMaxLimit) {
On 2015/05/13 22:24:06, jvoung wrote:
> Seems like Cant should be Can, since this doesn't print any errors and it
> returns true.

Good point. Fixing name.

https://codereview.chromium.org/1139673004/diff/60001/unittests/Bitcode/NaClM...
unittests/Bitcode/NaClMungeWriteErrorTests.cpp:251: "Error (Block unknown):
Block id must be less than << 4294967295: 1:"
On 2015/05/13 22:24:06, jvoung wrote:
> "less than << 4294967295" -- why the "<<" ?

Done.

https://codereview.chromium.org/1139673004/diff/60001/unittests/Bitcode/NaClM...
unittests/Bitcode/NaClMungeWriteErrorTests.cpp:257: // Show that parsing
successfully recovers (i.e. not crash) if the
On 2015/05/13 22:24:06, jvoung wrote:
> "parsing successfully recovers" ? I thought it was writing that recovers, and
> not in a way that parsing can succeed? There is EXPECT_DEATH, so it does
crash.

Good point. Rewrote to better fit test.

Powered by Google App Engine
This is Rietveld 408576698