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

Page Allocator bugs #27

Open
Knight-Ops opened this issue Dec 16, 2020 · 1 comment
Open

Page Allocator bugs #27

Knight-Ops opened this issue Dec 16, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Knight-Ops
Copy link

Knight-Ops commented Dec 16, 2020

Chapter 3 onward there is a bug in the Page Allocator that rears it's ugly head when you try to allocate more pages than are possible. Since for i in 0..num_pages - pages is not using checked_sub You can underflow num_pages and end up iterating way past the end of allocable memory, this will likely result in heap corruption for any allocation greater than the number of pages remaining in the heap. This is particularly troublesome because it is in an unsafe block.

Additionally, for i in 0..num_pages - pages should be for i in 0..=num_pages - pages so we can use the last page. While a minor grievance, I actually implemented this on a microcontroller that only had a single page of heap memory, which you couldn't allocate because the range doesn't include the last page in the heap... needless to say, this was detrimental to the usefulness of the allocator.

https://github.com/sgmarz/osblog/blob/master/risc_v/chapters/ch3/src/page.rs#L137

@sgmarz
Copy link
Owner

sgmarz commented Feb 19, 2021

I will have to look into this. Thank you.

@sgmarz sgmarz added the bug Something isn't working label Feb 19, 2021
@sgmarz sgmarz self-assigned this Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants