Skip to content

Commit dc1db00

Browse files
Dan Carpentermstsirkin
authored andcommitted
vduse: check that offset is within bounds in get_config()
This condition checks "len" but it does not check "offset" and that could result in an out of bounds read if "offset > dev->config_size". The problem is that since both variables are unsigned the "dev->config_size - offset" subtraction would result in a very high unsigned value. I think these checks might not be necessary because "len" and "offset" are supposed to already have been validated using the vhost_vdpa_config_validate() function. But I do not know the code perfectly, and I like to be safe. Fixes: c8a6153 ("vduse: Introduce VDUSE - vDPA Device in Userspace") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/20211208150956.GA29160@kili Signed-off-by: Michael S. Tsirkin <[email protected]> Cc: [email protected]
1 parent 3ed21c1 commit dc1db00

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ static void vduse_vdpa_get_config(struct vdpa_device *vdpa, unsigned int offset,
655655
{
656656
struct vduse_dev *dev = vdpa_to_vduse(vdpa);
657657

658-
if (len > dev->config_size - offset)
658+
if (offset > dev->config_size ||
659+
len > dev->config_size - offset)
659660
return;
660661

661662
memcpy(buf, dev->config + offset, len);

0 commit comments

Comments
 (0)