From da3f64c8fe01dae1eaf1e1fc192dfcd711dc1dbe Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Mon, 23 Apr 2018 11:28:59 -0700 Subject: [PATCH] crovm/plugin: fix PerVcpuState to be per vcpu Because resize was used to grow a vec, each Arc> was cloned from the original Default, merely increasing the ref count on the same default data. This change manually pushes a unique set of data per vcpu. BUG=chromium:835916 TEST=None Change-Id: I7116c764effd0f33f706f912bcf4d5d28ba1e08e Reviewed-on: https://chromium-review.googlesource.com/1024504 Commit-Ready: Zach Reizner Tested-by: Zach Reizner Reviewed-by: Aleksandr Kartashov Reviewed-by: Dmitry Torokhov Reviewed-by: Dylan Reid --- src/plugin/process.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugin/process.rs b/src/plugin/process.rs index 67f1b87296..4e7656f737 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -144,8 +144,15 @@ impl Process { for _ in 0..cpu_count { vcpu_sockets.push(new_seqpacket_pair().map_err(Error::CreateVcpuSocket)?); } - let mut per_vcpu_states: Vec>> = Vec::new(); - per_vcpu_states.resize(cpu_count as usize, Default::default()); + let mut per_vcpu_states: Vec>> = Vec::with_capacity(cpu_count as + usize); + // TODO(zachr): replace with `resize_default` when that stabilizes. Using a plain `resize` + // is incorrect because each element in the `Vec` will contain a shared reference to the + // same `PerVcpuState` instance. This happens because `resize` fills new slots using clones + // of the instance given to `resize`. + for _ in 0..cpu_count { + per_vcpu_states.push(Default::default()); + } let plugin_pid = match jail { Some(jail) => {