From nobody Mon May 25 06:40:18 2026 Received: from mail-03.1984.is (mail-03.1984.is [93.95.224.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D78E3B840F; Sun, 17 May 2026 14:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.95.224.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027379; cv=none; b=h4I0V3wZ1ipDHAaEGM8mLiDK6CuneXGbyScHYMvZqtgklMBISMQbb33A9gSJYKxhP13AAPM26O+nYZec1UEWML/ukUOqkHY8TaQ0hOndMZuuk5PiLnO0bINs1mEyk0Q9I8P9evUWMW0Zp3MRbZBwdx53tumCb2MppXDXtserxUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027379; c=relaxed/simple; bh=odM2YlQPz4z+Xbldmx3UAYOUP4AUgiktv9wgjCikjyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SEc33JkIlhaJXhC5P+I63lNwbrL6QCmJK438WPNrZax3gaJX9vv4OboJS6vy6grIKVwe8LBkVTHCoEXJ2PH8RtdVqrZZg+bAfuFPcufKWCIlzf3FdtW1hQfOiDJM139nNIqiv3TPVaTCDTzBDOJJzUmv84rFyXF8XFUSs9A7sss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=berkoc.com; spf=pass smtp.mailfrom=berkoc.com; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b=fu9d1BKu; arc=none smtp.client-ip=93.95.224.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=berkoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=berkoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b="fu9d1BKu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=berkoc.com; s=1984; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=gTqRY6sQfKZTTJNrPsag8pd2dprTtNMTjuf+gLE+BZk=; b=fu9d1BKuMdBjtrqIvVOiANgRiE 4QKyasC9whyRqUh2xU0NBLLeXTjYfE9oMuLVYJEeisQ2QOGNx4O/fi+h1NGRXxxm/suDMJONWLoO7 tCNnqP+D525EUzpXvy7EZxdC/lRIRfHWBVODG/Sq5lUbl/Kc8rWsZSz+qn0laVlhqju0nxqDSXF7/ 9y7oLQM2UCyqI2vUc0+M3Agh5K/l8HTaZX8QhBMPQH5Wrw8nfszmVHjnnbwDnb5TNLOpOlC6HmSpU FV/9/t01dRQSW858P2h28v63VdyJf+ui9GPRgboNw+drgUFLwvkMzVdvQ3qiamzZokjzi937lWVnY duKN8bog==; Received: from localhost by mail-03.1984.is with utf8esmtp (Exim 4.96) (envelope-from ) id 1wOcHU-00HFWk-1I; Sun, 17 May 2026 14:15:49 +0000 From: Berkant Koc To: Saurabh Sengar , Dexuan Cui , Long Li Cc: linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Michael Kelley , Thomas Zimmermann , Maarten Lankhorst , Maxime Ripard , Deepak Rawat , stable@vger.kernel.org Subject: [PATCH v2 1/2] drm/hyperv: validate resolution_count and harden VSP request paths Date: Sun, 17 May 2026 16:25:01 +0200 Message-ID: <20260517-drm-hyperv-patch1-v2@berkoc.com> In-Reply-To: <20260517-drm-hyperv-cover-v2@berkoc.com> References: <20260517-drm-hyperv-cover@berkoc.com> <20260517-drm-hyperv-patch1@berkoc.com> <20260517134926.B4179C2BCB0@smtp.kernel.org> <20260517-drm-hyperv-cover-v2@berkoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable User-Agent: git-send-email/2.47.3 X-Spam-Score: -0.0 (/) X-Authenticated-User: me@berkoc.com X-Sender-Address: me@berkoc.com Content-Type: text/plain; charset="utf-8" The synthetic video device parses a SYNTHVID_RESOLUTION_RESPONSE that contains a u8 resolution_count and a u8 default_resolution_index. The existing check rejects resolution_count =3D=3D 0 and an index 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 the array bound, folded into the existing zero-check so a single log entry remains per failure. When that bounds check (or any later failure in hyperv_get_supported_resolution()) returns an error, the caller in hyperv_connect_vsp() previously logged a warning and continued without populating hv->screen_width_max / hv->screen_height_max / preferred_*. hyperv_mode_config_init() then set dev->mode_config.max_width and max_height to 0, which makes drm_internal_framebuffer_create() reject every userspace framebuffer with -EINVAL. Populate the fields with the WIN8 defaults that the pre-WIN10 branch already uses so a failed resolution probe degrades to a usable display instead of disabling it. The driver also issues three sequential VSP requests (negotiate version, update VRAM location, get supported resolution) that share a single hv->wait completion. None of the call sites call reinit_completion() between requests. If wait_for_completion_timeout() returns 0 but a delayed response later triggers complete(&hv->wait) in the receive callback, the next request's wait can consume that stale completion, return immediately, and parse stale data out of hv->init_buf. Call reinit_completion() before each send so every request waits for its own response. Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video= device") Cc: stable@vger.kernel.org # 5.14+ Signed-off-by: Berkant Koc --- drivers/gpu/drm/hyperv/hyperv_drm_proto.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c b/drivers/gpu/drm/hy= perv/hyperv_drm_proto.c index 051ecc526832..3b5065fe06e4 100644 --- a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c +++ b/drivers/gpu/drm/hyperv/hyperv_drm_proto.c @@ -223,6 +223,7 @@ static int hyperv_negotiate_version(struct hv_device *h= dev, u32 ver) msg->vid_hdr.size =3D sizeof(struct synthvid_msg_hdr) + sizeof(struct synthvid_version_req); msg->ver_req.version =3D ver; + reinit_completion(&hv->wait); hyperv_sendpacket(hdev, msg); =20 t =3D wait_for_completion_timeout(&hv->wait, VMBUS_VSP_TIMEOUT); @@ -257,6 +258,7 @@ int hyperv_update_vram_location(struct hv_device *hdev,= phys_addr_t vram_pp) msg->vram.user_ctx =3D vram_pp; msg->vram.vram_gpa =3D vram_pp; msg->vram.is_vram_gpa_specified =3D 1; + reinit_completion(&hv->wait); hyperv_sendpacket(hdev, msg); =20 t =3D wait_for_completion_timeout(&hv->wait, VMBUS_VSP_TIMEOUT); @@ -383,6 +385,7 @@ static int hyperv_get_supported_resolution(struct hv_de= vice *hdev) sizeof(struct synthvid_supported_resolution_req); msg->resolution_req.maximum_resolution_count =3D SYNTHVID_MAX_RESOLUTION_COUNT; + reinit_completion(&hv->wait); hyperv_sendpacket(hdev, msg); =20 t =3D wait_for_completion_timeout(&hv->wait, VMBUS_VSP_TIMEOUT); @@ -391,8 +394,11 @@ static int hyperv_get_supported_resolution(struct hv_d= evice *hdev) return -ETIMEDOUT; } =20 - if (msg->resolution_resp.resolution_count =3D=3D 0) { - drm_err(dev, "No supported resolutions\n"); + if (msg->resolution_resp.resolution_count =3D=3D 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; } =20 @@ -506,8 +512,13 @@ int hyperv_connect_vsp(struct hv_device *hdev) =20 if (hyperv_version_ge(hv->synthvid_version, SYNTHVID_VERSION_WIN10)) { ret =3D hyperv_get_supported_resolution(hdev); - if (ret) + if (ret) { drm_err(dev, "Failed to get supported resolution from host, use default= \n"); + hv->screen_width_max =3D SYNTHVID_WIDTH_WIN8; + hv->screen_height_max =3D SYNTHVID_HEIGHT_WIN8; + hv->preferred_width =3D SYNTHVID_WIDTH_WIN8; + hv->preferred_height =3D SYNTHVID_HEIGHT_WIN8; + } } else { hv->screen_width_max =3D SYNTHVID_WIDTH_WIN8; hv->screen_height_max =3D SYNTHVID_HEIGHT_WIN8; --=20 2.47.3 From nobody Mon May 25 06:40:18 2026 Received: from mail-01.1984.is (mail-01.1984.is [185.112.145.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C67A23B4EA5; Sun, 17 May 2026 14:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.112.145.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027386; cv=none; b=cNZyz+rvybQV3JrLlQu0ycGcNkT8G9ZabGYRndeIR7FgxWb2aHdqwsNh21XPZGWPfEokaDNOvEn9GMxQR8rQl4mAyUTuafUhDUoZ727M7kCpvUza4DW+MXQea4gGsOhzz+d+uIs3940xM+JOHSqZ9NpGv8Ap/61LKgh5xkxfKes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779027386; c=relaxed/simple; bh=wfRtwd5UyLQeg6FmTxzzEcj0AG+dbYmOt73exLQ4iWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fIMzutSPGsz9pMkjNrXRxbfH9GBEghC5VXb+baK6atX3m+DgPvUFu1tJuZGw6heBVA5h/HcVailJJtigiVYLULjadyhSDcUtquvyGQLAuuyTdXRVkm2FPhSUVz9Ww4KfAi1H8NQKh76bUfBbNdHZP7zZluxSzPby8Bvrni6I//o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=berkoc.com; spf=pass smtp.mailfrom=berkoc.com; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b=JQs7UWV+; arc=none smtp.client-ip=185.112.145.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=berkoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=berkoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b="JQs7UWV+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=berkoc.com; s=1984; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MQ8YiYdNWpRqmjF8/PofO4sgGjF2gJ1u/rtwQhqBB4A=; b=JQs7UWV+0f8ACDzMvMmCgR0P+M RTTcR2fvyyLiN35YD/qnMLGg+S22ZsPGZOZgqz/olECemqjiiGdWEUc4PCuToI8QTEOd3LSaq8bzz OHHhyTlaJo/a0tJHLhvikNDv7lDbfOiqzd6Ro1+Q2rFGytyES7TMECdTFh4vRyieuAC1Y6JsvhtEs enBLO3JpZZUlhhRgkpPKAZ1fl7cUboQELh8+wNn5KT/Ff9GF5p5TpLuK5ecz6xojdLxkP12heZpYh HG1q8c6ejzhm2qkdICdc9kSIwxEgeul/CrJoyHx/csIiUoJ6EqCdj08clvJJO2qy4JWrVwOuUzaI1 EOvzZ8qA==; Received: from localhost by mail-01.1984.is with utf8esmtp (Exim 4.96) (envelope-from ) id 1wOcHk-00GB2e-1S; Sun, 17 May 2026 14:16:05 +0000 From: Berkant Koc To: Saurabh Sengar , Dexuan Cui , Long Li Cc: linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Michael Kelley , Thomas Zimmermann , Maarten Lankhorst , Maxime Ripard , Deepak Rawat , stable@vger.kernel.org Subject: [PATCH v2 2/2] drm/hyperv: validate VMBus packet size in receive callback Date: Sun, 17 May 2026 16:25:02 +0200 Message-ID: <20260517-drm-hyperv-patch2-v2@berkoc.com> In-Reply-To: <20260517-drm-hyperv-cover-v2@berkoc.com> References: <20260517-drm-hyperv-cover@berkoc.com> <20260517-drm-hyperv-patch2@berkoc.com> <20260517-drm-hyperv-cover-v2@berkoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable User-Agent: git-send-email/2.47.3 X-Spam-Score: -0.0 (/) X-Authenticated-User: me@berkoc.com X-Sender-Address: me@berkoc.com Content-Type: text/plain; charset="utf-8" hyperv_receive() reads bytes_recvd from vmbus_recvpacket() but does not forward that value to hyperv_receive_sub(). The sub-handler reads msg->vid_hdr.type and msg->feature_chg.is_dirt_needed without knowing how many bytes the host actually wrote, so a short packet leaves the parser reading bytes that the host did not write in this packet. The unconditional memcpy(hv->init_buf, msg, VMBUS_MAX_PACKET_SIZE) on the wait-completion path also copies the full 16 KiB recv_buf regardless of bytes_recvd, including any residue from the prior message. Pass bytes_recvd into hyperv_receive_sub() and reject any packet shorter than the pipe + synthvid header. The dirt-feature branch additionally requires the feature_change payload size before reading is_dirt_needed. The init_buf copy now uses bytes_recvd as the length argument, which keeps it bounded by VMBUS_MAX_PACKET_SIZE through the new upper check. Unchanged from v1. Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video= device") Cc: stable@vger.kernel.org # 5.14+ Signed-off-by: Berkant Koc --- drivers/gpu/drm/hyperv/hyperv_drm_proto.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c b/drivers/gpu/drm/hy= perv/hyperv_drm_proto.c index 3b5065fe06e4..cdab4895dd40 100644 --- a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c +++ b/drivers/gpu/drm/hyperv/hyperv_drm_proto.c @@ -423,26 +423,35 @@ static int hyperv_get_supported_resolution(struct hv_= device *hdev) return 0; } =20 -static void hyperv_receive_sub(struct hv_device *hdev) +static void hyperv_receive_sub(struct hv_device *hdev, u32 bytes_recvd) { struct hyperv_drm_device *hv =3D hv_get_drvdata(hdev); struct synthvid_msg *msg; + size_t hdr_size; =20 if (!hv) return; =20 + hdr_size =3D sizeof(struct pipe_msg_hdr) + + sizeof(struct synthvid_msg_hdr); + if (bytes_recvd < hdr_size || bytes_recvd > VMBUS_MAX_PACKET_SIZE) + return; + msg =3D (struct synthvid_msg *)hv->recv_buf; =20 /* Complete the wait event */ if (msg->vid_hdr.type =3D=3D SYNTHVID_VERSION_RESPONSE || msg->vid_hdr.type =3D=3D SYNTHVID_RESOLUTION_RESPONSE || msg->vid_hdr.type =3D=3D SYNTHVID_VRAM_LOCATION_ACK) { - memcpy(hv->init_buf, msg, VMBUS_MAX_PACKET_SIZE); + memcpy(hv->init_buf, msg, bytes_recvd); complete(&hv->wait); return; } =20 if (msg->vid_hdr.type =3D=3D SYNTHVID_FEATURE_CHANGE) { + if (bytes_recvd < hdr_size + + sizeof(struct synthvid_feature_change)) + return; hv->dirt_needed =3D msg->feature_chg.is_dirt_needed; if (hv->dirt_needed) hyperv_hide_hw_ptr(hv->hdev); @@ -469,7 +478,7 @@ static void hyperv_receive(void *ctx) &bytes_recvd, &req_id); if (bytes_recvd > 0 && recv_buf->pipe_hdr.type =3D=3D PIPE_MSG_DATA) - hyperv_receive_sub(hdev); + hyperv_receive_sub(hdev, bytes_recvd); } while (bytes_recvd > 0 && ret =3D=3D 0); } =20 --=20 2.47.3