Skip to content

Commit ef0dbcc

Browse files
geeky-ashugregkh
authored andcommitted
drm/dp/mst: fix buffer overflows in sideband chunk accumulation
commit 55bd5e6 upstream. drm_dp_sideband_append_payload() has three related bugs when processing device-provided sideband reply data: 1. Zero-length curchunk_len underflow: msg_len is a 6-bit field taken directly from the DP sideband header. If a device sends msg_len=0, curchunk_len is set to zero. The condition (curchunk_idx >= curchunk_len) is immediately true, and curchunk_len-1 wraps to 255 (u8 underflow). drm_dp_msg_data_crc4() reads 255 bytes from chunk[48], then memcpy() writes 255 bytes into msg[], both far out of bounds. 2. chunk[48] overflow: curchunk_len can reach 63 (6-bit field). chunk[] is only 48 bytes. Multi-iteration payload assembly appends 16-byte blocks until curchunk_idx reaches curchunk_len, writing up to 15 bytes past the end of chunk[] into msg[]. 3. msg[256] overflow: each chunk contributes (curchunk_len-1) bytes to msg[]. No check ensures curlen + (curchunk_len-1) stays within msg[256], so the memcpy can spill into adjacent struct fields. All three are reachable from any DP MST device that can forge sideband reply messages on a physical connection. Fixes: ad7f8a1 ("drm/helper: add Displayport multi-stream helper (v0.6)") Cc: <stable@vger.kernel.org> # v3.17+ Signed-off-by: Ashutosh Desai <ashutoshdesai993@gmail.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Lyude Paul <lyude@redhat.com> Link: https://patch.msgid.link/20260410041901.2438960-1-ashutoshdesai993@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 04d953f commit ef0dbcc

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/gpu/drm/display/drm_dp_mst_topology.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ static bool drm_dp_sideband_append_payload(struct drm_dp_sideband_msg_rx *msg,
780780
{
781781
u8 crc4;
782782

783+
/* curchunk_len must be >= 1 (min 1 CRC byte) and fit in chunk[] */
784+
if (!msg->curchunk_len ||
785+
msg->curchunk_len > ARRAY_SIZE(msg->chunk) ||
786+
msg->curchunk_idx + replybuflen > ARRAY_SIZE(msg->chunk))
787+
return false;
788+
783789
memcpy(&msg->chunk[msg->curchunk_idx], replybuf, replybuflen);
784790
msg->curchunk_idx += replybuflen;
785791

@@ -790,6 +796,9 @@ static bool drm_dp_sideband_append_payload(struct drm_dp_sideband_msg_rx *msg,
790796
print_hex_dump(KERN_DEBUG, "wrong crc",
791797
DUMP_PREFIX_NONE, 16, 1,
792798
msg->chunk, msg->curchunk_len, false);
799+
/* Guard against accumulated msg[] overflow */
800+
if (msg->curlen + msg->curchunk_len - 1 > ARRAY_SIZE(msg->msg))
801+
return false;
793802
/* copy chunk into bigger msg */
794803
memcpy(&msg->msg[msg->curlen], msg->chunk, msg->curchunk_len - 1);
795804
msg->curlen += msg->curchunk_len - 1;

0 commit comments

Comments
 (0)