-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
extmod: Check vfs block device invalid return values, increase error handling #13572
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
extmod: Check vfs block device invalid return values, increase error handling #13572
Conversation
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #13572 +/- ##
==========================================
- Coverage 98.57% 98.57% -0.01%
==========================================
Files 164 164
Lines 21341 21330 -11
==========================================
- Hits 21036 21025 -11
Misses 305 305 ☔ View full report in Codecov by Sentry. |
This comment was marked as resolved.
This comment was marked as resolved.
1a178bc
to
d278b46
Compare
d278b46
to
4bc7276
Compare
7f74230
to
7eb2fbb
Compare
This is awesome! We get a bug fix, better error handling, remove a TODO, de-duplicated code, and code size reduction! |
7eb2fbb
to
a6cae89
Compare
a6cae89
to
c893f2e
Compare
Rebased, fixed inconsistent commit message prefixes. 😁 |
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>
- Code size saving as all of these functions are very similar. - Resolves the "TODO" of the plain read and write functions not propagating errors. An error in the underlying block device now causes VFatFs to return EIO, for example. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
c893f2e
to
f4ab9d9
Compare
Thanks, now merged. |
Summary
Two fixes, currently in two commits as the second one is more complex than the first:
mp_vfs_blockdev_read_ext/mp_vfs_blockdev_write_ext
to be 0 or a negative integer. Returning positive integers here confuses littlefs (see lfs1.c:66 for example). Adds a unit test for an invalid block device of this kind. Closes heap-buffer-overflow: from integer overflow at mp_stream_rw #13046.EDIT: There was previously a semi-related fix for the "stream" part of the linked issue in this PR, but it was impossible to test and only necessary if the underlying stream (in C) violated its API contract. The block device fix in this PR already prevents this from happening in the one known case.
Trade-offs and Alternatives
There is a risk that an old implementation of BlockDev readblocks/writeblocks somewhere returns a non-zero integer or other value on success and will now fail as the result is checked. I think this is unlikely though, as the same function is called for the
_ext
variants and those results have always been checked.Testing
Ran the
vfs
tests on both unix port and rp2 port.This work was funded through GitHub Sponsors.