From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755578AbcETBA2 (ORCPT ); Thu, 19 May 2016 21:00:28 -0400 Received: from outbound.smtp.vt.edu ([198.82.183.121]:37269 "EHLO omr1.cc.vt.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754665AbcETBA1 (ORCPT ); Thu, 19 May 2016 21:00:27 -0400 X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6+dev To: Greg Kroah-Hartman Cc: Alan Stern , Andrey Ryabinin , Oliver Neukum , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH] - silence UBSAN complaint in ehci-hcd. From: Valdis.Kletnieks@vt.edu In-Reply-To: <20160520005031.GA11921@kroah.com> References: <14469.1463692740@turing-police.cc.vt.edu> <20160520005031.GA11921@kroah.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==_Exmh_1463705976_4779P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Date: Thu, 19 May 2016 20:59:36 -0400 Message-ID: <24464.1463705976@turing-police.cc.vt.edu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --==_Exmh_1463705976_4779P Content-Type: text/plain; charset=us-ascii On Thu, 19 May 2016 17:50:31 -0700, Greg Kroah-Hartman said: > On Thu, May 19, 2016 at 05:19:00PM -0400, Valdis Kletnieks wrote: > > UBSAN throws a complaint: > > > > [ 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]' > > > > though it's only on the hostpc[] part, not on the port_status[] on the > > previous line which has the same exact index calculation. The root cause is > > that the first declaration is port_status[0], which uses a GCC extension and > > UBSAN is smart enough to realize the programmer is doing something > > intentionally odd. > > > > However, the problematic declaration is hostpc[1], which doesn't have > > the "I know what I'm doing" semantics of [0]. Change the declaration to match. > > > > Signed-Off-By: Valdis Kletnieks > > > > --- a/include/linux/usb/ehci_def.h 2015-01-06 01:04:24.342436706 -0500 > > +++ b/include/linux/usb/ehci_def.h 2016-05-19 13:57:20.869304540 -0400 > > @@ -180,11 +180,11 @@ struct ehci_regs { > > * PORTSCx > > */ > > /* HOSTPC: offset 0x84 */ > > - u32 hostpc[1]; /* HOSTPC extension */ > > + u32 hostpc[0]; /* HOSTPC extension */ > > #define HOSTPC_PHCD (1<<22) /* Phy clock disable */ > > #define HOSTPC_PSPD (3<<25) /* Port speed detection */ > > Hm, this is odd, you really do want hostpc to be 1 u32 value, don't make > it 0 please. If you walk off the end of hostpc, well, let's fix that > properly. Well, UBSAN doesn't complain about the *other* use of the same exact index, apparently because 'u32 port_status[0]' tells it to shut up we know what we're doing. And I'm pretty sure that if hostpc was supposed to be exactly one u32 rather than an array, it wouldn't have the [] semantics everyplace... --==_Exmh_1463705976_4779P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Exmh version 2.5 07/13/2001 iQIVAwUBVz5heAdmEQWDXROgAQLA1xAAsaQvfST1A5GBa0FUGbC1H8/W3L7Dmm8V 49+fY7gTzol+Egr6e00sFciht/3sxhM4eeFWaoPlp/NfNvsHwHoi+31aeSR7gRId gknjSQpM1ua4fmg4Yawi80s4JpPPQcDV9zztXRmWwRuIgPJ4zP4uiFzeazVGskex EQkY1h49KSZxGghuEBr58ozqmzcbnM7xUwdHWDKrhMvxktGgw+EDDmzo73VxAM+N MzmUgpWJGvTZkylHSDIfZWFBFyc7P3LnnHBs0nlGmvfBQ5VCtvNK9Mj8MKB5mu0j PyQxggmKw7xi6HZ2U6K6jlBaXqXbGAZQIH3lzNbOTMCkfTGo1yo28Lqp/bD/JhWI ZyIZo0LpoGVkb3hnAxSV+jJir6n1qRr0PQAAPk+4VCEyZMJO5hNe97SwLwgPSNtN XcdWNm/j6x2eeR4DN50zWxrVL6iiltDEaaz3AT4cv+KO54hGivUB0KlIfyjsWxsd yRH9UtBy5x9thYmYUGF/adSOnMhdx4S4TBiE2g3a8ZSmuj1dZT9bu+iVHVzjZViP GEM4djJPDEiwJN0hzmKysdWo77DsH6Qo9nTmoV8XbDfAkOxVDx1DNtY4HvTcNC5u wnreaf18XmfS9EW+H73JdoUM/DRChqEaOy1WxR+zXE/L8/b+nDE2l2e8Cp27em6A SGc9N0RplM8= =7ANm -----END PGP SIGNATURE----- --==_Exmh_1463705976_4779P--