Skip to contentSkip to conversation

perf/x86/rapl: Annotate struct rapl_pmus with __counted_by

PATCH Applied Kees Cook 3 participants 3 messages Oct 6, 2023 – Oct 8, 2023

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 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 (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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Adrian Hunter <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 arch/x86/events/rapl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/rapl.c +1 -1
index c2c37fb0a228..8d98d468b976 100644
@@ -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 {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Kees Cook

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 <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Adrian Hunter <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Borislav Petkov <[email protected]>
Quoted 8 lines

Thanks!

Signature · 1 line
Gustavo
Quoted 17 lines
---
  arch/x86/events/rapl.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/rapl.c +1 -1
index c2c37fb0a228..8d98d468b976 100644
@@ -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 {
merge bot Applied
#2 lore raw

[tip: perf/core] perf/x86/rapl: Annotate 'struct rapl_pmus' with __counted_by

In reply to Kees Cook
The following commit has been merged into the perf/core branch of tip:

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 <[email protected]>
AuthorDate:    Fri, 06 Oct 2023 13:17:54 -07:00
Committer:     Ingo Molnar <[email protected]>
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.

---
 arch/x86/events/rapl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/rapl.c +1 -1
index c2c37fb..8d98d46 100644
@@ -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 {