drm/dp/mst: fix OOB reads in remote DPCD/I2C sideband reply parsers
Subsystems (3)
PATCH 1/1 drm/dp/mst: fix OOB reads in remote DPCD/I2C sideband reply parsers
drm_dp_sideband_parse_remote_dpcd_read() reads num_bytes from the raw message and then unconditionally does:
memcpy(bytes, &raw->msg[idx], num_bytes);
without checking that idx + num_bytes <= raw->curlen. raw->msg[] is 256 bytes; if a malicious or misbehaving MST hub sets num_bytes larger than the remaining payload, the memcpy reads past the received data into whatever follows in raw->msg[].
drm_dp_sideband_parse_remote_i2c_read_ack() has the same flaw and also lacked the post-increment idx bounds check (noted with a /* TODO check */ comment since the code was introduced).
Add the missing bounds checks in both functions, consistent with the pattern used throughout the rest of the sideband parser.
--- drivers/gpu/drm/display/drm_dp_mst_topology.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_dp_mst_topology.c +7 -1
@@ -873,6 +873,8 @@ static bool drm_dp_sideband_parse_remote_dpcd_read(struct drm_dp_sideband_msg_rx idx++;if (idx > raw->curlen) goto fail_len; +if (idx + repmsg->u.remote_dpcd_read_ack.num_bytes > raw->curlen) + goto fail_len;memcpy (repmsg->u.remote_dpcd_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_dpcd_read_ack.num_bytes);return true;
@@ -907,7 +909,11 @@ static bool drm_dp_sideband_parse_remote_i2c_read_ack(struct drm_dp_sideband_msg goto fail_len; repmsg->u.remote_i2c_read_ack.num_bytes = raw->msg[idx]; idx++; -/* TODO check */ +if (idx > raw->curlen) + goto fail_len; +if (idx + repmsg->u.remote_i2c_read_ack.num_bytes > raw->curlen) + goto fail_len; +memcpy (repmsg->u.remote_i2c_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_i2c_read_ack.num_bytes);return true; fail_len:
Signature · 1 line
2.34.1
Hi,
Just a gentle ping on this patch from a few weeks ago - no rush at all.
https://lore.kernel.org/dri-devel/[email protected]/
Happy to revise anything if needed. Thanks!
Ashutosh
Hi - one comment down below:
Quoted 37 lines · Ashutosh Desai
drm_dp_sideband_parse_remote_dpcd_read()readsnum_bytesfrom the raw message and then unconditionally does:
memcpy(bytes, &raw->msg[idx], num_bytes);without checking that idx +
num_bytes<= raw->curlen. raw->msg[] is 256 bytes; if a malicious or misbehaving MST hub setsnum_byteslarger
than the remaining payload, the memcpy reads past the received data into whatever follows in raw->msg[].
drm_dp_sideband_parse_remote_i2c_read_ack()has the same flaw and also
lacked the post-increment idx bounds check (noted with a /* TODO check */
comment since the code was introduced).Add the missing bounds checks in both functions, consistent with the pattern used throughout the rest of the sideband parser.
Signed-off-by Ashutosh Desai <[email protected]>---
drivers/gpu/drm/display/drm_dp_mst_topology.c | 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -873,6 +873,8 @@ static booldrm_dp_sideband_parse_remote_dpcd_read(struct
drm_dp_sideband_msg_rxidx++;
if (idx >raw->curlen)
gotofail_len;drivers/gpu/drm/display/drm_dp_mst_topology.c +1
-0+ if (idx + repmsg->u.remote_dpcd_read_ack.num_bytes > raw-Quoted 1 line
curlen)
drivers/gpu/drm/display/drm_dp_mst_topology.c
Quoted 1 line
drivers/gpu/drm/display/drm_dp_mst_topology.c +1
-0+ goto fail_len;
Do we need both checks here? It seems like we could just replace the first check with the second check.
Quoted 14 lines
memcpy(repmsg->u.remote_dpcd_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_dpcd_read_ack.num_bytes);
return true;drivers/gpu/drm/display/drm_dp_mst_topology.c +0
-0@@ -907,7 +909,11 @@ static booldrm_dp_sideband_parse_remote_i2c_read_ack(struct
drm_dp_sideband_msggotofail_len;repmsg->u.remote_i2c_read_ack.num_bytes= raw->msg[idx]; idx++;drivers/gpu/drm/display/drm_dp_mst_topology.c +3
-1-/* TODO check */ +if (idx > raw->curlen) + goto fail_len; + if (idx + repmsg->u.remote_i2c_read_ack.num_bytes > raw-Quoted 1 line
curlen)
drivers/gpu/drm/display/drm_dp_mst_topology.c
Quoted 1 line
drivers/gpu/drm/display/drm_dp_mst_topology.c +1
-0+ goto fail_len;
Same here
Quoted 5 lines
+
memcpy(repmsg->u.remote_i2c_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_i2c_read_ack.num_bytes);
return true;
fail_len: