* [PATCH] sched/core: Do not treat class list boundary markers as arrays
@ 2022-05-16 19:42 Kees Cook
2022-05-16 20:44 ` Peter Zijlstra
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2022-05-16 19:42 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Kees Cook, Christophe de Dinechin, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Davidlohr Bueso, linux-kernel,
linux-hardening
GCC 12 is very sensitive about array checking, and views all negative
array accesses as unsafe (a not unreasonable position). Avoid the
warnings about __begin_sched_classes being accessed via negative bounds
by converting them to the pointers they actually are. Silences this
warning:
In file included from kernel/sched/core.c:81:
kernel/sched/core.c: In function ‘set_rq_online.part.0’:
kernel/sched/sched.h:2197:52: error: array subscript -1 is outside array bounds of ‘struct sched_class[44343134792571037]’
[-Werror=array-bounds]
2197 | #define sched_class_lowest (__begin_sched_classes - 1)
| ^
kernel/sched/sched.h:2200:41: note: in definition of macro ‘for_class_range’
2200 | for (class = (_from); class != (_to); class--)
| ^~~
kernel/sched/sched.h:2203:53: note: in expansion of macro ‘sched_class_lowest’
2203 |for_class_range(class, sched_class_highest, sched_class_lowest)
| ^~~~~~~~~~~~~~~~~~
kernel/sched/core.c:9115:17: note: in expansion of macro ‘for_each_class’
9115 | for_each_class(class) {
| ^~~~~~~~~~~~~~
kernel/sched/sched.h:2193:27: note: at offset -208 into object ‘__begin_sched_classes’ of size [0, 9223372036854775807]
2193 | extern struct sched_class __begin_sched_classes[];
| ^~~~~~~~~~~~~~~~~~~~~
Reported-by: Christophe de Dinechin <dinechin@redhat.com>
Link: https://lore.kernel.org/lkml/20220414150855.2407137-2-dinechin@redhat.com/
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
kernel/sched/sched.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 8dccb34eb190..3d31ed9d33fa 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2190,8 +2190,8 @@ const struct sched_class name##_sched_class \
__section("__" #name "_sched_class")
/* Defined in include/asm-generic/vmlinux.lds.h */
-extern struct sched_class __begin_sched_classes[];
-extern struct sched_class __end_sched_classes[];
+extern struct sched_class *__begin_sched_classes;
+extern struct sched_class *__end_sched_classes;
#define sched_class_highest (__end_sched_classes - 1)
#define sched_class_lowest (__begin_sched_classes - 1)
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sched/core: Do not treat class list boundary markers as arrays
2022-05-16 19:42 [PATCH] sched/core: Do not treat class list boundary markers as arrays Kees Cook
@ 2022-05-16 20:44 ` Peter Zijlstra
0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2022-05-16 20:44 UTC (permalink / raw)
To: Kees Cook
Cc: Ingo Molnar, Christophe de Dinechin, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Davidlohr Bueso, linux-kernel,
linux-hardening
On Mon, May 16, 2022 at 12:42:41PM -0700, Kees Cook wrote:
> GCC 12 is very sensitive about array checking, and views all negative
> array accesses as unsafe (a not unreasonable position). Avoid the
> warnings about __begin_sched_classes being accessed via negative bounds
> by converting them to the pointers they actually are. Silences this
> warning:
Yeah, this patch is *much* saner, thanks!
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 8dccb34eb190..3d31ed9d33fa 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2190,8 +2190,8 @@ const struct sched_class name##_sched_class \
> __section("__" #name "_sched_class")
>
> /* Defined in include/asm-generic/vmlinux.lds.h */
> -extern struct sched_class __begin_sched_classes[];
> -extern struct sched_class __end_sched_classes[];
> +extern struct sched_class *__begin_sched_classes;
> +extern struct sched_class *__end_sched_classes;
>
> #define sched_class_highest (__end_sched_classes - 1)
> #define sched_class_lowest (__begin_sched_classes - 1)
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-16 21:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 19:42 [PATCH] sched/core: Do not treat class list boundary markers as arrays Kees Cook
2022-05-16 20:44 ` Peter Zijlstra
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).