Skip to content

Commit

Permalink
Merge pull request #8 from gurasinghMS/user/gurasingh/remove_arbitrar…
Browse files Browse the repository at this point in the history
…y_tag

Taking care of all the use-arbitrary-inputs
  • Loading branch information
gurasinghMS authored Jan 7, 2025
2 parents d059496 + b10558c commit ccc69c8
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions vm/devices/storage/disk_nvme/nvme_driver/fuzz/fuzz_nvme_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct FuzzNvmeDriver {
impl FuzzNvmeDriver {
/// Setup a new nvme driver with a fuzz-enabled backend device.
pub async fn new(driver: DefaultDriver) -> Result<Self, arbitrary::Error> {
let base_len = 64 << 20; // 64MB TODO: [use-arbitrary-input]
let payload_len = 1 << 20; // 1MB TODO: [use-arbitrary-input]
let base_len = arbitrary_data::<usize>()?;
let payload_len = arbitrary_data::<usize>()?;
let mem = DeviceSharedMemory::new(base_len, payload_len);

// Trasfer buffer
Expand All @@ -52,20 +52,20 @@ impl FuzzNvmeDriver {
&mut msi_set,
&mut ExternallyManagedMmioIntercepts,
NvmeControllerCaps {
msix_count: 2, // TODO: [use-arbitrary-input]
max_io_queues: 64, // TODO: [use-arbitrary-input]
msix_count: arbitrary_data::<u16>()?,
max_io_queues: arbitrary_data::<u16>()?,
subsystem_id: guid,
},
);

nvme.client()
.add_namespace(1, disklayer_ram::ram_disk(2 << 20, false).unwrap()) // TODO: [use-arbitrary-input]
.add_namespace(arbitrary_data::<u32>()?, disklayer_ram::ram_disk(arbitrary_data::<u64>()?, false).unwrap())
.await
.unwrap();

let device = FuzzEmulatedDevice::new(nvme, msi_set, mem);
let nvme_driver = NvmeDriver::new(&driver_source, 64, device).await.unwrap(); // TODO: [use-arbitrary-input]
let namespace = nvme_driver.namespace(1).await.unwrap(); // TODO: [use-arbitrary-input]
let nvme_driver = NvmeDriver::new(&driver_source, arbitrary_data::<u32>()?, device).await.unwrap();
let namespace = nvme_driver.namespace(arbitrary_data::<u32>()?).await.unwrap();

Ok(Self {
driver: Some(nvme_driver),
Expand All @@ -76,24 +76,8 @@ impl FuzzNvmeDriver {

/// Clean up fuzzing infrastructure.
pub async fn shutdown(&mut self) {
self.namespace
.deallocate(
0, // TODO: [use-arbitrary-input]
&[
DsmRange {
context_attributes: 0, // TODO: [use-arbitrary-input]
starting_lba: 1000, // TODO: [use-arbitrary-input]
lba_count: 2000, // TODO: [use-arbitrary-input]
},
DsmRange {
context_attributes: 0, // TODO: [use-arbitrary-input]
starting_lba: 2, // TODO: [use-arbitrary-input]
lba_count: 2, // TODO: [use-arbitrary-input]
},
],
)
.await
.unwrap();
// TODO: Add a feature here to wipe memory that was written to the namespace by the fuzzer.
// Since the fuzzer is deterministic, this is not immediately needed.

self.driver.take().unwrap().shutdown().await;
}
Expand All @@ -108,7 +92,7 @@ impl FuzzNvmeDriver {
block_count,
target_cpu,
} => {
let buf_range = OwnedRequestBuffers::linear(0, 16384, true); // TODO: [use-arbitrary-input]
let buf_range = OwnedRequestBuffers::linear(arbitrary_data::<u64>()?, arbitrary_data::<usize>()?, true);
self.namespace
.read(
target_cpu,
Expand All @@ -126,7 +110,7 @@ impl FuzzNvmeDriver {
block_count,
target_cpu,
} => {
let buf_range = OwnedRequestBuffers::linear(0, 16384, true); // TODO: [use-arbitrary-input]
let buf_range = OwnedRequestBuffers::linear(arbitrary_data::<u64>()?, arbitrary_data::<usize>()?, true);
self.namespace
.write(
target_cpu,
Expand Down

0 comments on commit ccc69c8

Please sign in to comment.