Skip to content

Commit b91cf6e

Browse files
stefano-garzarellamstsirkin
authored andcommitted
vdpa_sim_blk: check if sector is 0 for commands other than read or write
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>
1 parent 0c89e2a commit b91cf6e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/vdpa/vdpa_sim/vdpa_sim_blk.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim,
112112
offset = sector << SECTOR_SHIFT;
113113
status = VIRTIO_BLK_S_OK;
114114

115+
if (type != VIRTIO_BLK_T_IN && type != VIRTIO_BLK_T_OUT &&
116+
sector != 0) {
117+
dev_dbg(&vdpasim->vdpa.dev,
118+
"sector must be 0 for %u request - sector: 0x%llx\n",
119+
type, sector);
120+
status = VIRTIO_BLK_S_IOERR;
121+
goto err_status;
122+
}
123+
115124
switch (type) {
116125
case VIRTIO_BLK_T_IN:
117126
if (!vdpasim_blk_check_range(sector, to_push)) {
@@ -178,6 +187,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim,
178187
break;
179188
}
180189

190+
err_status:
181191
/* If some operations fail, we need to skip the remaining bytes
182192
* to put the status in the last byte
183193
*/

0 commit comments

Comments
 (0)