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

Potential access violation / buffer overflow condition #1626

Closed
legendtang opened this issue Aug 10, 2017 · 0 comments
Closed

Potential access violation / buffer overflow condition #1626

legendtang opened this issue Aug 10, 2017 · 0 comments
Labels

Comments

@legendtang
Copy link

legendtang commented Aug 10, 2017

What version of shadowsocks-libev are you using?

v3.0.8

What operating system are you using?

Arch Linux

What did you do?

Nothing but inspecting.

What did you expect to see?

Everything works like a charm.

What did you see instead?

It seems that at

long pos = ftell(f);
it uses ftell to get file pointer position, and in this condition
buf = ss_malloc(pos + 1);
malloc(0), but buf is directly used at
int nread = fread(buf, pos, 1, f);
as a buffer. The return address of malloc(0) is generally a valid address but not NULL. To the best of my knowledge, on some virtual file system or processing special file, the fseek/ftell will return negative value.

Moreover, according to our test cases, OS can accept this type of address written but in this condition pos is a size_t so it is max possible integer. So this is already an exploitable buffer overflow. If this condition passed, we will also see a buffer underflow at

buf[pos] = '\0'; // end of string

Ref: https://stackoverflow.com/questions/40853316/under-what-circumstances-will-fseek-ftell-or-fstat-fail-to-get-the-size-of-a-fil

What is your config in detail (with all sensitive info masked)?

@legendtang legendtang changed the title Potential buffer underflow condition Potential access violation / buffer overflow condition Aug 10, 2017
@madeye madeye closed this as completed in f8283fc Aug 12, 2017
@madeye madeye added the bug label Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants