[PATCH v2 5/7] mm/page_alloc: Add __alloc_size attributes for better bounds checking

From
Kees Cook <hidden>
Date
2021-08-18 21:40:56
Also in
linux-hardening, linux-kbuild, lkml
Reply to
Kees Cook, 2021-08-18
As already done in GrapheneOS, add the __alloc_size attribute for
appropriate page allocator interfaces, to provide additional hinting
for better bounds checking, assisting CONFIG_FORTIFY_SOURCE and other
compiler optimizations.

Co-developed-by: Daniel Micay <redacted>
Signed-off-by: Daniel Micay <redacted>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: <redacted>
Signed-off-by: Kees Cook <redacted>
---
 include/linux/gfp.h | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 3745efd21cf6..897538d5ffd2 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -618,8 +618,10 @@ static inline struct folio *folio_alloc(gfp_t gfp, unsigned int order)
 extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order);
 extern unsigned long get_zeroed_page(gfp_t gfp_mask);
 
+__alloc_size(1)
 void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
 void free_pages_exact(void *virt, size_t size);
+__alloc_size(1)
 void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
 
 #define __get_free_page(gfp_mask) \
-- 
2.30.2

Thread (20 messages) 20 messages, 7 authors, last reply 2021-09-22
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help