mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
base: windows: error if CPU >= 64 in set_cpu_affinity
The loop that generates the CPU affinity mask uses a shift by the CPU index to generate a u64, so if the shift count is 64 or greater, it will shift past the end of the u64 and panic when overflow checks are enabled (which we enable by default in release builds in Cargo.toml). Add a bounds check so set_cpu_affinity() will return an error rather than causing a panic in this case. BUG=None TEST=run tests via wine on 72 logical core machine Change-Id: I2ac4a0602b2c014aeca4939ec2882926cdfe2c29 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3935523 Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
parent
28de38563d
commit
4b6c33d346
1 changed files with 3 additions and 0 deletions
|
@ -28,6 +28,9 @@ use super::Result;
|
|||
pub fn set_cpu_affinity<I: IntoIterator<Item = usize>>(cpus: I) -> Result<usize> {
|
||||
let mut affinity_mask: usize = 0;
|
||||
for cpu in cpus {
|
||||
if cpu >= 64 {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
affinity_mask |= 1 << cpu;
|
||||
}
|
||||
set_cpu_affinity_mask(affinity_mask)
|
||||
|
|
Loading…
Reference in a new issue