Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect out-of-bounds reads #3

Open
Shnatsel opened this issue Sep 10, 2018 · 4 comments
Open

Detect out-of-bounds reads #3

Shnatsel opened this issue Sep 10, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@Shnatsel
Copy link
Owner

It would be nice to be able to detect out-of-bounds reads as well. This is actually pretty easy to implement - just allocate more memory than was requested and clobber it with the same variable value as the rest of the buffer. If any of the clobbered values show up in the output, then the program is definitely exploitable - either via reads from uninitialized memory or via out-of-bounds reads.

Use case: I needed this functionality to determine whether sile/libflate#16 is exploitable or not.

I have already implemented checks for out-of-bounds reads to the right of the buffer in branch detect-oob-reads, but the ones to the left are still TODO - there's just a static canary there that's inherited from libdislocator.

@Shnatsel Shnatsel added enhancement New feature or request help wanted Extra attention is needed labels Sep 10, 2018
@PlasmaPower
Copy link
Contributor

PlasmaPower commented Oct 2, 2018

Doesn't the additional mprotect page already do this?

@PlasmaPower
Copy link
Contributor

I guess that's also missing for calloc.

@Shnatsel
Copy link
Owner Author

Shnatsel commented Oct 2, 2018

Additional mprotect page makes the program crash, which sort of works, but muddles the picture because you can't tell if it was an out-of-bounds write or an information leak.

I find that tools tools complementary to each other work best, and the more approaches you have in your toolbox, the better. The mprotect page is not terribly useful because libdislocator and Address Sanitizer already detect the exact same thing, so I'm trying to do something complementary here.

In my use case I had a program crash under libdislocator (with mprotect page), and wanted to run it through a different tool to determine whether this is an actually exploitable out-of-bounds read. ASAN would also report the error regardless. So I've tweaked libdiffuzz to allocate extra space at the end and clobber it, which is an approach orthogonal to existing tools, and that gave me the answer I was looking for.

Good point about calloc!

@Shnatsel
Copy link
Owner Author

#4 has added an option to detect OOB reads that come after the allocated buffer. It is toggled by an environment variable. OOB reads from before the allocated buffer are not yet detected.

@Shnatsel Shnatsel removed the help wanted Extra attention is needed label Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants