Repository navigation
Fix replay tool output buffer sizing and usage instructions - #8
Open
dajiaohuang wants to merge 1 commit into
Open
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
replay.cpp allocated a fixed 0x2000 byte output buffer, but each payload record's outbuffer_length is passed unmodified to DeviceIoControl as nOutBufferSize. The target harness (kafl.targets windows_x86_64) uses a 0x10000 byte output buffer, so replaying a record produced for an IOCTL that returns more than 8 KiB makes the kernel write past the replay buffer. Size the output buffer from the record's outbuffer_length instead, growing it only when a larger record is replayed, and zero the allocated region before each IOCTL. The documented build/run steps could not work either: replay.cpp uses CreateFileW/DeviceIoControl, i.e. it is a Windows binary, yet the guide compiled it with a placeholder command and ran ./replay on the Linux host, and referenced an undefined $kAFL variable. Build it with the MinGW-w64 C++ cross-compiler and run it inside the Windows guest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trigger
make deploy -- --tags examples,examples-template-windowsbuilds the Windows targetharness (
kafl.targets/windows_x86_64/src/driver/vuln_test.c) with an output buffer of0x10000bytes (malloc(0x10000)), and every payload record stores the output length usedby the harness. Replaying such a record with the utility documented in section 7 of
docs/installation/README.md, whereoutbuffer_lengthis larger than 8 KiB.Actual
replay.cppallocates a fixedBUF_SIZE(0x2000) output buffer but passes the record'soutbuffer_lengthunmodified toDeviceIoControlasnOutBufferSize:so the kernel writes up to
outbuffer_lengthbytes into an 8 KiB allocation. Replaying a16 KiB record makes the tool die with an access violation (
0xC0000005).Section 7 of the same guide also cannot be followed as written:
replay.cppusesCreateFileW/DeviceIoControl, i.e. it is a Windows binary, but the instructions use aplaceholder
[you compiler]command and then./replayon the Linux host, and reference anundefined
$kAFLvariable (the deployedenv.shonly exportsKAFL_ROOT).Expected
Replay any payload produced by the harness (output buffers up to
0x10000) without memorycorruption, and documented build/run steps that work on the supported Ubuntu host plus the
Windows guest.
Change
outbuffer_length, growing it only when a largerrecord is replayed, and zero the allocated region before each IOCTL.
inside the Windows guest; use
~/kAFL(the clone location from section 2) instead of theundefined
$kAFL.Validation
/W4 /std:c++17build of the changedreplay.cpp: clean.DeviceIoControlthat follows the documented contract (kernel may write up to
nOutBufferSizebytes),plus synthetic multi-record payload files:
0xC0000005; 4 KiB -> 32 KiB records ->0xC00000050x10000, the harness maximum) and mixed-size records all OKhardware, the patched kAFL kernel and a Windows guest), and the MinGW cross-build itself
(the file was compiled with MSVC here; no MinGW toolchain available in this environment).