public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/memcg: Annotate struct mem_cgroup_threshold_ary with __counted_by
@ 2023-09-22 17:53 Kees Cook
  2023-09-22 18:25 ` Shakeel Butt
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Kees Cook @ 2023-09-22 17:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kees Cook, Shakeel Butt, Roman Gushchin, Johannes Weiner,
	Michal Hocko, Matthew Wilcox (Oracle), Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Yosry Ahmed, Yu Zhao, Miaohe Lin,
	Yafang Shao, Kefeng Wang, Qi Zheng, linux-kernel, llvm,
	linux-hardening

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 checking 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 mem_cgroup_threshold_ary.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/memcontrol.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 45d0c10e86cc..e0cfab58ab71 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -143,7 +143,7 @@ struct mem_cgroup_threshold_ary {
 	/* Size of entries[] */
 	unsigned int size;
 	/* Array of thresholds */
-	struct mem_cgroup_threshold entries[];
+	struct mem_cgroup_threshold entries[] __counted_by(size);
 };
 
 struct mem_cgroup_thresholds {
-- 
2.34.1


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

end of thread, other threads:[~2023-09-25  7:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-22 17:53 [PATCH] mm/memcg: Annotate struct mem_cgroup_threshold_ary with __counted_by Kees Cook
2023-09-22 18:25 ` Shakeel Butt
2023-09-22 18:32   ` Kees Cook
2023-09-22 19:11 ` Shakeel Butt
2023-09-22 22:25 ` Roman Gushchin
2023-09-23 17:03 ` Gustavo A. R. Silva
2023-09-25  7:09 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox