-
Notifications
You must be signed in to change notification settings - Fork 177
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
native runtime: implement memory bounds check #751
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a40121a
native runtime: implement memory bounds check
yamt 20027a6
add some test code for memory bounds check
yamt 526984e
avoid void pointer arithmetics, which is a GCC extention
yamt 380805f
runtimes/native: don't reject zero-byte memory access
yamt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(module | ||
(func $blit (import "env" "blit") (param i32 i32 i32 i32 i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 0x10 | ||
i32.const 0x10000001 | ||
i32.const 0 | ||
call $blit | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(module | ||
(func $blit (import "env" "blit") (param i32 i32 i32 i32 i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 0x8 | ||
i32.const 0x10000001 | ||
i32.const 1 | ||
call $blit | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(module | ||
(func $blit (import "env" "blit") (param i32 i32 i32 i32 i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 65529 | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 8 | ||
i32.const 8 | ||
i32.const 0 | ||
call $blit | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(module | ||
(func $blit (import "env" "blit") (param i32 i32 i32 i32 i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 65521 | ||
i32.const 0 | ||
i32.const 0 | ||
i32.const 8 | ||
i32.const 8 | ||
i32.const 1 | ||
call $blit | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(module | ||
(func $tracef (import "env" "tracef") (param i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 50000 | ||
i32.const 65529 | ||
call $tracef | ||
) | ||
(data (i32.const 50000) "%f\00") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(module | ||
(func $tracef (import "env" "tracef") (param i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 65533 | ||
i32.const 0 | ||
call $tracef | ||
) | ||
(data (i32.const 65533) "xxx") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(module | ||
(func $tracef (import "env" "tracef") (param i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 40000 | ||
i32.const 65533 | ||
i32.store | ||
|
||
i32.const 50000 | ||
i32.const 40000 | ||
call $tracef | ||
) | ||
(data (i32.const 50000) "%s\00") | ||
(data (i32.const 65533) "xxx") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(module | ||
(func $tracef (import "env" "tracef") (param i32 i32)) | ||
(memory (import "env" "memory") 1 1) | ||
(func (export "update") | ||
i32.const 50000 | ||
i32.const 65533 | ||
call $tracef | ||
) | ||
(data (i32.const 50000) "%s\00") | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the bounds check here, but do we necessarily need to do an overflow checked multiply? I think we can live with possible overflows, as long as it doesn't allow out of bounds access somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to implement bounds check that way, we need to make this module (runtime.c) know the implementation details of w4_framebufferBlit. or, implement bounds check in w4_framebufferBlit itself.
IMO, it's simpler to perform overflow checks here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Passing huge values for width/height here that result in an overflow here would fool the bounds check and result in OOB in w4_framebufferBlit. Nice catch!