]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: typec: altmodes/displayport: do not index invalid pin_assignments
authorRD Babiera <rdbabiera@google.com>
Wed, 18 Jun 2025 22:49:42 +0000 (22:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:24:55 +0000 (18:24 +0200)
commit af4db5a35a4ef7a68046883bfd12468007db38f1 upstream.

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: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
Cc: stable <stable@kernel.org>
Signed-off-by: RD Babiera <rdbabiera@google.com>
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20250618224943.3263103-2-rdbabiera@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/altmodes/displayport.c
include/linux/usb/typec_dp.h

index 35d7a4d40d9a4f1055208c104e0d1496b0cd0d49..80407a4679fa354e33ff6ef240575a4e7a3b7ccd 100644 (file)
@@ -492,7 +492,7 @@ static ssize_t pin_assignment_show(struct device *dev,
 
        assignments = get_current_pin_assignments(dp);
 
-       for (i = 0; assignments; assignments >>= 1, i++) {
+       for (i = 0; assignments && i < DP_PIN_ASSIGN_MAX; assignments >>= 1, i++) {
                if (assignments & 1) {
                        if (i == cur)
                                len += sprintf(buf + len, "[%s] ",
index 296909ea04f26cc1b3ecce41eff99cf1fa71f6a0..afb73b3e0b80905c18db329179982996e56a8930 100644 (file)
@@ -56,6 +56,7 @@ enum {
        DP_PIN_ASSIGN_D,
        DP_PIN_ASSIGN_E,
        DP_PIN_ASSIGN_F, /* Not supported after v1.0b */
+       DP_PIN_ASSIGN_MAX,
 };
 
 /* DisplayPort alt mode specific commands */