1 // Copyright 2018 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // Copyright © 2022 Intel Corporation 6 // 7 // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause 8 9 #![no_main] 10 11 use libfuzzer_sys::fuzz_target; 12 use vm_memory::{bitmap::AtomicBitmap, GuestAddress}; 13 14 type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>; 15 16 const MEM_SIZE: usize = 256 * 1024 * 1024; 17 // From 'arch::x86_64::layout::CMDLINE_START' 18 const CMDLINE_START: GuestAddress = GuestAddress(0x20000); 19 20 fuzz_target!(|bytes| { 21 let payload_config = vmm::config::PayloadConfig { 22 firmware: None, 23 kernel: None, 24 cmdline: Some(String::from_utf8_lossy(&bytes).to_string()), 25 initramfs: None, 26 #[cfg(feature = "igvm")] 27 igvm: None, 28 }; 29 let kernel_cmdline = match vmm::vm::Vm::generate_cmdline(&payload_config) { 30 Ok(cmdline) => cmdline, 31 _ => return, 32 }; 33 let guest_memory = GuestMemoryMmap::from_ranges(&[(GuestAddress(0), MEM_SIZE)]).unwrap(); 34 35 linux_loader::loader::load_cmdline(&guest_memory, CMDLINE_START, &kernel_cmdline).ok(); 36 }); 37