Skip to content

Commit

Permalink
audit: use struct_size() helper in kmalloc()
Browse files Browse the repository at this point in the history
Make use of struct_size() helper instead of an open-coded calucation.

Link: KSPP/linux#160
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Xiu Jianfeng authored and pcmoore committed Dec 14, 2021
1 parent fa55b7d commit bc6e60a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
if (err)
return err;
}
sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);
sig_data = kmalloc(struct_size(sig_data, ctx, len), GFP_KERNEL);
if (!sig_data) {
if (audit_sig_sid)
security_release_secctx(ctx, len);
Expand Down
2 changes: 1 addition & 1 deletion kernel/audit_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static struct audit_tree *alloc_tree(const char *s)
{
struct audit_tree *tree;

tree = kmalloc(sizeof(struct audit_tree) + strlen(s) + 1, GFP_KERNEL);
tree = kmalloc(struct_size(tree, pathname, strlen(s) + 1), GFP_KERNEL);
if (tree) {
refcount_set(&tree->count, 1);
tree->goner = 0;
Expand Down
2 changes: 1 addition & 1 deletion kernel/auditfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
void *bufp;
int i;

data = kmalloc(sizeof(*data) + krule->buflen, GFP_KERNEL);
data = kmalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
if (unlikely(!data))
return NULL;
memset(data, 0, sizeof(*data));
Expand Down

0 comments on commit bc6e60a

Please sign in to comment.