Skip to content

Commit

Permalink
Fix CI from the prior CVE fixes (#5250)
Browse files Browse the repository at this point in the history
Pulling in various shapes of fixes from `release-2.0.0` and `main`.
  • Loading branch information
alexcrichton committed Nov 14, 2022
1 parent 75260f5 commit b84167f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
18 changes: 10 additions & 8 deletions crates/runtime/src/cow.rs
Expand Up @@ -647,14 +647,16 @@ impl MemoryImageSlot {
/// Map anonymous zeroed memory across the whole slot,
/// inaccessible. Used both during instantiate and during drop.
fn reset_with_anon_memory(&mut self) -> Result<()> {
unsafe {
let ptr = rustix::mm::mmap_anonymous(
self.base as *mut c_void,
self.static_size,
rustix::mm::ProtFlags::empty(),
rustix::mm::MapFlags::PRIVATE | rustix::mm::MapFlags::FIXED,
)?;
assert_eq!(ptr as usize, self.base);
if self.static_size > 0 {
unsafe {
let ptr = rustix::mm::mmap_anonymous(
self.base as *mut c_void,
self.static_size,
rustix::mm::ProtFlags::empty(),
rustix::mm::MapFlags::PRIVATE | rustix::mm::MapFlags::FIXED,
)?;
assert_eq!(ptr as usize, self.base);
}
}

self.image = None;
Expand Down
12 changes: 9 additions & 3 deletions crates/runtime/src/instance/allocator/pooling.rs
Expand Up @@ -330,13 +330,19 @@ impl InstancePool {
)
};

let mut slot = self
.memories
.take_memory_image_slot(instance_index, defined_index);
let slot = if cfg!(memory_init_cow) {
Some(
self.memories
.take_memory_image_slot(instance_index, defined_index),
)
} else {
None
};
if let Some(image) = runtime_info
.memory_image(defined_index)
.map_err(|err| InstantiationError::Resource(err.into()))?
{
let mut slot = slot.unwrap();
let initial_size = plan.memory.minimum * WASM_PAGE_SIZE as u64;

// If instantiation fails, we can propagate the error
Expand Down
21 changes: 6 additions & 15 deletions tests/all/pooling_allocator.rs
Expand Up @@ -581,14 +581,10 @@ fn drop_externref_global_during_module_init() -> Result<()> {

#[test]
fn switch_image_and_non_image() -> Result<()> {
let mut pool = PoolingAllocationConfig::default();
pool.instance_count(1);
let mut c = Config::new();
c.allocation_strategy(InstanceAllocationStrategy::Pooling {
instance_limits: InstanceLimits {
count: 1,
..Default::default()
},
strategy: Default::default(),
});
c.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
let engine = Engine::new(&c)?;
let module1 = Module::new(
&engine,
Expand Down Expand Up @@ -683,15 +679,10 @@ configured maximum of 16 bytes; breakdown of allocation requirement:

#[test]
fn zero_memory_pages_disallows_oob() -> Result<()> {
let mut pool = PoolingAllocationConfig::default();
pool.instance_count(1).instance_memory_pages(0);
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling {
strategy: PoolingAllocationStrategy::NextAvailable,
instance_limits: InstanceLimits {
count: 1,
memory_pages: 0,
..Default::default()
},
});
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));

let engine = Engine::new(&config)?;
let module = Module::new(
Expand Down

0 comments on commit b84167f

Please sign in to comment.