Skip to content

Commit dda7e89

Browse files
matnymangregkh
authored andcommitted
xhci: Fix root hub port null pointer dereference in xhci tracepoints
The pointer from a xhci usb virt device to its root hub port (vdev->rhub_port) is set later when device is addressed, not while vdev is allocated. Tracepoints dereferenced this rhub_port pointer when freeing the virt device, which causes null pointer dereference if tracing is enabled and device is freed before addressed. This can happen if tracing is enabled and xhci driver is unloaded before a device is fully enumerated, or initial enumeration fails and device is reset and freed before retry. Don't dereference the rhub_port or show port numbers when tracing xhci_free_virt_device(). This info is not very useful anyway. Print the more useful slot id instead Fixes: 06790c1 ("xhci: replace real & fake port with pointer to root hub port") Reported-by: Thinh Nguyen <[email protected]> Closes: https://lore.kernel.org/linux-usb/[email protected]/ Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5bfc311 commit dda7e89

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

drivers/usb/host/xhci-trace.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,20 @@ DECLARE_EVENT_CLASS(xhci_log_free_virt_dev,
172172
__field(void *, vdev)
173173
__field(unsigned long long, out_ctx)
174174
__field(unsigned long long, in_ctx)
175-
__field(int, hcd_portnum)
176-
__field(int, hw_portnum)
175+
__field(int, slot_id)
177176
__field(u16, current_mel)
178177

179178
),
180179
TP_fast_assign(
181180
__entry->vdev = vdev;
182181
__entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
183182
__entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
184-
__entry->hcd_portnum = (int) vdev->rhub_port->hcd_portnum;
185-
__entry->hw_portnum = (int) vdev->rhub_port->hw_portnum;
183+
__entry->slot_id = (int) vdev->slot_id;
186184
__entry->current_mel = (u16) vdev->current_mel;
187185
),
188-
TP_printk("vdev %p ctx %llx | %llx hcd_portnum %d hw_portnum %d current_mel %d",
189-
__entry->vdev, __entry->in_ctx, __entry->out_ctx,
190-
__entry->hcd_portnum, __entry->hw_portnum, __entry->current_mel
186+
TP_printk("vdev %p slot %d ctx %llx | %llx current_mel %d",
187+
__entry->vdev, __entry->slot_id, __entry->in_ctx,
188+
__entry->out_ctx, __entry->current_mel
191189
)
192190
);
193191

0 commit comments

Comments
 (0)