From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753257AbcERKWi (ORCPT ); Wed, 18 May 2016 06:22:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:38600 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753222AbcERKWh (ORCPT ); Wed, 18 May 2016 06:22:37 -0400 Message-ID: <1463566747.22748.24.camel@suse.com> Subject: Re: UBSAN whinge in ihci-hub.c From: Oliver Neukum To: Andrey Ryabinin Cc: Greg Kroah-Hartman , Alan Stern , LKML , linux-usb@vger.kernel.org, Valdis Kletnieks Date: Wed, 18 May 2016 12:19:07 +0200 In-Reply-To: References: <5739.1463521960@turing-police.cc.vt.edu> <20160517221644.GA17167@kroah.com> <1463559507.22748.12.camel@suse.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.11 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-05-18 at 12:16 +0300, Andrey Ryabinin wrote: > 2016-05-18 11:18 GMT+03:00 Oliver Neukum : > > On Wed, 2016-05-18 at 10:40 +0300, Andrey Ryabinin wrote: > >> 2016-05-18 1:16 GMT+03:00 Greg Kroah-Hartman : > >> > On Tue, May 17, 2016 at 05:52:40PM -0400, Valdis Kletnieks wrote: > >> >> 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]' > >> > > >> > > >> > > >> > It's a known bug in ubsan, > >> > >> It's not a bug. int *p = &a[-1] is undefined behavior. It doesn't > >> matter whether that pointer dereferenced or not. > > > > That is a bold statement. Pointer arithmetic is defined. How can > > the computation of an address be undefined behavior while it is > > not used? > > It's defined only if pointer points to array element or one-past-end > element. Everything else is undefined. > > $ 6.5.6.8 > "If both the pointer operand and the result point to elements of > the same array object, > or one past the last element of the array object, the evaluation > shall not produce an overflow; > otherwise, the behavior is undefined." But we do not care whether the calculation overflows. We don't use it at all in those cases. Regards Oliver