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

Set an executable page at the top of the stack #433

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enable-chaos-mode-by-default = ["ckb-vm-definitions/enable-chaos-mode-by-default
# Disable slow tests to run miri on CI
miri-ci = []
pprof = []
heap-stack-overlap-detect = []

[dependencies]
byteorder = "1"
Expand Down
10 changes: 10 additions & 0 deletions src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ pub trait SupportMachine: CoreMachine {
stack_start: u64,
stack_size: u64,
) -> Result<u64, Error> {
#[cfg(feature = "heap-stack-overlap-detect")]
{
use super::memory::FLAG_EXECUTABLE;
use super::RISCV_PAGESIZE;
// When the heap or stack attempts to write data to this area,
// ckb-vm will return an error due to wxorx rules.
self.memory_mut()
.set_flag(stack_start / RISCV_PAGESIZE as u64, FLAG_EXECUTABLE)?;
}

// When we re-ordered the sections of a program, writing data in high memory
// will cause unnecessary changes. At the same time, for ckb, argc is always 0
// and the memory is initialized to 0, so memory writing can be safely skipped.
Expand Down
1 change: 1 addition & 0 deletions tests/test_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ pub fn test_asm_wxorx_crash_64() {
);
}

#[cfg(not(feature = "heap-stack-overlap-detect"))]
#[test]
pub fn test_asm_alloc_many() {
let buffer = fs::read("tests/programs/alloc_many").unwrap().into();
Expand Down
1 change: 1 addition & 0 deletions tests/test_dy_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn run_memory_suc(memory_size: usize, bin_path: String, bin_name: String) {
}
}

#[cfg(not(feature = "heap-stack-overlap-detect"))]
#[test]
fn test_dy_memory() {
run_memory_suc(
Expand Down
1 change: 1 addition & 0 deletions tests/test_resume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(has_asm)]
#![cfg(not(feature = "heap-stack-overlap-detect"))]
pub mod machine_build;
use bytes::Bytes;
use ckb_vm::cost_model::constant_cycles;
Expand Down
1 change: 1 addition & 0 deletions tests/test_resume2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(has_asm)]
#![cfg(not(feature = "heap-stack-overlap-detect"))]
pub mod machine_build;
use bytes::Bytes;
use ckb_vm::cost_model::constant_cycles;
Expand Down
Loading