Skip to content

Commit e1f33be

Browse files
gkurzmstsirkin
authored andcommitted
vhost: fix error path in vhost_init_used()
We don't want side effects. If something fails, we rollback vq->is_le to its previous value. Signed-off-by: Greg Kurz <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 4e94ebd commit e1f33be

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/vhost/vhost.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,8 @@ int vhost_init_used(struct vhost_virtqueue *vq)
11561156
{
11571157
__virtio16 last_used_idx;
11581158
int r;
1159+
bool is_le = vq->is_le;
1160+
11591161
if (!vq->private_data) {
11601162
vq->is_le = virtio_legacy_is_little_endian();
11611163
return 0;
@@ -1165,15 +1167,20 @@ int vhost_init_used(struct vhost_virtqueue *vq)
11651167

11661168
r = vhost_update_used_flags(vq);
11671169
if (r)
1168-
return r;
1170+
goto err;
11691171
vq->signalled_used_valid = false;
1170-
if (!access_ok(VERIFY_READ, &vq->used->idx, sizeof vq->used->idx))
1171-
return -EFAULT;
1172+
if (!access_ok(VERIFY_READ, &vq->used->idx, sizeof vq->used->idx)) {
1173+
r = -EFAULT;
1174+
goto err;
1175+
}
11721176
r = __get_user(last_used_idx, &vq->used->idx);
11731177
if (r)
1174-
return r;
1178+
goto err;
11751179
vq->last_used_idx = vhost16_to_cpu(vq, last_used_idx);
11761180
return 0;
1181+
err:
1182+
vq->is_le = is_le;
1183+
return r;
11771184
}
11781185
EXPORT_SYMBOL_GPL(vhost_init_used);
11791186

0 commit comments

Comments
 (0)