-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
heap-buffer-overflow: from integer overflow at mp_stream_rw #13046
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
Comments
Thanks for submitting this report. I am able to reproduce this, and confirm the bug exists as described. Triggering the bug depends on the user running a malformed block device driver, as provided with your PoC. A fix should be available in MicroPython soon. Please let us know if you plan to register a CVE for this or any other issue you've reported. (I'd suggest in this case it's not applicable, as any exploit depends on a malformed block device driver and no such driver exists in Micropython.) |
This only happens if the underlying filesystem implementation is malformed, but results in unsigned integer overflow and out of bounds read otherwise. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
This only happens if the underlying stream implementation is malformed, but results in unsigned integer overflow and out of bounds read otherwise. Second fix for micropython#13046 - allows for possibility an invalid result comes back from a different stream implementation. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Thank you for confirming this issue! I sent you a DM in discord about CVEs. |
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
This only happens if the underlying stream implementation is malformed, but results in unsigned integer overflow and out of bounds read otherwise. Second fix for micropython#13046 - allows for possibility an invalid result comes back from a different stream implementation. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
A positive result here can result in eventual memory corruption as littlefs expects the result of a cache read/write function to be 0 or a negative integer for an error. Closes micropython#13046 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Hi all, Sorry for burdening you with a lot of bug reports. we found buffer overflow at mp_stream_rw.
Summary
py/stream.c:121
, it checks the unsigned integer size with > 0, thus it lead to integer overflow, and then heap buffer overflowPoC
Problem Statement
vstr->buf
is allocated atpy/stream.c:122
, withsz
1-length.The chunk
vstr->buf
is flown tomp_stream_rw
atpy/stream.c:46
, as a parameterbuf_
, andsize
is 1 here. At the first while looppy/stream.c:60
, it callsio_func
, which islfs1_cache_read
, and theout_sz
is 10.Problem occurs here, because the
size
is 1 andout_sz
is 10, both are mp_uint_t, thussize -= out_sz
makes integer overflow. ⇒ it’s 18446744073709551607 in unix port.and then, because size is still over 0 (because of integer overflow), it calls io_func again, with the address of
buf_ + 10
and size18446744073709551607
then, lfs1_cache_read do memcpy with the
diff
, on the invalid offsetbuf_ + 10
. thus, it is heap-over-flow.Patch
we need to compare out_sz and size, instead of using while (size > 0) on unsigned integer.
Crash log
Thank you for taking the time to review our bug report! :)
The text was updated successfully, but these errors were encountered: