diff mbox series

drm/i915/gvt: Prevent integer overflow in intel_vgpu_emulate_cfg_write()

Message ID 20211124144913.GA13656@kili (mailing list archive)
State New, archived
Headers show
Series drm/i915/gvt: Prevent integer overflow in intel_vgpu_emulate_cfg_write() | expand

Commit Message

Dan Carpenter Nov. 24, 2021, 2:49 p.m. UTC
The "offset" is a u32 that comes from the user.  The bug is that the
"offset + bytes" operation can have an integer overflow problem which
leads to an out of bounds access.

Fixes: 4d60c5fd3f87 ("drm/i915/gvt: vGPU PCI configuration space virtualization")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/i915/gvt/cfg_space.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gvt/cfg_space.c b/drivers/gpu/drm/i915/gvt/cfg_space.c
index b490e3db2e38..8a54dd3de91c 100644
--- a/drivers/gpu/drm/i915/gvt/cfg_space.c
+++ b/drivers/gpu/drm/i915/gvt/cfg_space.c
@@ -316,6 +316,10 @@  int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset,
 	if (drm_WARN_ON(&i915->drm, bytes > 4))
 		return -EINVAL;
 
+	if (drm_WARN_ON(&i915->drm,
+			offset > vgpu->gvt->device_info.cfg_space_size))
+		return -EINVAL;
+
 	if (drm_WARN_ON(&i915->drm,
 			offset + bytes > vgpu->gvt->device_info.cfg_space_size))
 		return -EINVAL;