diff mbox series

drm/dp_mst: Fix MST sideband message body length check

Message ID 20241125205314.1725887-1-imre.deak@intel.com (mailing list archive)
State New
Headers show
Series drm/dp_mst: Fix MST sideband message body length check | expand

Commit Message

Imre Deak Nov. 25, 2024, 8:53 p.m. UTC
Fix the MST sideband message body length check, which must be at least 1
byte accounting for the message body CRC (aka message data CRC) at the
end of the message.

This fixes a case where an MST branch device returns a header with a
correct header CRC (indicating a correctly received body length), with
the body length being incorrectly set to 0. This will later lead to a
memory corruption in drm_dp_sideband_append_payload() and the following
errors in dmesg:

   UBSAN: array-index-out-of-bounds in drivers/gpu/drm/display/drm_dp_mst_topology.c:786:25
   index -1 is out of range for type 'u8 [48]'
   Call Trace:
    drm_dp_sideband_append_payload+0x33d/0x350 [drm_display_helper]
    drm_dp_get_one_sb_msg+0x3ce/0x5f0 [drm_display_helper]
    drm_dp_mst_hpd_irq_handle_event+0xc8/0x1580 [drm_display_helper]

   memcpy: detected field-spanning write (size 18446744073709551615) of single field "&msg->msg[msg->curlen]" at drivers/gpu/drm/display/drm_dp_mst_topology.c:791 (size 256)
   Call Trace:
    drm_dp_sideband_append_payload+0x324/0x350 [drm_display_helper]
    drm_dp_get_one_sb_msg+0x3ce/0x5f0 [drm_display_helper]
    drm_dp_mst_hpd_irq_handle_event+0xc8/0x1580 [drm_display_helper]

Cc: <stable@vger.kernel.org>
Cc: Lyude Paul <lyude@redhat.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 drivers/gpu/drm/display/drm_dp_mst_topology.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Lyude Paul Nov. 25, 2024, 8:54 p.m. UTC | #1
Reviewed-by: Lyude Paul <lyude@redhat.com>

On Mon, 2024-11-25 at 22:53 +0200, Imre Deak wrote:
> Fix the MST sideband message body length check, which must be at least 1
> byte accounting for the message body CRC (aka message data CRC) at the
> end of the message.
> 
> This fixes a case where an MST branch device returns a header with a
> correct header CRC (indicating a correctly received body length), with
> the body length being incorrectly set to 0. This will later lead to a
> memory corruption in drm_dp_sideband_append_payload() and the following
> errors in dmesg:
> 
>    UBSAN: array-index-out-of-bounds in drivers/gpu/drm/display/drm_dp_mst_topology.c:786:25
>    index -1 is out of range for type 'u8 [48]'
>    Call Trace:
>     drm_dp_sideband_append_payload+0x33d/0x350 [drm_display_helper]
>     drm_dp_get_one_sb_msg+0x3ce/0x5f0 [drm_display_helper]
>     drm_dp_mst_hpd_irq_handle_event+0xc8/0x1580 [drm_display_helper]
> 
>    memcpy: detected field-spanning write (size 18446744073709551615) of single field "&msg->msg[msg->curlen]" at drivers/gpu/drm/display/drm_dp_mst_topology.c:791 (size 256)
>    Call Trace:
>     drm_dp_sideband_append_payload+0x324/0x350 [drm_display_helper]
>     drm_dp_get_one_sb_msg+0x3ce/0x5f0 [drm_display_helper]
>     drm_dp_mst_hpd_irq_handle_event+0xc8/0x1580 [drm_display_helper]
> 
> Cc: <stable@vger.kernel.org>
> Cc: Lyude Paul <lyude@redhat.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  drivers/gpu/drm/display/drm_dp_mst_topology.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c b/drivers/gpu/drm/display/drm_dp_mst_topology.c
> index ac90118b9e7a8..e6ee180815b20 100644
> --- a/drivers/gpu/drm/display/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c
> @@ -320,6 +320,9 @@ static bool drm_dp_decode_sideband_msg_hdr(const struct drm_dp_mst_topology_mgr
>  	hdr->broadcast = (buf[idx] >> 7) & 0x1;
>  	hdr->path_msg = (buf[idx] >> 6) & 0x1;
>  	hdr->msg_len = buf[idx] & 0x3f;
> +	if (hdr->msg_len < 1)		/* min space for body CRC */
> +		return false;
> +
>  	idx++;
>  	hdr->somt = (buf[idx] >> 7) & 0x1;
>  	hdr->eomt = (buf[idx] >> 6) & 0x1;
diff mbox series

Patch

diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c b/drivers/gpu/drm/display/drm_dp_mst_topology.c
index ac90118b9e7a8..e6ee180815b20 100644
--- a/drivers/gpu/drm/display/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c
@@ -320,6 +320,9 @@  static bool drm_dp_decode_sideband_msg_hdr(const struct drm_dp_mst_topology_mgr
 	hdr->broadcast = (buf[idx] >> 7) & 0x1;
 	hdr->path_msg = (buf[idx] >> 6) & 0x1;
 	hdr->msg_len = buf[idx] & 0x3f;
+	if (hdr->msg_len < 1)		/* min space for body CRC */
+		return false;
+
 	idx++;
 	hdr->somt = (buf[idx] >> 7) & 0x1;
 	hdr->eomt = (buf[idx] >> 6) & 0x1;