Skip to content

Fix panics caused by misaligned pointer dereferences in "Double Faults" & "Introduction to Paging"#1226

Merged
phil-opp merged 2 commits intophil-opp:mainfrom
SPuntte:fix-post-06-ub-panic
Jun 2, 2023
Merged

Fix panics caused by misaligned pointer dereferences in "Double Faults" & "Introduction to Paging"#1226
phil-opp merged 2 commits intophil-opp:mainfrom
SPuntte:fix-post-06-ub-panic

Conversation

@SPuntte
Copy link
Copy Markdown
Contributor

@SPuntte SPuntte commented May 20, 2023

EDIT 2023-05-31:

I just noticed that post 8 is affected by this as well (as already discussed in #1215) and applied the same fix there.


In the "Double Faults" post, the following code is given as an example:

// trigger a page fault
unsafe {
    *(0xdeadbeef as *mut u64) = 42;
};

Dereferencing 0xdeadbeef as any type larger than u8 is undefined behavior, and a recently merged PR for Rust added runtime debug assertions for this.

Thus, instead of the desired effects, the above code panics with the message 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0xdeadbeef'.

Fortunately, the author chose the value 42 such that it fits in an u8, facilitating an easy fix without the need to invent another funny address that would additionally be 8-byte aligned ;)

The English blog text does not mention the type of the pointer so I assume that neither do the translations.

@SPuntte SPuntte changed the title Fix panic caused by misaligned pointer dereference in "Double Faults" Fix panics caused by misaligned pointer dereferences in "Double Faults" & "Introduction to Paging" May 31, 2023
@riking
Copy link
Copy Markdown

riking commented Jun 1, 2023

without the need to invent another funny address that would additionally be 8-byte aligned ;)

abad1dea is 2-byte aligned.

Copy link
Copy Markdown
Owner

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@phil-opp phil-opp merged commit a1b195e into phil-opp:main Jun 2, 2023
@phil-opp phil-opp added the relnotes "Release notes" – Notable changes that are rendered on the blog. label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes "Release notes" – Notable changes that are rendered on the blog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants