Skip to content

Commit f4a2d28

Browse files
GustavoARSilvajrjohansen
authored andcommitted
apparmor: Use struct_size() helper in kzalloc()
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 worse scenario, could lead to heap overflows. Link: KSPP#160 Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 4d47fbb commit f4a2d28

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

security/apparmor/label.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
424424
AA_BUG(size < 1);
425425

426426
/* + 1 for null terminator entry on vec */
427-
new = kzalloc(sizeof(*new) + sizeof(struct aa_profile *) * (size + 1),
428-
gfp);
427+
new = kzalloc(struct_size(new, vec, size + 1), gfp);
429428
AA_DEBUG("%s (%p)\n", __func__, new);
430429
if (!new)
431430
goto fail;

security/apparmor/policy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
259259
struct aa_profile *profile;
260260

261261
/* freed by free_profile - usually through aa_put_profile */
262-
profile = kzalloc(sizeof(*profile) + sizeof(struct aa_profile *) * 2,
263-
gfp);
262+
profile = kzalloc(struct_size(profile, label.vec, 2), gfp);
264263
if (!profile)
265264
return NULL;
266265

0 commit comments

Comments
 (0)