apparmor: Use struct_size() helper in kmalloc()
Subsystems (2)
PATCH 1/1 apparmor: Use struct_size() helper in kmalloc()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.
Also, address the following sparse warnings:security/apparmor/lib.c:139:23: warning: using sizeof on a flexible structure
--- security/apparmor/lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/lib.c +1 -1
@@ -136,7 +136,7 @@ __counted char *aa_str_alloc(int size, gfp_t gfp) {struct counted_str *str; - str =kmalloc (sizeof (struct counted_str ) + size, gfp); + str =kmalloc (struct_size (str, name, size), gfp);if (!str)return NULL ;
Signature · 1 line
2.27.0
Quoted 9 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows.Also, address the following sparse warnings:
security/apparmor/lib.c:139:23: warning: using sizeof on a flexible structure
thanks, I have pulled this into my tree
Acked-by John Johansen <[email protected]>
Quoted 17 lines
--- security/apparmor/lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/apparmor/lib.c +1
-1@@ -136,7 +136,7 @@ __counted char *aa_str_alloc(int size, gfp_t gfp) {struct counted_str *str; - str =kmalloc (sizeof (struct counted_str ) + size, gfp); + str =kmalloc (struct_size (str, name, size), gfp);if (!str)return NULL ;