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

Bug in kalign_heap #16

Open
ankarenko opened this issue Oct 9, 2023 · 1 comment
Open

Bug in kalign_heap #16

ankarenko opened this issue Oct 9, 2023 · 1 comment

Comments

@ankarenko
Copy link

Hello, thanks for the project, it very helps me to learn os development

I've found a little but quite severe bug in kalign_heap function

while (!last->next)

I think it should be
while (last->next)

@ankarenko
Copy link
Author

ankarenko commented Oct 19, 2023

mos/src/kernel/memory/vmm.c

Lines 171 to 175 in 8327ee4

char *aligned_object = kalign_heap(PMM_FRAME_SIZE);
// NOTE: MQ 2019-11-24 page directory, page table have to be aligned by 4096
struct pdirectory *va_dir = kcalloc(1, sizeof(struct pdirectory));
if (aligned_object)
kfree(aligned_object);

Also this code might return badly aligned address because kcallloc may choose one of free blocks in a list of kblocklist instead of allocating the new properly aligned one by kalign_heap function

To test it, you can put before the code

void* ptr = kcalloc(PMM_FRAME_SIZE, 1);  // make sure ptr is not properly aligned
kfree(ptr);

... kalign code ...  

// struct pdirectory *va_dir will be equal to ptr which is not properly aligned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant