Skip to content

Commit aca58ea

Browse files
committed
drm/bridge: ti-sn65dsi86: Never store more than msg->size bytes in AUX xfer
For aux reads, the value `msg->size` indicates the size of the buffer provided by `msg->buffer`. We should never in any circumstances write more bytes to the buffer since it may overflow the buffer. In the ti-sn65dsi86 driver there is one code path that reads the transfer length from hardware. Even though it's never been seen to be a problem, we should make extra sure that the hardware isn't increasing the length since doing so would cause us to overrun the buffer. Fixes: 982f589 ("drm/bridge: ti-sn65dsi86: Update reply on aux failures") Reviewed-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Douglas Anderson <dianders@chromium.org> Link: https://patchwork.freedesktop.org/patch/msgid/20231214123752.v3.2.I7b83c0f31aeedc6b1dc98c7c741d3e1f94f040f8@changeid
1 parent 3164c8a commit aca58ea

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/gpu/drm/bridge/ti-sn65dsi86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux,
527527
u32 request_val = AUX_CMD_REQ(msg->request);
528528
u8 *buf = msg->buffer;
529529
unsigned int len = msg->size;
530+
unsigned int short_len;
530531
unsigned int val;
531532
int ret;
532533
u8 addr_len[SN_AUX_LENGTH_REG + 1 - SN_AUX_ADDR_19_16_REG];
@@ -600,7 +601,8 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux,
600601
}
601602

602603
if (val & AUX_IRQ_STATUS_AUX_SHORT) {
603-
ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &len);
604+
ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &short_len);
605+
len = min(len, short_len);
604606
if (ret)
605607
goto exit;
606608
} else if (val & AUX_IRQ_STATUS_NAT_I2C_FAIL) {

0 commit comments

Comments
 (0)