* [PATCH] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by
@ 2023-10-06 20:17 Kees Cook
2023-10-06 20:46 ` Gustavo A. R. Silva
2023-10-08 10:22 ` [tip: perf/core] perf/x86/rapl: Annotate 'struct rapl_pmus' " tip-bot2 for Kees Cook
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-06 20:17 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Kees Cook, Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Ian Rogers,
Adrian Hunter, Thomas Gleixner, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Gustavo A. R. Silva, linux-perf-users,
linux-hardening, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, llvm
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct rapl_pmus.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/x86/events/rapl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index c2c37fb0a228..8d98d468b976 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -115,7 +115,7 @@ struct rapl_pmu {
struct rapl_pmus {
struct pmu pmu;
unsigned int maxdie;
- struct rapl_pmu *pmus[];
+ struct rapl_pmu *pmus[] __counted_by(maxdie);
};
enum rapl_unit_quirk {
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by
2023-10-06 20:17 [PATCH] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by Kees Cook
@ 2023-10-06 20:46 ` Gustavo A. R. Silva
2023-10-08 10:22 ` [tip: perf/core] perf/x86/rapl: Annotate 'struct rapl_pmus' " tip-bot2 for Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-06 20:46 UTC (permalink / raw)
To: Kees Cook, Peter Zijlstra
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Ian Rogers,
Adrian Hunter, Thomas Gleixner, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Gustavo A. R. Silva, linux-perf-users,
linux-hardening, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, llvm
On 10/6/23 22:17, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct rapl_pmus.
>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: x86@kernel.org
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-perf-users@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> arch/x86/events/rapl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
> index c2c37fb0a228..8d98d468b976 100644
> --- a/arch/x86/events/rapl.c
> +++ b/arch/x86/events/rapl.c
> @@ -115,7 +115,7 @@ struct rapl_pmu {
> struct rapl_pmus {
> struct pmu pmu;
> unsigned int maxdie;
> - struct rapl_pmu *pmus[];
> + struct rapl_pmu *pmus[] __counted_by(maxdie);
> };
>
> enum rapl_unit_quirk {
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: perf/core] perf/x86/rapl: Annotate 'struct rapl_pmus' with __counted_by
2023-10-06 20:17 [PATCH] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by Kees Cook
2023-10-06 20:46 ` Gustavo A. R. Silva
@ 2023-10-08 10:22 ` tip-bot2 for Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Kees Cook @ 2023-10-08 10:22 UTC (permalink / raw)
To: linux-tip-commits
Cc: Kees Cook, Ingo Molnar, Gustavo A. R. Silva, x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: a56d5551e1993ca84dd0c69df5a3d8223d13fb5f
Gitweb: https://git.kernel.org/tip/a56d5551e1993ca84dd0c69df5a3d8223d13fb5f
Author: Kees Cook <keescook@chromium.org>
AuthorDate: Fri, 06 Oct 2023 13:17:54 -07:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 08 Oct 2023 12:18:17 +02:00
perf/x86/rapl: Annotate 'struct rapl_pmus' with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS=y (for
array indexing) and CONFIG_FORTIFY_SOURCE=y (for strcpy/memcpy-family
functions).
Found with Coccinelle:
https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Add __counted_by for 'struct rapl_pmus'.
No change in functionality intended.
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20231006201754.work.473-kees@kernel.org
---
arch/x86/events/rapl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index c2c37fb..8d98d46 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -115,7 +115,7 @@ struct rapl_pmu {
struct rapl_pmus {
struct pmu pmu;
unsigned int maxdie;
- struct rapl_pmu *pmus[];
+ struct rapl_pmu *pmus[] __counted_by(maxdie);
};
enum rapl_unit_quirk {
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-08 10:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-06 20:17 [PATCH] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by Kees Cook
2023-10-06 20:46 ` Gustavo A. R. Silva
2023-10-08 10:22 ` [tip: perf/core] perf/x86/rapl: Annotate 'struct rapl_pmus' " tip-bot2 for Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox