linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sh: machvec: Use char[] for section boundaries
@ 2022-09-07 23:43 Kees Cook
  2022-09-08  6:53 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kees Cook @ 2022-09-07 23:43 UTC (permalink / raw)
  To: Yoshinori Sato
  Cc: Kees Cook, Rich Felker, linux-sh, Geert Uytterhoeven, Paul Mundt,
	linux-kernel, linux-hardening

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.")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 arch/sh/include/asm/sections.h |  2 +-
 arch/sh/kernel/machvec.c       | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
index 8edb824049b9..0cb0ca149ac3 100644
--- a/arch/sh/include/asm/sections.h
+++ b/arch/sh/include/asm/sections.h
@@ -4,7 +4,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[];
 
diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c
index d606679a211e..57efaf5b82ae 100644
--- a/arch/sh/kernel/machvec.c
+++ b/arch/sh/kernel/machvec.c
@@ -20,8 +20,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)
@@ -87,8 +87,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
@@ -102,7 +102,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;
 	}
 
 	pr_notice("Booting machvec: %s\n", get_system_type());
-- 
2.34.1


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

* Re: [PATCH] sh: machvec: Use char[] for section boundaries
  2022-09-07 23:43 [PATCH] sh: machvec: Use char[] for section boundaries Kees Cook
@ 2022-09-08  6:53 ` Geert Uytterhoeven
  2022-09-08 12:17 ` Gustavo A. R. Silva
  2022-09-08 22:15 ` Rich Felker
  2 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2022-09-08  6:53 UTC (permalink / raw)
  To: Kees Cook
  Cc: Yoshinori Sato, Rich Felker, Linux-sh list, Paul Mundt,
	Linux Kernel Mailing List, linux-hardening

On Thu, Sep 8, 2022 at 1:43 AM Kees Cook <keescook@chromium.org> wrote:
> 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.")
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] sh: machvec: Use char[] for section boundaries
  2022-09-07 23:43 [PATCH] sh: machvec: Use char[] for section boundaries Kees Cook
  2022-09-08  6:53 ` Geert Uytterhoeven
@ 2022-09-08 12:17 ` Gustavo A. R. Silva
  2022-09-08 22:15 ` Rich Felker
  2 siblings, 0 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-08 12:17 UTC (permalink / raw)
  To: Kees Cook
  Cc: Yoshinori Sato, Rich Felker, linux-sh, Geert Uytterhoeven,
	Paul Mundt, linux-kernel, linux-hardening

On Wed, Sep 07, 2022 at 04:43:45PM -0700, Kees Cook wrote:
> 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.")
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

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

* Re: [PATCH] sh: machvec: Use char[] for section boundaries
  2022-09-07 23:43 [PATCH] sh: machvec: Use char[] for section boundaries Kees Cook
  2022-09-08  6:53 ` Geert Uytterhoeven
  2022-09-08 12:17 ` Gustavo A. R. Silva
@ 2022-09-08 22:15 ` Rich Felker
  2022-09-13 17:34   ` Kees Cook
  2 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2022-09-08 22:15 UTC (permalink / raw)
  To: Kees Cook
  Cc: Yoshinori Sato, linux-sh, Geert Uytterhoeven, Paul Mundt,
	linux-kernel, linux-hardening

On Wed, Sep 07, 2022 at 04:43:45PM -0700, Kees Cook wrote:
> 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

LGMT. This is the approach I recommend for this general type of
mechanism. So,

Acked-by: Rich Felker <dalias@libc.org>

Since I haven't been on top of collating patches for upstreaming, I'd
be happy if anyone else wants to take this in their tree before I get
back to it.

Rich


> 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.")
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  arch/sh/include/asm/sections.h |  2 +-
>  arch/sh/kernel/machvec.c       | 10 +++++-----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
> index 8edb824049b9..0cb0ca149ac3 100644
> --- a/arch/sh/include/asm/sections.h
> +++ b/arch/sh/include/asm/sections.h
> @@ -4,7 +4,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[];
>  
> diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c
> index d606679a211e..57efaf5b82ae 100644
> --- a/arch/sh/kernel/machvec.c
> +++ b/arch/sh/kernel/machvec.c
> @@ -20,8 +20,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)
> @@ -87,8 +87,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
> @@ -102,7 +102,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;
>  	}
>  
>  	pr_notice("Booting machvec: %s\n", get_system_type());
> -- 
> 2.34.1

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

* Re: [PATCH] sh: machvec: Use char[] for section boundaries
  2022-09-08 22:15 ` Rich Felker
@ 2022-09-13 17:34   ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2022-09-13 17:34 UTC (permalink / raw)
  To: Rich Felker
  Cc: Yoshinori Sato, linux-sh, Geert Uytterhoeven, Paul Mundt,
	linux-kernel, linux-hardening

On Thu, Sep 08, 2022 at 06:15:39PM -0400, Rich Felker wrote:
> On Wed, Sep 07, 2022 at 04:43:45PM -0700, Kees Cook wrote:
> > 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
> 
> LGMT. This is the approach I recommend for this general type of
> mechanism. So,
> 
> Acked-by: Rich Felker <dalias@libc.org>
> 
> Since I haven't been on top of collating patches for upstreaming, I'd
> be happy if anyone else wants to take this in their tree before I get
> back to it.

Great; thanks! I'll take it via my tree. :)

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2022-09-13 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 23:43 [PATCH] sh: machvec: Use char[] for section boundaries Kees Cook
2022-09-08  6:53 ` Geert Uytterhoeven
2022-09-08 12:17 ` Gustavo A. R. Silva
2022-09-08 22:15 ` Rich Felker
2022-09-13 17:34   ` Kees Cook

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).