From nobody Sun May 24 20:33:10 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 528A43A7822; Thu, 21 May 2026 20:56:15 +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=1779396977; cv=none; b=DSspuYIxIXI50X6TvEVm82B2fMKOS5pZN8/n6tGT4C+b9nDXjUkIPhTfA+6YdUaYUvKwk8OFq5m0qYelCIARq7O51frHprdwVLv2EMYYT5azwdoH7pIAibMavXAKo842V3Gm0OdXntEEw161x+wgNH5D4qHrm0cwjULvm7YUCek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779396977; c=relaxed/simple; bh=ILuFrIOgTO8y5W1rv5THOEIkmcdLmOdqUeFLjCyS2Xs=; h=Message-ID:In-Reply-To:References:From:To:Cc:Date:Subject; b=ODmYeD3efzLNHlDTweg8Eo/i4H2Gej6tkKsJl8EQv88TtCCaWmuZpduRliit7SzbeXaXGXWzfZCMMwOom4IeR0en8efjaB0qOBVupiQdxGqxq+VLN2flakRhKOmc0sdfJmMfskwghWwXl7blcpSaoH6gOr76AyuVGbFya9frUSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=Q2hQrtm/; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b=i4ycK9WD; arc=none smtp.client-ip=185.112.145.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="Q2hQrtm/"; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b="i4ycK9WD" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=berkoc.com; s=1984; h=Subject:Date:Cc:To:From:References:In-Reply-To:Message-ID:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: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=yEgrKS1yuvRt1SapJoA7ktrpyTmlvnKNqxmZJDoUF6o=; b=Q2hQrtm/Yd/XPUQk8cStEXveZK kmNwLA64ysvTfH/wbylPTAJ8GVEi7VM56N48DYUfRVjBklZKCNLi4g+fzUtsX7nShaX22itc1dPcT uir4jzkrhyUIy5jxAdOD7RPicn/hUqIOxCNaPKgqMwA0ZsWYF301y71US1MQL1ra6O5XJCkBeIxbM CAH7NZzMiAjH/TVQtfD0Nh4GttVGJGbocQTshKGWf3nmLoQqdJUx3VvUtpwpB5iZ/kkwmbCCvXEWR e2JDPBL/YHXZM1az5Xvt5MH/J6IgmVJlI1kCtKMqGU4jgNkC7/560FUDnIgAvdpR/qX6CopVlx7s5 wOe7NnlA==; Received: from localhost by mail-01.1984.is with utf8esmtp (Exim 4.96) (envelope-from ) id 1wQAR5-00DeeU-0C; Thu, 21 May 2026 20:56:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkoc.com; i=@berkoc.com; q=dns/txt; s=me; t=1779396954; h=message-id : date : subject : cc : to : from : sender : reply-to; bh=yEgrKS1yuvRt1SapJoA7ktrpyTmlvnKNqxmZJDoUF6o=; b=i4ycK9WD+KWb16+raZso9u4MMcCvs/jsdjN1qG4kxsglffqRfD03u5Cz4RpFBWBOWOAhg epPcqmHwxwV6FpeMJEGE4reBDj/pjew8Mlqk/jTLjSEEOIeP3rnw055FJY1eKdFMVOk39XJ nOIhyZjyxr6yrrORELMfnAPB+jKEReWOrMv6hCJRHXKrGkbilmH/pGjJFmLFiMSnE6RIbq3 yWaN/vASXa8T+Vh2aYSpwnwgmQmoiYkEFG1NiAcxKRK0sSsdWDmC5GR4Dwy7jzlgbtq8HRS wxuM7l5xVeAnNWePXIK/a3nBwzAs137ML+uLI0kvUj8691Wm79VmmodnMsYA== Message-ID: <6945b22419c7d404b4954a113de2ac9c900dba93.1779396074.git.me@berkoc.com> In-Reply-To: References: 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 Date: Tue, 19 May 2026 22:08:17 +0200 Subject: [PATCH v4 1/2] drm/hyperv: validate resolution_count and fix WIN8 fallback X-Spam-Score: -0.2 (/) X-Authenticated-User: me@berkoc.com X-Sender-Address: me@berkoc.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A SYNTHVID_RESOLUTION_RESPONSE with resolution_count > 64 walks past the supported_resolution[SYNTHVID_MAX_RESOLUTION_COUNT] array in the parse loop. Bound resolution_count against the array size, folded into the existing zero-check. When the WIN10 resolution probe fails, the caller in hyperv_connect_vsp() left hv->screen_*_max / preferred_* unpopulated, which sets mode_config.max_width / max_height to 0 and makes drm_internal_framebuffer_create() reject every userspace framebuffer with -EINVAL. The pre-WIN10 branch had the same gap for preferred_width / preferred_height. Use a single post-probe fallback guarded by screen_width_max =3D=3D 0 so both paths converge on the WIN8 defaults. Signed-off-by: Berkant Koc Assisted-by: Claude:claude-opus-4-7 berkoc-pipeline Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video= device") Cc: stable@vger.kernel.org # 5.14+ Reviewed-by: Michael Kelley --- drivers/gpu/drm/hyperv/hyperv_drm_proto.c | 13 ++++++++++--- 1 file changed, 10 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 051ecc526..c3d0ff229 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_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 @@ -508,9 +511,13 @@ int hyperv_connect_vsp(struct hv_device *hdev) ret =3D hyperv_get_supported_resolution(hdev); if (ret) drm_err(dev, "Failed to get supported resolution from host, use default= \n"); - } else { + } + + if (!hv->screen_width_max) { 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; } =20 hv->mmio_megabytes =3D hdev->channel->offermsg.offer.mmio_megabytes; --=20 2.47.3 From nobody Sun May 24 20:33:10 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 5FC7636CDE0; Thu, 21 May 2026 20:56:35 +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=1779396997; cv=none; b=L7+ra3jy7G+xL1zsm9dXcg3DOGc6As8ioSDewCMv09JxigTpxRai6ciSDCRwFYp8sZD+4j8s+F8LhLXqRCVOcmFmOp7/y/NiKiFuIq2gPaW1G/1HRS2CxAowpvvRNnWKKFzTlCfIwnAHPFTBD/J/3ZcO0/yCxxI/pwn295GNjUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779396997; c=relaxed/simple; bh=P6NHnSBS7A5nCK7EBrwNsszRWgG5h0L9aT882bgvnGI=; h=Message-ID:In-Reply-To:References:From:To:Cc:Date:Subject; b=PzStq6m3L50GHIknmywAV/cqP6Xwzo4SWHEkQMJbskk/9dFhpqT1X8rgYhLjeIkHxQgtzWdjm+eaDCisMHTCNK+KFuUU9yxDQeXEK/mQw9rr4orUd9ldo/cwwxKz8pKSnaDO7z77UiO/aeAXh4CBeo9vkudESpH+xeZcih1YLlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=B1OLPmwh; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b=d1hyWEgK; arc=none smtp.client-ip=185.112.145.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="B1OLPmwh"; dkim=pass (2048-bit key) header.d=berkoc.com header.i=@berkoc.com header.b="d1hyWEgK" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=berkoc.com; s=1984; h=Subject:Date:Cc:To:From:References:In-Reply-To:Message-ID:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: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=IwxizOZe2KuLhYlTxGDJy2jH2w3o7dBZIW4lsDZsoTg=; b=B1OLPmwhXKjq85FtxUHJcdH6Vf EW9dQqZkqhW1+QbS3DF5HdUEeNSKr6kyp+xTMRhD8/D125gA8SOy36A9x2i7Anfhi40dF7G9/x8gV 8pXITHzjRyb8kO3iY4xzV1SNykVYk4oO732p2B9EJNRc8sPxgXSY7Kr78NrdGD2577fFzmYl47FeH LJ9nXOgTkdoaKu/lpatf4j8J3hI4+uoLBHrSkPKg2HEzUdnEXYjDKxgaX2q+xJABdBdswmtz4IQah 7mK877oq+N196m6Mu1hUgGb3ZY+dBaHFR5cD24KgrD0nd9qnOSfri2EzymWeDlKlOFGM01YCxCNiI Ei3IBcvg==; Received: from localhost by mail-01.1984.is with utf8esmtp (Exim 4.96) (envelope-from ) id 1wQART-00DejJ-0h; Thu, 21 May 2026 20:56:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkoc.com; i=@berkoc.com; q=dns/txt; s=me; t=1779396980; h=message-id : date : subject : cc : to : from : sender : reply-to; bh=IwxizOZe2KuLhYlTxGDJy2jH2w3o7dBZIW4lsDZsoTg=; b=d1hyWEgKkxROdKjkzMI4lbAsEGVG4crHSbzmk/coBsotlt5JWglMQ6viwp/71/S3IN/t0 H1Cv7l1jJPVVLxArwN0/Yi4Ov7oiTeralv8jYOf99I9H9XnivsycSabFq3Nd03lzaLk+AJ2 Z2HOwWu027Cj/yF/gRx8TxFkrtzEcwEDyx5ibAlYeQWkx4A0nfKHlcfbZVH0WHQnfKZ32Pl 5I+PLnlWia7soGG2KnQuu19X+JlB/dYxxda4mZWSBFpkocPLWi21s3DzSrk/Y7TRuaaJDAH gNOzraUKUK0c0+6qtEZ7p7k6W2BjJhP0OhsKaJePBg/HfY9Ew2FFJyhg+knA== Message-ID: <6e5d1d57a3afc4c5ea0d2a3d62be58c90741a869.1779396074.git.me@berkoc.com> In-Reply-To: References: 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 Date: Tue, 19 May 2026 22:08:53 +0200 Subject: [PATCH v4 2/2] drm/hyperv: validate VMBus packet size in receive callback X-Spam-Score: -0.2 (/) X-Authenticated-User: me@berkoc.com X-Sender-Address: me@berkoc.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" hyperv_receive_sub() reads msg->vid_hdr.type and dispatches into one of four message-type branches without knowing how many bytes the host wrote into hv->recv_buf. The completion path then runs memcpy(hv->init_buf, msg, VMBUS_MAX_PACKET_SIZE), so the consumer that wakes on wait_for_completion_timeout() can read up to 16 KiB of residue from a prior message as if it were the response payload. Pass bytes_recvd into hyperv_receive_sub() and reject any packet that does not cover the pipe + synthvid header. For the three completion-driving types (SYNTHVID_VERSION_RESPONSE, SYNTHVID_RESOLUTION_RESPONSE, SYNTHVID_VRAM_LOCATION_ACK) require the type-specific payload before memcpy/complete, and apply the same rule to SYNTHVID_FEATURE_CHANGE before reading is_dirt_needed. SYNTHVID_RESOLUTION_RESPONSE is variable length: the host fills resolution_count entries, not the full SYNTHVID_MAX_RESOLUTION_COUNT array. Validate the fixed prefix first so resolution_count can be read, bound it against the array, then require only the count-sized array, so the shorter responses the host actually sends are accepted. Only run the sub-handler when vmbus_recvpacket() returned success. The memcpy length is bytes_recvd, which is bounded by VMBUS_MAX_PACKET_SIZE only on a successful receive; on -ENOBUFS vmbus_recvpacket() instead reports the required length, which can exceed hv->recv_buf, so copying bytes_recvd would read and write past the 16 KiB buffers. Gating on the success return keeps the copy bounded. Rejected packets are reported via drm_err_ratelimited() rather than silently dropped, matching the CoCo-hardened pattern in hv_kvp_onchannelcallback(). Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video= device") Cc: stable@vger.kernel.org # 5.14+ Signed-off-by: Berkant Koc Assisted-by: Claude:claude-opus-4-7 berkoc-pipeline --- drivers/gpu/drm/hyperv/hyperv_drm_proto.c | 63 +++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c b/drivers/gpu/drm/hy= perv/hyperv_drm_proto.c index c3d0ff229..48054b607 100644 --- a/drivers/gpu/drm/hyperv/hyperv_drm_proto.c +++ b/drivers/gpu/drm/hyperv/hyperv_drm_proto.c @@ -420,26 +420,81 @@ 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) { + drm_err_ratelimited(&hv->dev, + "synthvid packet too small for header: %u\n", + bytes_recvd); + 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); + size_t need =3D hdr_size; + + switch (msg->vid_hdr.type) { + case SYNTHVID_VERSION_RESPONSE: + need +=3D sizeof(struct synthvid_version_resp); + break; + case SYNTHVID_RESOLUTION_RESPONSE: + /* + * The resolution response is variable length: the host + * fills resolution_count entries, not the full + * SYNTHVID_MAX_RESOLUTION_COUNT array. Require the fixed + * prefix first so resolution_count can be read, then + * demand exactly the count-sized array. + */ + need +=3D offsetof(struct synthvid_supported_resolution_resp, + supported_resolution); + if (bytes_recvd < need) + break; + if (msg->resolution_resp.resolution_count > + SYNTHVID_MAX_RESOLUTION_COUNT) { + drm_err_ratelimited(&hv->dev, + "synthvid resolution count too large: %u\n", + msg->resolution_resp.resolution_count); + return; + } + need +=3D msg->resolution_resp.resolution_count * + sizeof(struct hvd_screen_info); + break; + case SYNTHVID_VRAM_LOCATION_ACK: + need +=3D sizeof(struct synthvid_vram_location_ack); + break; + } + if (bytes_recvd < need) { + drm_err_ratelimited(&hv->dev, + "synthvid packet too small for type %u: %u < %zu\n", + msg->vid_hdr.type, bytes_recvd, need); + return; + } + 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)) { + drm_err_ratelimited(&hv->dev, + "synthvid feature change packet too small: %u\n", + bytes_recvd); + return; + } hv->dirt_needed =3D msg->feature_chg.is_dirt_needed; if (hv->dirt_needed) hyperv_hide_hw_ptr(hv->hdev); @@ -464,9 +519,9 @@ static void hyperv_receive(void *ctx) ret =3D vmbus_recvpacket(hdev->channel, recv_buf, VMBUS_MAX_PACKET_SIZE, &bytes_recvd, &req_id); - if (bytes_recvd > 0 && + if (!ret && 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