linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set
@ 2018-12-17 15:03 Anders Roxell
  2019-01-11 19:01 ` Andrey Ryabinin
  0 siblings, 1 reply; 5+ messages in thread
From: Anders Roxell @ 2018-12-17 15:03 UTC (permalink / raw)
  To: aryabinin; +Cc: arnd, linux-kernel, Anders Roxell

When booting an allmodconfig kernel, there are a lot of false-positives.
With a message like this 'UBSAN: Undefined behaviour in...' with a call
trace that follows.

Reworked so that when building a allmodconfig kernel that turns
everything into '=m' or '=y' will turn off UBSAN_ALIGNMENT.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 lib/Kconfig.ubsan | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index 98fa559ebd80..a2ae4a8e4fa6 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -27,15 +27,19 @@ config UBSAN_SANITIZE_ALL
 	  Enabling this option will get kernel image size increased
 	  significantly.
 
-config UBSAN_ALIGNMENT
-	bool "Enable checking of pointers alignment"
+config UBSAN_NO_ALIGNMENT
+	bool "Disable checking of pointers alignment"
 	depends on UBSAN
-	default y if !HAVE_EFFICIENT_UNALIGNED_ACCESS
+	default y if HAVE_EFFICIENT_UNALIGNED_ACCESS
 	help
-	  This option enables detection of unaligned memory accesses.
-	  Enabling this option on architectures that support unaligned
+	  This option disables the check of unaligned memory accesses.
+	  This option should be used when building allmodconfig.
+	  Disabling this option on architectures that support unaligned
 	  accesses may produce a lot of false positives.
 
+config UBSAN_ALIGNMENT
+	def_bool !UBSAN_NO_ALIGNMENT
+
 config TEST_UBSAN
 	tristate "Module for testing for undefined behavior detection"
 	depends on m && UBSAN
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set
  2018-12-17 15:03 [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set Anders Roxell
@ 2019-01-11 19:01 ` Andrey Ryabinin
  2019-01-30  1:36   ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Ryabinin @ 2019-01-11 19:01 UTC (permalink / raw)
  To: Anders Roxell, Andrew Morton; +Cc: arnd, linux-kernel



On 12/17/18 6:03 PM, Anders Roxell wrote:
> When booting an allmodconfig kernel, there are a lot of false-positives.
> With a message like this 'UBSAN: Undefined behaviour in...' with a call
> trace that follows.
> 
> Reworked so that when building a allmodconfig kernel that turns
> everything into '=m' or '=y' will turn off UBSAN_ALIGNMENT.
> 
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> ---

Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>


>  lib/Kconfig.ubsan | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
> index 98fa559ebd80..a2ae4a8e4fa6 100644
> --- a/lib/Kconfig.ubsan
> +++ b/lib/Kconfig.ubsan
> @@ -27,15 +27,19 @@ config UBSAN_SANITIZE_ALL
>  	  Enabling this option will get kernel image size increased
>  	  significantly.
>  
> -config UBSAN_ALIGNMENT
> -	bool "Enable checking of pointers alignment"
> +config UBSAN_NO_ALIGNMENT
> +	bool "Disable checking of pointers alignment"
>  	depends on UBSAN
> -	default y if !HAVE_EFFICIENT_UNALIGNED_ACCESS
> +	default y if HAVE_EFFICIENT_UNALIGNED_ACCESS
>  	help
> -	  This option enables detection of unaligned memory accesses.
> -	  Enabling this option on architectures that support unaligned
> +	  This option disables the check of unaligned memory accesses.
> +	  This option should be used when building allmodconfig.
> +	  Disabling this option on architectures that support unaligned
>  	  accesses may produce a lot of false positives.
>  
> +config UBSAN_ALIGNMENT
> +	def_bool !UBSAN_NO_ALIGNMENT
> +
>  config TEST_UBSAN
>  	tristate "Module for testing for undefined behavior detection"
>  	depends on m && UBSAN
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set
  2019-01-11 19:01 ` Andrey Ryabinin
@ 2019-01-30  1:36   ` Andrew Morton
  2019-01-30 17:12     ` Andrey Ryabinin
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2019-01-30  1:36 UTC (permalink / raw)
  To: Andrey Ryabinin; +Cc: Anders Roxell, arnd, linux-kernel

On Fri, 11 Jan 2019 22:01:16 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:

> 
> 
> On 12/17/18 6:03 PM, Anders Roxell wrote:
> > When booting an allmodconfig kernel, there are a lot of false-positives.
> > With a message like this 'UBSAN: Undefined behaviour in...' with a call
> > trace that follows.
> > 
> > Reworked so that when building a allmodconfig kernel that turns
> > everything into '=m' or '=y' will turn off UBSAN_ALIGNMENT.
> > 
> > Suggested-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> > ---
> 
> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> 

Confused.  Why does allmodconfig result in UBSAN warnings?
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set
  2019-01-30  1:36   ` Andrew Morton
@ 2019-01-30 17:12     ` Andrey Ryabinin
  2019-01-30 21:30       ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Ryabinin @ 2019-01-30 17:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Anders Roxell, arnd, linux-kernel



On 1/30/19 4:36 AM, Andrew Morton wrote:
> On Fri, 11 Jan 2019 22:01:16 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> 
>>
>>
>> On 12/17/18 6:03 PM, Anders Roxell wrote:
>>> When booting an allmodconfig kernel, there are a lot of false-positives.
>>> With a message like this 'UBSAN: Undefined behaviour in...' with a call
>>> trace that follows.
>>>
>>> Reworked so that when building a allmodconfig kernel that turns
>>> everything into '=m' or '=y' will turn off UBSAN_ALIGNMENT.
>>>
>>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
>>> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
>>> ---
>>
>> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>>
> 
> Confused.  Why does allmodconfig result in UBSAN warnings?
>  

UBSAN warnings is a result of enabling noisy CONFIG_UBSAN_ALIGNMENT which is disabled
by default if HAVE_EFFICIENT_UNALIGNED_ACCESS=y.
It's noisy even if don't have efficient unaligned access, e.g. people often add  __cacheline_aligned_in_smp
in structs, but forget to align allocations of such struct (kmalloc() give 8-byte alignment in worst case).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set
  2019-01-30 17:12     ` Andrey Ryabinin
@ 2019-01-30 21:30       ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2019-01-30 21:30 UTC (permalink / raw)
  To: Andrey Ryabinin; +Cc: Andrew Morton, Anders Roxell, Linux Kernel Mailing List

On Wed, Jan 30, 2019 at 6:12 PM Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> On 1/30/19 4:36 AM, Andrew Morton wrote:
> > On Fri, 11 Jan 2019 22:01:16 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> >> On 12/17/18 6:03 PM, Anders Roxell wrote:
> >>> When booting an allmodconfig kernel, there are a lot of false-positives.
> >>> With a message like this 'UBSAN: Undefined behaviour in...' with a call
> >>> trace that follows.
> >>>
> >>> Reworked so that when building a allmodconfig kernel that turns
> >>> everything into '=m' or '=y' will turn off UBSAN_ALIGNMENT.
> >>>
> >>> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> >>> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> >>> ---
> >>
> >> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> >>
> >
> > Confused.  Why does allmodconfig result in UBSAN warnings?
> >
>
> UBSAN warnings is a result of enabling noisy CONFIG_UBSAN_ALIGNMENT which is disabled
> by default if HAVE_EFFICIENT_UNALIGNED_ACCESS=y.
> It's noisy even if don't have efficient unaligned access, e.g. people often add
>  __cacheline_aligned_in_smp in structs, but forget to align allocations of such struct
> (kmalloc() give 8-byte alignment in worst case).

That would be a fixable issue, but there is another one that I looked at
with Anders: We have a number of list_for_each_entry_safe() loops
that use a list_head on the stack and add objects of a type with
large alignment. When list_for_each_entry_safe() gets to the end of
that list, it sees a pointer to an unaligned structure starting  few bytes
before the list_head on stack. The only element of that structure that
is ever used is that list_head, so there is no actual problem, but the
warning triggers nonetheless.

      Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-30 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-17 15:03 [PATCH] lib/ubsan: default UBSAN_ALIGNMENT to not set Anders Roxell
2019-01-11 19:01 ` Andrey Ryabinin
2019-01-30  1:36   ` Andrew Morton
2019-01-30 17:12     ` Andrey Ryabinin
2019-01-30 21:30       ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).