thunderbolt: Validate DP bandwidth notification port
Subsystems (2)
PATCH v2 1/1 thunderbolt: Validate DP bandwidth notification port
The port number in a DP bandwidth notification is six bits wide and comes from the router. A router whose maximum port number is smaller can therefore make tb_handle_dp_bandwidth_request() index beyond the max_port_number + 1 entries allocated for sw->ports. The first tb_port_is_dpin() check then reads the out-of-bounds object.
Add a common helper that warns and rejects out-of-range port numbers, and use it before dereferencing the notification port.
---
Changes in v2:
- Add tb_switch_port() and use it for both tb_port_at() and the DP bandwidth notification lookup, as requested by Mika.
- Submit the DP bandwidth fix alone; the path-discovery change is not included.
drivers/thunderbolt/tb.c | 4 +++- drivers/thunderbolt/tb.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/thunderbolt/tb.c +3 -1
@@ -2756,7 +2756,9 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) goto unlock; } - in = &sw->ports[ev->port]; + in =tb_switch_port (sw, ev->port); +if (!in) + goto put_sw;if (!tb_port_is_dpin (in)) {tb_port_warn (in,"bandwidth request to non-DP IN adapter\n" ); goto put_sw;
drivers/thunderbolt/tb.h +8 -3
@@ -585,14 +585,19 @@ static inline u64 tb_route(const struct tb_switch *sw)return ((u64 ) sw->config.route_hi) <<32 | sw->config.route_lo; } +static inline struct tb_port *tb_switch_port (struct tb_switch *sw,u8 port) +{ +if (WARN_ON (port > sw->config.max_port_number)) +return NULL ; +return &sw->ports[port]; +} +static inline struct tb_port *tb_port_at (u64 route,struct tb_switch *sw) {u8 port; port = route >> (sw->config.depth *8 ); -if (WARN_ON (port > sw->config.max_port_number)) -return NULL ; -return &sw->ports[port]; +return tb_switch_port (sw, port); }static inline const char *tb_width_name (enum tb_link_width width)
base-commit: 50d05c7c76c96b90462f24debacca971d2e86713
Signature · 1 line
2.55.0
Hi,
Quoted 11 lines · Daehyeon Ko
The port number in a DP bandwidth notification is six bits wide and comes from the router. A router whose maximum port number is smaller can therefore make
tb_handle_dp_bandwidth_request()index beyond themax_port_number+ 1 entries allocated forsw->ports. The firsttb_port_is_dpin()check then reads the out-of-bounds object.Add a common helper that warns and rejects out-of-range port numbers, and use it before dereferencing the notification port.
Fixes 6ce3563520be ("thunderbolt: Add support for DisplayPort bandwidth allocation mode")
Instead of fixes I think this one should be going in as improvement. At the moment there are no known device routers with DP IN so it's only hosts and we trust them.
Quoted 18 lines
Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>---
Changes in v2:
- Addtb_switch_port()and use it for bothtb_port_at()and the DP bandwidth notification lookup, as requested by Mika.
- Submit the DP bandwidth fix alone; the path-discovery change is not included.drivers/thunderbolt/tb.c | 4 +++- drivers/thunderbolt/tb.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)drivers/thunderbolt/tb.c +0
-0
drivers/thunderbolt/tb.c static void tb_handle_dp_bandwidth_request(struct work_struct *work) · line 2761
Quoted 7 lines
drivers/thunderbolt/tb.c +3
-1@@ -2756,7 +2756,9 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) goto unlock; } - in = &sw->ports[ev->port]; + in =tb_switch_port (sw, ev->port); +if (!in) + goto put_sw;
Can you also replace the code in tb_handle_hotplug() with this?
Quoted 8 lines
drivers/thunderbolt/tb.c +0
-0if (!tb_port_is_dpin (in)) {tb_port_warn (in,"bandwidth request to non-DP IN adapter\n" ); goto put_sw;drivers/thunderbolt/tb.h +0
-0
drivers/thunderbolt/tb.h static inline u64 tb_route(const struct tb_switch *sw) · line 590
Quoted 6 lines
drivers/thunderbolt/tb.h +3
-0@@ -585,14 +585,19 @@ static inline u64 tb_route(const struct tb_switch *sw)return ((u64 ) sw->config.route_hi) <<32 | sw->config.route_lo; } +static inline struct tb_port *tb_switch_port (struct tb_switch *sw,u8 port) +{ +if (WARN_ON (port > sw->config.max_port_number))
Make this tb_sw_warn() instead.
Quoted 20 lines
drivers/thunderbolt/tb.h +5
-3+return NULL ; +return &sw->ports[port]; +} +static inline struct tb_port *tb_port_at (u64 route,struct tb_switch *sw) {u8 port; port = route >> (sw->config.depth *8 ); -if (WARN_ON (port > sw->config.max_port_number)) -return NULL ; -return &sw->ports[port]; +return tb_switch_port (sw, port); }static inline const char *tb_width_name (enum tb_link_width width)base-commit:
50d05c7c76c96b90462f24debacca971d2e86713Signature · 1 line
2.55.0