Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1479906 > unrolled thread

UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c

Started byMeelis Roos <mroos@linux.ee>
First post2016-09-09 13:40 +0200
Last post2016-09-10 18:20 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c Meelis Roos <mroos@linux.ee> - 2016-09-09 13:40 +0200
    Re: UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c Michael Ellerman <mpe@ellerman.id.au> - 2016-09-10 12:00 +0200
      Re: UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c Meelis Roos <mroos@linux.ee> - 2016-09-11 09:50 +0200
    Re: UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> - 2016-09-10 18:20 +0200

#1479906 — UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c

FromMeelis Roos <mroos@linux.ee>
Date2016-09-09 13:40 +0200
SubjectUBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c
Message-ID<sfsk2-2dK-17@gated-at.bofh.it>
Got this on my PowerPC G4 (533 MHz, PowerPC 7410, PowerMac3,4 platform), 
with gcc version 5.3.1 20160509 (Debian 5.3.1-19):

[    0.000000] ================================================================================
[    0.000000] UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c:2240:25
[    0.000000] shift exponent 32 is too large for 32-bit type 'long unsigned int'
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.8.0-rc5-00075-gd71f058 #106
[    0.000000] Call Trace:
[    0.000000] [c0a5ff10] [c03aa588] ubsan_epilogue+0x18/0x4c (unreliable)
[    0.000000] [c0a5ff20] [c03aab38] __ubsan_handle_shift_out_of_bounds+0xe8/0x13c
[    0.000000] [c0a5ffa0] [c07c42d0] cpu_feature_keys_init+0xa0/0xb8
[    0.000000] [c0a5ffd0] [c07ca1fc] setup_feature_keys+0x14/0x24
[    0.000000] [c0a5ffe0] [c07c6c74] machine_init+0x18/0x58
[    0.000000] [c0a5fff0] [c000341c] start_here+0x38/0x78
[    0.000000] ================================================================================



-- 
Meelis Roos (mroos@linux.ee)

[toc] | [next] | [standalone]


#1480577

FromMichael Ellerman <mpe@ellerman.id.au>
Date2016-09-10 12:00 +0200
Message-ID<sfNeO-70F-25@gated-at.bofh.it>
In reply to#1479906
Meelis Roos <mroos@linux.ee> writes:

> Got this on my PowerPC G4 (533 MHz, PowerPC 7410, PowerMac3,4 platform), 
> with gcc version 5.3.1 20160509 (Debian 5.3.1-19):
>
> [    0.000000] ================================================================================
> [    0.000000] UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c:2240:25
> [    0.000000] shift exponent 32 is too large for 32-bit type 'long unsigned int'
> [    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.8.0-rc5-00075-gd71f058 #106
> [    0.000000] Call Trace:
> [    0.000000] [c0a5ff10] [c03aa588] ubsan_epilogue+0x18/0x4c (unreliable)
> [    0.000000] [c0a5ff20] [c03aab38] __ubsan_handle_shift_out_of_bounds+0xe8/0x13c
> [    0.000000] [c0a5ffa0] [c07c42d0] cpu_feature_keys_init+0xa0/0xb8
> [    0.000000] [c0a5ffd0] [c07ca1fc] setup_feature_keys+0x14/0x24
> [    0.000000] [c0a5ffe0] [c07c6c74] machine_init+0x18/0x58
> [    0.000000] [c0a5fff0] [c000341c] start_here+0x38/0x78
> [    0.000000] ================================================================================

Oops, my bad.

#define NUM_CPU_FTR_KEYS	64

...

	for (i = 0; i < NUM_CPU_FTR_KEYS; i++) {
		unsigned long f = 1ul << i;

Does this fix it?

cheers

diff --git a/arch/powerpc/include/asm/cpu_has_feature.h b/arch/powerpc/include/asm/cpu_has_feature.h
index 2ef55f8968a2..b312b152461b 100644
--- a/arch/powerpc/include/asm/cpu_has_feature.h
+++ b/arch/powerpc/include/asm/cpu_has_feature.h
@@ -15,7 +15,7 @@ static inline bool early_cpu_has_feature(unsigned long feature)
 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
 #include <linux/jump_label.h>
 
-#define NUM_CPU_FTR_KEYS	64
+#define NUM_CPU_FTR_KEYS	BITS_PER_LONG
 
 extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
 

[toc] | [prev] | [next] | [standalone]


#1480750

FromMeelis Roos <mroos@linux.ee>
Date2016-09-11 09:50 +0200
Message-ID<sg7Gx-3ey-7@gated-at.bofh.it>
In reply to#1480577
> Does this fix it?

Yes, thank you!

> diff --git a/arch/powerpc/include/asm/cpu_has_feature.h b/arch/powerpc/include/asm/cpu_has_feature.h
> index 2ef55f8968a2..b312b152461b 100644
> --- a/arch/powerpc/include/asm/cpu_has_feature.h
> +++ b/arch/powerpc/include/asm/cpu_has_feature.h
> @@ -15,7 +15,7 @@ static inline bool early_cpu_has_feature(unsigned long feature)
>  #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
>  #include <linux/jump_label.h>
>  
> -#define NUM_CPU_FTR_KEYS	64
> +#define NUM_CPU_FTR_KEYS	BITS_PER_LONG
>  
>  extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
>  
> 

-- 
Meelis Roos (mroos@linux.ee)

[toc] | [prev] | [next] | [standalone]


#1480660

From"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Date2016-09-10 18:20 +0200
Message-ID<sfTay-2uE-3@gated-at.bofh.it>
In reply to#1479906
Meelis Roos <mroos@linux.ee> writes:

> Got this on my PowerPC G4 (533 MHz, PowerPC 7410, PowerMac3,4 platform), 
> with gcc version 5.3.1 20160509 (Debian 5.3.1-19):
>
> [    0.000000] ================================================================================
> [    0.000000] UBSAN: Undefined behaviour in arch/powerpc/kernel/cputable.c:2240:25
> [    0.000000] shift exponent 32 is too large for 32-bit type 'long unsigned int'
> [    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.8.0-rc5-00075-gd71f058 #106
> [    0.000000] Call Trace:
> [    0.000000] [c0a5ff10] [c03aa588] ubsan_epilogue+0x18/0x4c (unreliable)
> [    0.000000] [c0a5ff20] [c03aab38] __ubsan_handle_shift_out_of_bounds+0xe8/0x13c
> [    0.000000] [c0a5ffa0] [c07c42d0] cpu_feature_keys_init+0xa0/0xb8
> [    0.000000] [c0a5ffd0] [c07ca1fc] setup_feature_keys+0x14/0x24
> [    0.000000] [c0a5ffe0] [c07c6c74] machine_init+0x18/0x58
> [    0.000000] [c0a5fff0] [c000341c] start_here+0x38/0x78
> [    0.000000] ================================================================================
>
>

Can you try

diff --git a/arch/powerpc/include/asm/cpu_has_feature.h b/arch/powerpc/include/asm/cpu_has_feature.h
index 2ef55f8968a2..b312b152461b 100644
--- a/arch/powerpc/include/asm/cpu_has_feature.h
+++ b/arch/powerpc/include/asm/cpu_has_feature.h
@@ -15,7 +15,7 @@ static inline bool early_cpu_has_feature(unsigned long feature)
 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
 #include <linux/jump_label.h>
 
-#define NUM_CPU_FTR_KEYS	64
+#define NUM_CPU_FTR_KEYS	BITS_PER_LONG
 
 extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web