sh: machvec: Use char[] for section boundaries
authorKees Cook <keescook@chromium.org>
Wed, 7 Sep 2022 23:40:44 +0000 (16:40 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:15:38 +0000 (13:15 +0200)
[ Upstream commit c5783af354688b24abd359f7086c282ec74de993 ]

As done for other sections, define the extern as a character array,
which relaxes many of the compiler-time object size checks, which would
otherwise assume it's a single long. Solves the following build error:

arch/sh/kernel/machvec.c: error: array subscript 'struct sh_machine_vector[0]' is partly outside array bounds of 'long int[1]' [-Werror=array-bounds]:  => 105:33

Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/lkml/alpine.DEB.2.22.394.2209050944290.964530@ramsan.of.borg/
Fixes: 9655ad03af2d ("sh: Fixup machvec support.")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Rich Felker <dalias@libc.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/sh/include/asm/sections.h
arch/sh/kernel/machvec.c

index 7a99e6af637284d3061a96a274f375f2189f2eb2..9ec764c4ffe9039d57cccf1615051fa1c81fa89c 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <asm-generic/sections.h>
 
-extern long __machvec_start, __machvec_end;
+extern char __machvec_start[], __machvec_end[];
 extern char __uncached_start, __uncached_end;
 extern char __start_eh_frame[], __stop_eh_frame[];
 
index ec05f491c3471ea1e5e57a0ef9b93409f996c008..a9f797a76e7c16f60e85e2d1d8dd59b3ee854abc 100644 (file)
@@ -22,8 +22,8 @@
 #define MV_NAME_SIZE 32
 
 #define for_each_mv(mv) \
-       for ((mv) = (struct sh_machine_vector *)&__machvec_start; \
-            (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \
+       for ((mv) = (struct sh_machine_vector *)__machvec_start; \
+            (mv) && (unsigned long)(mv) < (unsigned long)__machvec_end; \
             (mv)++)
 
 static struct sh_machine_vector * __init get_mv_byname(const char *name)
@@ -89,8 +89,8 @@ void __init sh_mv_setup(void)
        if (!machvec_selected) {
                unsigned long machvec_size;
 
-               machvec_size = ((unsigned long)&__machvec_end -
-                               (unsigned long)&__machvec_start);
+               machvec_size = ((unsigned long)__machvec_end -
+                               (unsigned long)__machvec_start);
 
                /*
                 * Sanity check for machvec section alignment. Ensure
@@ -104,7 +104,7 @@ void __init sh_mv_setup(void)
                 * vector (usually the only one) from .machvec.init.
                 */
                if (machvec_size >= sizeof(struct sh_machine_vector))
-                       sh_mv = *(struct sh_machine_vector *)&__machvec_start;
+                       sh_mv = *(struct sh_machine_vector *)__machvec_start;
        }
 
        printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type());