Skip to content

Commit d65026c

Browse files
jasowangdavem330
authored andcommitted
vhost: validate log when IOTLB is enabled
Vq log_base is the userspace address of bitmap which has nothing to do with IOTLB. So it needs to be validated unconditionally otherwise we may try use 0 as log_base which may lead to pin pages that will lead unexpected result (e.g trigger BUG_ON() in set_bit_to_user()). Fixes: 6b1e6cc ("vhost: new device IOTLB API") Reported-by: [email protected] Signed-off-by: Jason Wang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 58f101b commit d65026c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/vhost/vhost.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,14 +1244,12 @@ static int vq_log_access_ok(struct vhost_virtqueue *vq,
12441244
/* Caller should have vq mutex and device mutex */
12451245
int vhost_vq_access_ok(struct vhost_virtqueue *vq)
12461246
{
1247-
if (vq->iotlb) {
1248-
/* When device IOTLB was used, the access validation
1249-
* will be validated during prefetching.
1250-
*/
1251-
return 1;
1252-
}
1253-
return vq_access_ok(vq, vq->num, vq->desc, vq->avail, vq->used) &&
1254-
vq_log_access_ok(vq, vq->log_base);
1247+
int ret = vq_log_access_ok(vq, vq->log_base);
1248+
1249+
if (ret || vq->iotlb)
1250+
return ret;
1251+
1252+
return vq_access_ok(vq, vq->num, vq->desc, vq->avail, vq->used);
12551253
}
12561254
EXPORT_SYMBOL_GPL(vhost_vq_access_ok);
12571255

0 commit comments

Comments
 (0)