The synthetic video device receives a SYNTHVID_RESOLUTION_RESPONSE
containing a u8 resolution_count and a u8 default_resolution_index
from the host. The existing check rejects resolution_count == 0 and
rejects an index that is greater or equal to resolution_count, but
does not bound resolution_count itself against the fixed
supported_resolution[SYNTHVID_MAX_RESOLUTION_COUNT] array. A host
that returns resolution_count > 64 together with an in-range
default_resolution_index causes the subsequent loop to read past
the array.

Reject any resolution_count that exceeds SYNTHVID_MAX_RESOLUTION_COUNT,
folded into the existing zero-check for one log entry per failure.
This matches the input-validation pattern used by other VMBus parsers
under drivers/hv/ and trims one host-controlled value from the trusted
path.

Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video 
device")
Cc: [email protected] # 5.14+
Signed-off-by: Berkant Koc <[email protected]>
---
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c 
b/drivers/gpu/drm/hyperv/hyperv_drm_proto.c
index 051ecc526832..003bb118d64c 100644
--- a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c
+++ b/drivers/gpu/drm/hyperv/hyperv_drm_proto.c
@@ -391,8 +391,11 @@ static int hyperv_get_supported_resolution(struct 
hv_device *hdev)
                return -ETIMEDOUT;
        }
 
-       if (msg->resolution_resp.resolution_count == 0) {
-               drm_err(dev, "No supported resolutions\n");
+       if (msg->resolution_resp.resolution_count == 0 ||
+           msg->resolution_resp.resolution_count >
+           SYNTHVID_MAX_RESOLUTION_COUNT) {
+               drm_err(dev, "Invalid resolution count: %d\n",
+                       msg->resolution_resp.resolution_count);
                return -ENODEV;
        }
 
-- 
2.47.3


Reply via email to