Skip to contentSkip to conversation

vdpa_sim: fix pointer math in get_config

PATCH New Michael S. Tsirkin 1 participant 1 message Aug 10, 2020 virtio core

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vdpa_sim: fix pointer math in get_config

There is a pointer math bug here: the variable cast is a struct so the offset is in units of struct size. If "offset" is non-zero this will copy memory from beyond the end of the array.

Fixes 2c53d0f64c06 ("vdpasim: vDPA device simulator")
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +1 -1
index 604d9d25ca47..62d640327145 100644
@@ -558,7 +558,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset,
 	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
 
 	if (offset + len < sizeof(struct virtio_net_config))
-		memcpy(buf, &vdpasim->config + offset, len);
+		memcpy(buf, (u8 *)&vdpasim->config + offset, len);
 }
 
 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization