ethandmd / reedos

rust riscv minimal os
2 stars 6 forks source link

Block byte slice to struct #55

Open ethandmd opened 1 year ago

ethandmd commented 1 year ago

Currently from src/main.rs once hart0 hits process:test_multiprocess_syscall and eventually hits proc.initialize64(), the ensuing palloc_plural fails when alloc_pages attempts to do page.read_free() and finds garbage in the memory of the free page.

The culprit is likely src/fs.rs:29 when we read the superblock into the buffer.

ethandmd commented 1 year ago

Use after free: As suspected, when the allocated pages went out of scope and were dropped, the memory backing the block struct should have been part of the free list, but they were overwritten.

Double free: Alternatively, if you try fancy casting, blah blah, nonsense, things go poorly as well (double free), even with a Vec. So currently I used BlockSlice which a struct representing a file system block-minus can implement for free: impl<T: Copy> BlockSlice<T> for MyStruct {} where we first get the backing data and then copy it into a new Box<T> so that we can safely drop the original buffer.

7e0e4b1ccb638f65aefd041b74c0abf78c8aa53b