Skip to contentSkip to conversation

sh: Fix build with CONFIG_UBSAN=y

PATCH In review Kees Cook 3 participants 11 messages Jan 30, 2024 – Mar 1, 2024 SuperH

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 sh: Fix build with CONFIG_UBSAN=y

The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build.

sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'

---
 arch/sh/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/sh/boot/compressed/Makefile +1 -0
index b5e29f99c02c..6c6c791a1d06 100644
@@ -12,6 +12,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
            vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS)
 
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 #
 # IMAGE_OFFSET is the load offset of the compression loader
Signature · 1 line
2.34.1
#1 lore raw

Hi Kees,

Quoted 24 lines · Kees Cook

The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build.

sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'

---
 arch/sh/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/sh/boot/compressed/Makefile +0 -0
index b5e29f99c02c..6c6c791a1d06 100644

arch/sh/boot/compressed/Makefile targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \ · line 18

Quoted 7 lines
arch/sh/boot/compressed/Makefile +1 -0
@@ -12,6 +12,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
            vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS)
 
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 #
 # IMAGE_OFFSET is the load offset of the compression loader

Thanks for the patch. I'm looking into this now and will provide the review later.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#2 lore raw

Hi Kees,

Quoted 29 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 26 lines · Kees Cook

The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build.

sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'

---
 arch/sh/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/sh/boot/compressed/Makefile +0 -0
index b5e29f99c02c..6c6c791a1d06 100644
@@ -12,6 +12,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
            vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS)
 
Quoted 7 lines

arch/sh/boot/compressed/Makefile targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \ · line 18

Quoted 5 lines
arch/sh/boot/compressed/Makefile +1 -0
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 #
 # IMAGE_OFFSET is the load offset of the compression loader

Thanks for the patch. I'm looking into this now and will provide the review later.

I tried to reproduce the error using your tree and the branch devel/overflow/ubsan-only minus the above patch and using the provided config but I'm unable to reproduce the error above.

Am I missing anything?

Thanks,
Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
author
#3 lore raw
Quoted 40 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 29 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 26 lines · Kees Cook

The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build.

sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'

---
 arch/sh/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/sh/boot/compressed/Makefile +0 -0
index b5e29f99c02c..6c6c791a1d06 100644
@@ -12,6 +12,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
            vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS)
 
Quoted 7 lines

arch/sh/boot/compressed/Makefile targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \ · line 18

Quoted 5 lines
arch/sh/boot/compressed/Makefile +1 -0
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 #
 # IMAGE_OFFSET is the load offset of the compression loader

Thanks for the patch. I'm looking into this now and will provide the review later.

Quoted 5 lines

I tried to reproduce the error using your tree and the branch devel/overflow/ubsan-only minus the above patch and using the provided config but I'm unable to reproduce the error above.

Am I missing anything?

When I use GCC 13.2 (I'm specifically on Ubuntu 23.10) and the randconfig linked from the report:
https://download.01.org/0day-ci/archive/20240131/[email protected]/config
(which is notably enabling CONFIG_UBSAN=y and CONFIG_UBSAN_SHIFT=y) then I see at the final link stage:

/usr/bin/sh4-linux-gnu-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x650): undefined reference to `__ubsan_handle_shift_out_of_bounds'
...

After the patch, it's solved.

-Kees

Signature · 1 line
Kees Cook
#4 lore raw

Hi Kees,

Quoted 53 lines · Kees Cook
Quoted 40 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 29 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 26 lines · Kees Cook

The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build.

sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'

---
 arch/sh/boot/compressed/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/sh/boot/compressed/Makefile +0 -0
index b5e29f99c02c..6c6c791a1d06 100644
@@ -12,6 +12,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
            vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo $(OBJECTS)
 
Quoted 7 lines

arch/sh/boot/compressed/Makefile targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \ · line 18

Quoted 5 lines
arch/sh/boot/compressed/Makefile +1 -0
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 #
 # IMAGE_OFFSET is the load offset of the compression loader

Thanks for the patch. I'm looking into this now and will provide the review later.

Quoted 5 lines

I tried to reproduce the error using your tree and the branch devel/overflow/ubsan-only minus the above patch and using the provided config but I'm unable to reproduce the error above.

Am I missing anything?

When I use GCC 13.2 (I'm specifically on Ubuntu 23.10) and the randconfig linked from the report:
https://download.01.org/0day-ci/archive/20240131/[email protected]/config
(which is notably enabling CONFIG_UBSAN=y and CONFIG_UBSAN_SHIFT=y) then I see at the final link stage:

Quoted 5 lines

/usr/bin/sh4-linux-gnu-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x650): undefined reference to `__ubsan_handle_shift_out_of_bounds'
...

After the patch, it's solved.

OK, let me test with gcc 13.x. My build host is currently running openSUSE Leap 15.5.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#5 lore raw

Hi Kees,

Quoted 6 lines · John Paul Adrian Glaubitz
Quoted 6 lines

When I use GCC 13.2 (I'm specifically on Ubuntu 23.10) and the randconfig linked from the report:
https://download.01.org/0day-ci/archive/20240131/[email protected]/config
(which is notably enabling CONFIG_UBSAN=y and CONFIG_UBSAN_SHIFT=y) then I see at the final link stage:

Quoted 7 lines
Quoted 5 lines

/usr/bin/sh4-linux-gnu-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x650): undefined reference to `__ubsan_handle_shift_out_of_bounds'
...

After the patch, it's solved.

OK, let me test with gcc 13.x. My build host is currently running openSUSE Leap 15.5.

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Adrian

Quoted 1 line

[1] https://download.01.org/0day-ci/archive/20240131/[email protected]/reproduce

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
author
#6 lore raw
Quoted 13 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 10 lines · John Paul Adrian Glaubitz
Quoted 10 lines

When I use GCC 13.2 (I'm specifically on Ubuntu 23.10) and the randconfig linked from the report:
https://download.01.org/0day-ci/archive/20240131/[email protected]/config
(which is notably enabling CONFIG_UBSAN=y and CONFIG_UBSAN_SHIFT=y) then I see at the final link stage:

/usr/bin/sh4-linux-gnu-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x650): undefined reference to `__ubsan_handle_shift_out_of_bounds'
...

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

After the patch, it's solved.

OK, let me test with gcc 13.x. My build host is currently running openSUSE Leap 15.5.

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Sure, they're in -next, but for an -rc2 based tree, see:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/kspp

Signature · 1 line
Kees Cook
#7 lore raw
Quoted 7 lines · Kees Cook
Quoted 4 lines

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Sure, they're in -next, but for an -rc2 based tree, see:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/kspp

OK, thanks. I will give it a try with gcc-13.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#8 lore raw

Hi Kees,

Quoted 10 lines · John Paul Adrian Glaubitz
Quoted 7 lines · Kees Cook
Quoted 4 lines

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Sure, they're in -next, but for an -rc2 based tree, see:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/kspp

OK, thanks. I will give it a try with gcc-13.

I'm still unable to reproduce the error that the kernel test robot reported.

I'm using gcc-13:

glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc
sh4-linux-gcc: fatal error: no input files
compilation terminated. glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc --version sh4-linux-gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

glaubitz@node54:/data/home/glaubitz/linux-kees>

I checked out your tree and the for-next/kspp branch.

Then fetched the config that triggered the bug like this:

$ wget https://download.01.org/0day-ci/archive/20240131/[email protected]/config -O .config

Building the kernel with "make -j32 uImage" works fine. No errors except for some unreleated warnings that still need to be fixed.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#9 lore raw

Hi Adrian,

Quoted 29 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 10 lines · John Paul Adrian Glaubitz
Quoted 7 lines · Kees Cook
Quoted 4 lines

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Sure, they're in -next, but for an -rc2 based tree, see:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/kspp

OK, thanks. I will give it a try with gcc-13.

I'm still unable to reproduce the error that the kernel test robot reported.

I'm using gcc-13:

glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc
sh4-linux-gcc: fatal error: no input files
compilation terminated. glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc --version sh4-linux-gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

glaubitz@node54:/data/home/glaubitz/linux-kees>

Quoted 8 lines

I checked out your tree and the for-next/kspp branch.

Then fetched the config that triggered the bug like this:

$ wget https://download.01.org/0day-ci/archive/20240131/[email protected]/config -O .config

Building the kernel with "make -j32 uImage" works fine. No errors except for some unreleated warnings that still need to be fixed.

Sorry for late reply. Seems like the warnings can be reproduced by "make zImage" which is the default make target, but cannot be reproduced by "make uImage".

HEAD is now at 918327e9b7ffb ubsan: Remove CONFIG_UBSAN_SANITIZE_ALL

$ wget https://download.01.org/0day-ci/archive/20240131/[email protected]/config -O .config
$ sh4-linux-gcc --version
sh4-linux-gcc (GCC) 13.2.0
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh olddefconfig
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh
...
  LD      arch/sh/boot/compressed/vmlinux
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `inflate_fast':
misc.c:(.text+0xc5c): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflateReset':
misc.c:(.text+0xd00): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate':
misc.c:(.text+0x23fc): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/ashldi3.o: in function `__ashldi3':
ashldi3.c:(.text+0xc8): undefined reference to `__ubsan_handle_shift_out_of_bounds'
make[3]: *** [arch/sh/boot/compressed/Makefile:38: arch/sh/boot/compressed/vmlinux] Error 1
make[2]: *** [arch/sh/boot/Makefile:40: arch/sh/boot/compressed/vmlinux] Error 2
make[1]: *** [arch/sh/Makefile:170: zImage] Error 2
make: *** [Makefile:240: __sub-make] Error 2
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh uImage
...
  OBJCOPY arch/sh/boot/vmlinux.bin
  GZIP    arch/sh/boot/vmlinux.bin.gz
  UIMAGE  arch/sh/boot/uImage.gz
Image Name:   Linux-6.8.0-rc2+
Created:      Fri Mar  1 13:31:36 2024
Image Type:   SuperH Linux Kernel Image (gzip compressed)
Data Size:    9297141 Bytes = 9079.24 KiB = 8.87 MiB
Load Address: 08001000
Entry Point:  08002000
  Image arch/sh/boot/uImage is ready

--
Best Regards,
Yujie

#10 lore raw

Hi Yujie,

Quoted 68 lines · Yujie
Quoted 29 lines · John Paul Adrian Glaubitz

Hi Kees,

Quoted 10 lines · John Paul Adrian Glaubitz
Quoted 7 lines · Kees Cook
Quoted 4 lines

I just wanted to try reproduce the problem again with the reproducer in [1] as well as with gcc-13.2.0, but your branch devel/overflow/ubsan-only no longer exists.

Can you tell me where to find the patches now?

Sure, they're in -next, but for an -rc2 based tree, see:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/kspp

OK, thanks. I will give it a try with gcc-13.

I'm still unable to reproduce the error that the kernel test robot reported.

I'm using gcc-13:

glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc
sh4-linux-gcc: fatal error: no input files
compilation terminated. glaubitz@node54:/data/home/glaubitz/linux-kees> sh4-linux-gcc --version sh4-linux-gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

glaubitz@node54:/data/home/glaubitz/linux-kees>

Quoted 8 lines

I checked out your tree and the for-next/kspp branch.

Then fetched the config that triggered the bug like this:

$ wget https://download.01.org/0day-ci/archive/20240131/[email protected]/config -O .config

Building the kernel with "make -j32 uImage" works fine. No errors except for some unreleated warnings that still need to be fixed.

Sorry for late reply. Seems like the warnings can be reproduced by "make zImage" which is the default make target, but cannot be reproduced by "make uImage".

HEAD is now at 918327e9b7ffb ubsan: Remove CONFIG_UBSAN_SANITIZE_ALL

$ wget https://download.01.org/0day-ci/archive/20240131/[email protected]/config -O .config
$ sh4-linux-gcc --version
sh4-linux-gcc (GCC) 13.2.0
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh olddefconfig
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh
...
  LD      arch/sh/boot/compressed/vmlinux
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table':
misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `inflate_fast':
misc.c:(.text+0xc5c): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflateReset':
misc.c:(.text+0xd00): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate':
misc.c:(.text+0x23fc): undefined reference to `__ubsan_handle_shift_out_of_bounds'
sh4-linux-ld: arch/sh/boot/compressed/ashldi3.o: in function `__ashldi3':
ashldi3.c:(.text+0xc8): undefined reference to `__ubsan_handle_shift_out_of_bounds'
make[3]: *** [arch/sh/boot/compressed/Makefile:38: arch/sh/boot/compressed/vmlinux] Error 1
make[2]: *** [arch/sh/boot/Makefile:40: arch/sh/boot/compressed/vmlinux] Error 2
make[1]: *** [arch/sh/Makefile:170: zImage] Error 2
make: *** [Makefile:240: __sub-make] Error 2
Quoted 12 lines
$ make -j72 CROSS_COMPILE=sh4-linux- ARCH=sh uImage
...
  OBJCOPY arch/sh/boot/vmlinux.bin
  GZIP    arch/sh/boot/vmlinux.bin.gz
  UIMAGE  arch/sh/boot/uImage.gz
Image Name:   Linux-6.8.0-rc2+
Created:      Fri Mar  1 13:31:36 2024
Image Type:   SuperH Linux Kernel Image (gzip compressed)
Data Size:    9297141 Bytes = 9079.24 KiB = 8.87 MiB
Load Address: 08001000
Entry Point:  08002000
  Image arch/sh/boot/uImage is ready

Thanks a lot for pointing this out. This explains the problem.

I will have another look over the weekend and acknowledge the patch if Kees wants to pick it up through his own tree.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913