rust-osdev / x86_64

Library to program x86_64 hardware.
https://docs.rs/x86_64
Apache License 2.0
797 stars 132 forks source link

Call to VirtAddr::new() causes panic when CR2 does not contain a canonical address. #332

Closed RevolutionXenon closed 2 years ago

RevolutionXenon commented 2 years ago

https://docs.rs/x86_64/latest/src/x86_64/registers/control.rs.html#267

When CR2 contains a malformed address, this panic occurs: "panicked at 'address passed to VirtAddr::new must not contain any data in bits 48 to 64"

CR2 can obviously contain a non-canonical address after a page fault. This panic should not occur. I'm not sure what the best fix would be, but I ran into this because I tried to print CR2 in my panic handler and it just starts looping when you do that.

Freax13 commented 2 years ago

Good catch we should definitely not panic in that situation. We could change Cr2::read to return Result<VirtAddr, VirtAddrNotValid> and add a new method Cr2::read_raw that returns u64.

Changing Cr2::read would be a breaking change, but adding Cr2::read_raw could be done right now.

josephlr commented 2 years ago

Should this stay open to track the (breaking) change to Cr2::read?

josephlr commented 2 years ago

Whoops I just saw #335 I guess that PR (when merged) should close this issue.

toku-sa-n commented 2 years ago

I think this issue can be closed.