ufrisk / LeechCore

LeechCore - Physical Memory Acquisition Library & The LeechAgent Remote Memory Acquisition Agent
GNU General Public License v3.0
517 stars 92 forks source link

LcRead fails on unaligned / small reads #18

Closed ko1N closed 3 years ago

ko1N commented 3 years ago

I'm experiencing multiple issues when using the LcRead function on Linux.

In the following example I'm just reading from the physical address 0x1000. When reading 8 or 16 bytes I'm usually getting the following crash: realloc(): invalid old size

When reading 16-100 bytes I usually get something like: free(): invalid next size (fast) or corrupted size vs. prev_size while consolidating.

I see slight variations on the above calls which always lead to SIGSEGV or SIGABRT.

When reading more than 128 bytes it appears to work. The buffer is allocated using the Rust default allocator (so calling realloc or free on the buffer will fail).

Additionally when trying to do an un-aligned read (e.g. from address 0x1008) the result buffer just contains 0. LcRead returns with 0 in this case.

I tried the same addresses / lengths with the LcWrite function and that appears to work fine (even un-aligned and with a 8 byte buffer).

ufrisk commented 3 years ago

Thank you for this excellent bug report. I'll look into it and fix it ASAP.

ufrisk commented 3 years ago

Thank you for reporting this issue. There were indeed multiple issues around this with typical c-issues such as writing data outside the buffer corrupting the heap when using the LcRead API call. I believe it should now be completely fixed. If you should still happen to have issues please let me know and we'll reopen this issue.