diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 6e3d895ed..c78d2382d 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -52,6 +52,9 @@ jobs: - name: Formatting (rustfmt) run: cargo fmt --all -- --check + - name: Formatting (fuzz) (rustfmt) + run: cargo fmt --all --manifest-path fuzz/Cargo.toml -- --check + - name: Clippy (kvm) uses: actions-rs/cargo@v1 with: diff --git a/fuzz/fuzz_targets/balloon.rs b/fuzz/fuzz_targets/balloon.rs index 3cd5aabc4..ec97149bd 100644 --- a/fuzz/fuzz_targets/balloon.rs +++ b/fuzz/fuzz_targets/balloon.rs @@ -4,10 +4,11 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/block.rs b/fuzz/fuzz_targets/block.rs index 8714a8a40..01d774e8f 100644 --- a/fuzz/fuzz_targets/block.rs +++ b/fuzz/fuzz_targets/block.rs @@ -8,20 +8,21 @@ #![no_main] -use block::{async_io::DiskFile, raw_sync::RawFileDiskSync}; -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; +use std::collections::BTreeMap; use std::ffi; use std::fs::File; use std::io; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::PathBuf; use std::sync::Arc; + +use block::{async_io::DiskFile, raw_sync::RawFileDiskSync}; +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; -use std::collections::BTreeMap; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/console.rs b/fuzz/fuzz_targets/console.rs index 4fba45b3b..58d20c224 100644 --- a/fuzz/fuzz_targets/console.rs +++ b/fuzz/fuzz_targets/console.rs @@ -4,12 +4,13 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::fs::File; use std::io::Write; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/http_api.rs b/fuzz/fuzz_targets/http_api.rs index 18e44b379..5a6eefdc5 100644 --- a/fuzz/fuzz_targets/http_api.rs +++ b/fuzz/fuzz_targets/http_api.rs @@ -3,13 +3,14 @@ // SPDX-License-Identifier: Apache-2.0 #![no_main] -use libfuzzer_sys::fuzz_target; -use micro_http::Request; -use once_cell::sync::Lazy; use std::os::unix::io::AsRawFd; use std::path::PathBuf; use std::sync::mpsc::{channel, Receiver}; use std::thread; + +use libfuzzer_sys::fuzz_target; +use micro_http::Request; +use once_cell::sync::Lazy; use vm_migration::MigratableError; use vmm::api::{ http::*, ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData, diff --git a/fuzz/fuzz_targets/iommu.rs b/fuzz/fuzz_targets/iommu.rs index 414e4270e..8f02b420b 100644 --- a/fuzz/fuzz_targets/iommu.rs +++ b/fuzz/fuzz_targets/iommu.rs @@ -4,10 +4,11 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/linux_loader.rs b/fuzz/fuzz_targets/linux_loader.rs index 54de31ae2..fd6c09d66 100644 --- a/fuzz/fuzz_targets/linux_loader.rs +++ b/fuzz/fuzz_targets/linux_loader.rs @@ -8,13 +8,14 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use linux_loader::loader::KernelLoader; use std::ffi; use std::fs::File; use std::io; use std::io::{Seek, SeekFrom, Write}; use std::os::unix::io::{FromRawFd, RawFd}; + +use libfuzzer_sys::fuzz_target; +use linux_loader::loader::KernelLoader; use vm_memory::{bitmap::AtomicBitmap, GuestAddress}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/mem.rs b/fuzz/fuzz_targets/mem.rs index ab6abf153..e0204e41e 100644 --- a/fuzz/fuzz_targets/mem.rs +++ b/fuzz/fuzz_targets/mem.rs @@ -4,10 +4,11 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::{Arc, Mutex}; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{BlocksState, Mem, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/net.rs b/fuzz/fuzz_targets/net.rs index e77ac6e79..3469e2f28 100644 --- a/fuzz/fuzz_targets/net.rs +++ b/fuzz/fuzz_targets/net.rs @@ -4,12 +4,13 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::fs::File; use std::io::{Read, Write}; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/pmem.rs b/fuzz/fuzz_targets/pmem.rs index 00762fe03..786ad30ec 100644 --- a/fuzz/fuzz_targets/pmem.rs +++ b/fuzz/fuzz_targets/pmem.rs @@ -4,14 +4,15 @@ #![no_main] -use libc::{MAP_NORESERVE, MAP_PRIVATE, PROT_READ, PROT_WRITE}; -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::ffi; use std::fs::File; use std::io; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::sync::Arc; + +use libc::{MAP_NORESERVE, MAP_PRIVATE, PROT_READ, PROT_WRITE}; +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{Pmem, UserspaceMapping, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::guest_memory::FileOffset; diff --git a/fuzz/fuzz_targets/qcow.rs b/fuzz/fuzz_targets/qcow.rs index 2698b87a6..0a7c64fa2 100644 --- a/fuzz/fuzz_targets/qcow.rs +++ b/fuzz/fuzz_targets/qcow.rs @@ -5,14 +5,15 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause #![no_main] -use block::qcow::{QcowFile, RawFile}; -use libfuzzer_sys::fuzz_target; use std::ffi; use std::fs::File; use std::io::{self, Cursor, Read, Seek, SeekFrom, Write}; use std::mem::size_of; use std::os::unix::io::{FromRawFd, RawFd}; +use block::qcow::{QcowFile, RawFile}; +use libfuzzer_sys::fuzz_target; + // Take the first 64 bits of data as an address and the next 64 bits as data to // store there. The rest of the data is used as a qcow image. fuzz_target!(|bytes| { diff --git a/fuzz/fuzz_targets/rng.rs b/fuzz/fuzz_targets/rng.rs index 38ecb1b7a..b38a96cd4 100644 --- a/fuzz/fuzz_targets/rng.rs +++ b/fuzz/fuzz_targets/rng.rs @@ -4,10 +4,11 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; diff --git a/fuzz/fuzz_targets/serial.rs b/fuzz/fuzz_targets/serial.rs index 45f0618b0..9628c0c83 100644 --- a/fuzz/fuzz_targets/serial.rs +++ b/fuzz/fuzz_targets/serial.rs @@ -3,10 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 #![no_main] +use std::sync::Arc; + use devices::legacy::Serial; use libc::EFD_NONBLOCK; use libfuzzer_sys::fuzz_target; -use std::sync::Arc; use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig, InterruptSourceGroup}; use vm_device::BusDevice; use vmm_sys_util::eventfd::EventFd; diff --git a/fuzz/fuzz_targets/vhdx.rs b/fuzz/fuzz_targets/vhdx.rs index 33aedcd93..4f2e0f234 100644 --- a/fuzz/fuzz_targets/vhdx.rs +++ b/fuzz/fuzz_targets/vhdx.rs @@ -3,12 +3,13 @@ // SPDX-License-Identifier: Apache-2.0 #![no_main] -use libfuzzer_sys::fuzz_target; use std::ffi; use std::fs::File; use std::io::{self, Read, Seek, SeekFrom, Write}; use std::os::unix::io::{FromRawFd, RawFd}; + use block::vhdx::Vhdx; +use libfuzzer_sys::fuzz_target; // Populate the corpus directory with a test file: // truncate -s 16M /tmp/source diff --git a/fuzz/fuzz_targets/watchdog.rs b/fuzz/fuzz_targets/watchdog.rs index 1ce70b8fd..2896e9bd3 100644 --- a/fuzz/fuzz_targets/watchdog.rs +++ b/fuzz/fuzz_targets/watchdog.rs @@ -4,10 +4,11 @@ #![no_main] -use libfuzzer_sys::fuzz_target; -use seccompiler::SeccompAction; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::sync::Arc; + +use libfuzzer_sys::fuzz_target; +use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};