Skip to content

Commit 0bcd767

Browse files
geeky-ashugregkh
authored andcommitted
drm/dp/mst: fix OOB reads on 2-byte fields in sideband reply parsers
commit 6b89ba3 upstream. Three sideband reply parsers read 16-bit fields as: val = (raw->msg[idx] << 8) | (raw->msg[idx+1]); and check bounds only after the fact. When idx == raw->curlen, raw->msg[idx+1] reads one byte past the received message data into the following struct fields (curchunk_len, curchunk_idx, curlen). Affected functions: - drm_dp_sideband_parse_enum_path_resources_ack() full_payload_bw_number and avail_payload_bw_number fields - drm_dp_sideband_parse_allocate_payload_ack() allocated_pbn field - drm_dp_sideband_parse_query_payload_ack() allocated_pbn field Fix by using a single combined check (idx + 2 > curlen) before each 2-byte read. Since the check is strictly tighter than idx > curlen, no separate step is needed. 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> [added fixes tag] Signed-off-by: Lyude Paul <lyude@redhat.com> Link: https://patch.msgid.link/20260510203128.2884846-1-ashutoshdesai993@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 15a9863 commit 0bcd767

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

drivers/gpu/drm/display/drm_dp_mst_topology.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -925,16 +925,13 @@ static bool drm_dp_sideband_parse_enum_path_resources_ack(struct drm_dp_sideband
925925
repmsg->u.path_resources.port_number = (raw->msg[idx] >> 4) & 0xf;
926926
repmsg->u.path_resources.fec_capable = raw->msg[idx] & 0x1;
927927
idx++;
928-
if (idx > raw->curlen)
928+
if (idx + 2 > raw->curlen)
929929
goto fail_len;
930930
repmsg->u.path_resources.full_payload_bw_number = (raw->msg[idx] << 8) | (raw->msg[idx+1]);
931931
idx += 2;
932-
if (idx > raw->curlen)
932+
if (idx + 2 > raw->curlen)
933933
goto fail_len;
934934
repmsg->u.path_resources.avail_payload_bw_number = (raw->msg[idx] << 8) | (raw->msg[idx+1]);
935-
idx += 2;
936-
if (idx > raw->curlen)
937-
goto fail_len;
938935
return true;
939936
fail_len:
940937
DRM_DEBUG_KMS("enum resource parse length fail %d %d\n", idx, raw->curlen);
@@ -952,12 +949,9 @@ static bool drm_dp_sideband_parse_allocate_payload_ack(struct drm_dp_sideband_ms
952949
goto fail_len;
953950
repmsg->u.allocate_payload.vcpi = raw->msg[idx];
954951
idx++;
955-
if (idx > raw->curlen)
952+
if (idx + 2 > raw->curlen)
956953
goto fail_len;
957954
repmsg->u.allocate_payload.allocated_pbn = (raw->msg[idx] << 8) | (raw->msg[idx+1]);
958-
idx += 2;
959-
if (idx > raw->curlen)
960-
goto fail_len;
961955
return true;
962956
fail_len:
963957
DRM_DEBUG_KMS("allocate payload parse length fail %d %d\n", idx, raw->curlen);
@@ -971,12 +965,9 @@ static bool drm_dp_sideband_parse_query_payload_ack(struct drm_dp_sideband_msg_r
971965

972966
repmsg->u.query_payload.port_number = (raw->msg[idx] >> 4) & 0xf;
973967
idx++;
974-
if (idx > raw->curlen)
968+
if (idx + 2 > raw->curlen)
975969
goto fail_len;
976970
repmsg->u.query_payload.allocated_pbn = (raw->msg[idx] << 8) | (raw->msg[idx + 1]);
977-
idx += 2;
978-
if (idx > raw->curlen)
979-
goto fail_len;
980971
return true;
981972
fail_len:
982973
DRM_DEBUG_KMS("query payload parse length fail %d %d\n", idx, raw->curlen);

0 commit comments

Comments
 (0)