Skip to content

Commit

Permalink
vdpa_sim_blk: check if sector is 0 for commands other than read or write
Browse files Browse the repository at this point in the history
VIRTIO spec states: "The sector number indicates the offset
(multiplied by 512) where the read or write is to occur. This field is
unused and set to 0 for commands other than read or write."

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20220811083632.77525-2-sgarzare@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Stefano Garzarella authored and Michael S. Tsirkin committed Aug 11, 2022
1 parent 0c89e2a commit b91cf6e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim,
offset = sector << SECTOR_SHIFT;
status = VIRTIO_BLK_S_OK;

if (type != VIRTIO_BLK_T_IN && type != VIRTIO_BLK_T_OUT &&
sector != 0) {
dev_dbg(&vdpasim->vdpa.dev,
"sector must be 0 for %u request - sector: 0x%llx\n",
type, sector);
status = VIRTIO_BLK_S_IOERR;
goto err_status;
}

switch (type) {
case VIRTIO_BLK_T_IN:
if (!vdpasim_blk_check_range(sector, to_push)) {
Expand Down Expand Up @@ -178,6 +187,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim,
break;
}

err_status:
/* If some operations fail, we need to skip the remaining bytes
* to put the status in the last byte
*/
Expand Down

0 comments on commit b91cf6e

Please sign in to comment.