Skip to content

Commit

Permalink
apparmor: Use struct_size() helper in kzalloc()
Browse files Browse the repository at this point in the history
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: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: John Johansen <john.johansen@canonical.com>
  • Loading branch information
Gustavo A. R. Silva authored and John Johansen committed Nov 3, 2021
1 parent 4d47fbb commit f4a2d28
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions security/apparmor/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
AA_BUG(size < 1);

/* + 1 for null terminator entry on vec */
new = kzalloc(sizeof(*new) + sizeof(struct aa_profile *) * (size + 1),
gfp);
new = kzalloc(struct_size(new, vec, size + 1), gfp);
AA_DEBUG("%s (%p)\n", __func__, new);
if (!new)
goto fail;
Expand Down
3 changes: 1 addition & 2 deletions security/apparmor/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
struct aa_profile *profile;

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

Expand Down

0 comments on commit f4a2d28

Please sign in to comment.