block: Check request total length is a multiple of SECTOR_SIZE

The request can be spread over multiple descriptors but the virtio-block
specification (and this code) expects that is a whole number of sectors
(512 bytes).

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-07-08 15:32:30 +01:00
committed by Bo Chen
parent 5b99f9ce41
commit 1ba5f15198
2 changed files with 6 additions and 1 deletions

View File

@@ -644,7 +644,10 @@ impl Request {
if total_bytes == 0 {
return Ok(());
}
let total_sectors = total_bytes.div_ceil(SECTOR_SIZE);
if !total_bytes.is_multiple_of(SECTOR_SIZE) {
return Err(ExecuteError::BadRequest(Error::InvalidDataLength));
}
let total_sectors = total_bytes / SECTOR_SIZE;
let end_sector = self
.sector
.checked_add(total_sectors)

View File

@@ -71,6 +71,8 @@ pub enum Error {
GetFileMetadata(#[source] io::Error),
#[error("The requested operation would cause a seek beyond disk end")]
InvalidOffset,
#[error("Request data length is not a multiple of the 512-byte sector size")]
InvalidDataLength,
#[error("Failure in qcow")]
QcowError(#[source] qcow::Error),
#[error("The requested operation does not support multiple descriptors")]