Skip to content

Commit af4db5a

Browse files
RD Babieragregkh
authored andcommitted
usb: typec: altmodes/displayport: do not index invalid pin_assignments
A poorly implemented DisplayPort Alt Mode port partner can indicate that its pin assignment capabilities are greater than the maximum value, DP_PIN_ASSIGN_F. In this case, calls to pin_assignment_show will cause a BRK exception due to an out of bounds array access. Prevent for loop in pin_assignment_show from accessing invalid values in pin_assignments by adding DP_PIN_ASSIGN_MAX value in typec_dp.h and using i < DP_PIN_ASSIGN_MAX as a loop condition. Fixes: 0e3bb7d ("usb: typec: Add driver for DisplayPort alternate mode") Cc: stable <[email protected]> Signed-off-by: RD Babiera <[email protected]> Reviewed-by: Badhri Jagan Sridharan <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2831a81 commit af4db5a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

drivers/usb/typec/altmodes/displayport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static ssize_t pin_assignment_show(struct device *dev,
677677

678678
assignments = get_current_pin_assignments(dp);
679679

680-
for (i = 0; assignments; assignments >>= 1, i++) {
680+
for (i = 0; assignments && i < DP_PIN_ASSIGN_MAX; assignments >>= 1, i++) {
681681
if (assignments & 1) {
682682
if (i == cur)
683683
len += sprintf(buf + len, "[%s] ",

include/linux/usb/typec_dp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum {
5757
DP_PIN_ASSIGN_D,
5858
DP_PIN_ASSIGN_E,
5959
DP_PIN_ASSIGN_F, /* Not supported after v1.0b */
60+
DP_PIN_ASSIGN_MAX,
6061
};
6162

6263
/* DisplayPort alt mode specific commands */

0 commit comments

Comments
 (0)