From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752029AbcEQVwx (ORCPT ); Tue, 17 May 2016 17:52:53 -0400 Received: from outbound.smtp.vt.edu ([198.82.183.121]:51841 "EHLO omr2.cc.vt.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751120AbcEQVwv (ORCPT ); Tue, 17 May 2016 17:52:51 -0400 X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6+dev To: Alan Stern , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: UBSAN whinge in ihci-hub.c From: Valdis Kletnieks Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==_Exmh_1463521960_1953P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Date: Tue, 17 May 2016 17:52:40 -0400 Message-ID: <5739.1463521960@turing-police.cc.vt.edu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --==_Exmh_1463521960_1953P Content-Type: text/plain; charset=us-ascii So, not content in the amount of breakage I generate already, I compiled with UBSAN enabled... The immediately relevant part: [ 2.418576] ================================================================================ [ 2.418579] UBSAN: Undefined behaviour in drivers/usb/host/ehci-hub.c:877:47 [ 2.418582] index -1 is out of range for type 'u32 [1]' The code there: 875 u32 __iomem *status_reg = &ehci->regs->port_status[ 876 (wIndex & 0xff) - 1]; 877 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1]; 878 u32 temp, temp1, status; I'm guessing that the only reason that port_status[] didn't throw an error because that's declared as 'u32 port_status[0]' with a 'u32 reserved3[9]' behind it, while it's 'u32 hostpc[1]'. So we have (possibly) 2 bugs: 1) hostpc should possibly be a 'u32 hostpc[0]' I'd attach a patch, except I'm low on caffeine and unsure if the 'u32 reserved5[16]' that follows needs to be a [17] to compensate. Either that, or port_status[] and hostpc[] should *both* be explicitly sized so range-checking works better. 2) We need to figure out who passed a 0 wIndex down the stack, resulting in the busted indexing... The entire splat: [ 2.418567] hub 1-0:1.0: USB hub found [ 2.418576] ================================================================================ [ 2.418579] UBSAN: Undefined behaviour in drivers/usb/host/ehci-hub.c:877:47 [ 2.418582] index -1 is out of range for type 'u32 [1]' [ 2.418587] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.6.0-next-20160517-00001-gede618fce89c-dirty #279 [ 2.418590] Hardware name: Dell Inc. Latitude E6530/07Y85M, BIOS A17 08/19/2015 [ 2.418599] 0000000000000000 00000000ac1ab326 ffff88022ca232e8 ffffffffaa690aea [ 2.418605] ffff88022ca23300 00000000ac1ab326 ffff88022ca23310 ffffffffffffffff [ 2.418613] ffff88022ca23300 ffffffffaa7087ad ffffffffabd5aee0 ffff88022ca23358 [ 2.418615] Call Trace: [ 2.418628] [] dump_stack+0x7b/0xd1 [ 2.418633] [] ubsan_epilogue+0xd/0x40 [ 2.418639] [] __ubsan_handle_out_of_bounds+0x75/0xa0 [ 2.418644] [] ? syscall_slow_exit_work+0x1ed/0x310 [ 2.418649] [] ? usb_hcd_submit_urb+0x368/0xe00 [ 2.418655] [] ehci_hub_control+0xd9c/0xdc0 [ 2.418662] [] usb_hcd_submit_urb+0x8b1/0xe00 [ 2.418667] [] usb_submit_urb+0x2e1/0x8f0 [ 2.418672] [] ? __init_waitqueue_head+0x52/0xa0 [ 2.418677] [] usb_start_wait_urb+0x7d/0x130 [ 2.418682] [] usb_control_msg+0xdc/0x120 [ 2.418691] [] hub_probe+0x4e9/0x1110 [ 2.418696] [] ? _raw_spin_unlock_irqrestore+0x87/0x90 [ 2.418701] [] ? preempt_count_sub+0x4a/0x90 [ 2.418706] [] ? _raw_spin_unlock_irqrestore+0x74/0x90 [ 2.418711] [] usb_probe_interface+0x139/0x3e0 [ 2.418717] [] driver_probe_device+0x131/0x3c0 [ 2.418723] [] __device_attach_driver+0xc3/0x180 [ 2.418728] [] ? __driver_attach+0x100/0x100 [ 2.418732] [] bus_for_each_drv+0x8d/0x100 [ 2.418737] [] __device_attach+0xe8/0x170 [ 2.418742] [] device_initial_probe+0x13/0x20 [ 2.418746] [] bus_probe_device+0xe7/0x150 [ 2.418750] [] device_add+0x49b/0x690 [ 2.418756] [] usb_set_configuration+0x5bb/0xc80 [ 2.418762] [] generic_probe+0x36/0xa0 [ 2.418766] [] usb_probe_device+0x3b/0x80 [ 2.418770] [] driver_probe_device+0x131/0x3c0 [ 2.418775] [] __device_attach_driver+0xc3/0x180 [ 2.418779] [] ? __driver_attach+0x100/0x100 [ 2.418783] [] bus_for_each_drv+0x8d/0x100 [ 2.418788] [] __device_attach+0xe8/0x170 [ 2.418793] [] device_initial_probe+0x13/0x20 [ 2.418797] [] bus_probe_device+0xe7/0x150 [ 2.418801] [] device_add+0x49b/0x690 [ 2.418807] [] usb_new_device+0x319/0x970 [ 2.418812] [] usb_add_hcd+0x67b/0xa40 [ 2.418817] [] usb_hcd_pci_probe+0x4c3/0x770 [ 2.418822] [] ? trace_hardirqs_on_caller+0x16/0x2c0 [ 2.418827] [] ? preempt_count_sub+0x4a/0x90 [ 2.418832] [] ehci_pci_probe+0x36/0x40 [ 2.418837] [] pci_device_probe+0xdc/0x180 [ 2.418842] [] driver_probe_device+0x131/0x3c0 [ 2.418846] [] __driver_attach+0xb9/0x100 [ 2.418851] [] ? driver_probe_device+0x3c0/0x3c0 [ 2.418855] [] bus_for_each_dev+0x8a/0xf0 [ 2.418860] [] driver_attach+0x27/0x50 [ 2.418864] [] bus_add_driver+0x116/0x2b0 [ 2.418868] [] driver_register+0x9f/0x160 [ 2.418873] [] __pci_register_driver+0x8f/0xe0 [ 2.418879] [] ? ehci_hcd_init+0x90/0x90 [ 2.418885] [] ehci_pci_init+0x65/0x67 [ 2.418890] [] do_one_initcall+0x5f/0x210 [ 2.418896] [] kernel_init_freeable+0x33d/0x3d4 [ 2.418903] [] kernel_init+0xf/0x120 [ 2.418907] [] ret_from_fork+0x1f/0x40 [ 2.418911] [] ? rest_init+0x170/0x170 [ 2.418915] ================================================================================ [ 2.418934] hub 1-0:1.0: 2 ports detected [ 2.419850] ehci-pci 0000:00:1d.0: EHCI Host Controller [ 2.419993] ehci-pci 0000:00:1d.0: new USB bus registered, assigned bus number 2 [ 2.420031] ehci-pci 0000:00:1d.0: debug port 2 [ 2.423961] ehci-pci 0000:00:1d.0: cache line size of 64 is not supported [ 2.423998] ehci-pci 0000:00:1d.0: irq 21, io mem 0xf7737000 [ 2.430045] ehci-pci 0000:00:1d.0: USB 2.0 started, EHCI 1.00 --==_Exmh_1463521960_1953P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Exmh version 2.5 07/13/2001 iQIVAwUBVzuSqAdmEQWDXROgAQK5mg/+NDBjnz1ThRtfyQHQlb3Gr1B3UjueMxDA uIqK2AIBbBkNEjFBqKuI/JDa8i26kvJ8eW7xzDPXbDjES8PrurZyiAcn3WpmNGwD 76jYx8fkhB3brHhWU/lvWOmRspbx32kAEq0nI8PuzwaR7QN1wTXn44iMSC/ogOOg 7zctLrvmwIPRfbzYiEMZc4ayrxhAfYm8ioVgB6LWsVxh/uMPU1nbzu7ohw0sLlSL tIOKu5cCkkvAGNpHjlJCDqrPl0s4EuKjGOM+yjvs2XNOgedSWqfNelzw5MNu95Le LMl6qJXPkvI+MXgtMMlM+YhoMMc820YGgfX0uuT/yTOMvlk+f0snemD0XQiQucqz B9aONhE35B+GIpK4pA+8jl6Sg+I7POJcwWSqcy61vEHsvQ54cgOooOCkYbXw9YTA sPEzRK85DYymOWdvUz3umPOLi9Bwwss5cwTB28qEuUhYTAzCEBQuMfD2XvcgpZjo tUziXwUvVHopczyIrEpZJ5z3NtFBDrUEfsWf9kNLQc4kfD2F2Z6Yq1ig0qiP0YSE A+RW9PQzzcLMA6IVFUJbnnbl5Z5I/fZ3WkrRGlSXc3teSUeXMlkoMUfHlWbIyld9 CKPJkJMy+P3Nm50aJc4rNMu/yV+XfjJZ88GGPoiSMICfEm03nrT74QVfQdSEVZk2 AvKN53VuUIM= =JpSK -----END PGP SIGNATURE----- --==_Exmh_1463521960_1953P--