• Alexander Kappner's avatar
    xhci: Fix use-after-free in xhci debugfs · dde63405
    Alexander Kappner authored
    Trying to read from debugfs after the system has resumed from
    hibernate causes a use-after-free and thus a protection fault.
    
    Steps to reproduce:
    Hibernate system, resume from hibernate, then run
    $ cat /sys/kernel/debug/usb/xhci/*/command-ring/enqueue
    
    [ 3902.765086] general protection fault: 0000 [#1] PREEMPT SMP
    ...
    [ 3902.765136] RIP: 0010:xhci_trb_virt_to_dma.part.50+0x5/0x30
    ...
    [ 3902.765178] Call Trace:
    [ 3902.765188]  xhci_ring_enqueue_show+0x1e/0x40
    [ 3902.765197]  seq_read+0xdb/0x3a0
    [ 3902.765204]  ? __handle_mm_fault+0x5fb/0x1210
    [ 3902.765211]  full_proxy_read+0x4a/0x70
    [ 3902.765219]  __vfs_read+0x23/0x120
    [ 3902.765228]  vfs_read+0x8e/0x130
    [ 3902.765235]  SyS_read+0x42/0x90
    [ 3902.765242]  do_syscall_64+0x6b/0x290
    [ 3902.765251]  entry_SYSCALL64_slow_path+0x25/0x25
    
    The issue is caused by the xhci ring structures being reallocated
    when the system is resumed, but pointers to the old structures
    being retained in the debugfs files "private" field:
    
    The proposed patch fixes this issue by storing a pointer to the xhci_ring
    field in the xhci device structure in debugfs rather than directly
    storing a pointer to the xhci_ring.
    
    Fixes: 02b6fdc2 ("usb: xhci: Add debugfs interface for xHCI driver")
    Signed-off-by: default avatarAlexander Kappner <agk@godking.net>
    Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    dde63405
xhci-debugfs.c 12.7 KB