History

audit: use struct_size() helper in kmalloc()

Make use of struct_size() helper instead of an open-coded calucation.

Xiu Jianfeng committed 4 years ago

Commit bc6e60a1 parent fa55b7d3 files · +3 −3Browse files

Unified · Split

3 files
  1. kernel/audit.c +1 −1
  2. kernel/audit_tree.c +1 −1
  3. kernel/auditfilter.c +1 −1
kernel/audit.c+1−1
@@ -1446,7 +1446,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 1445 unmodified lines
14461446 if (err)
14471447 return err;
14481448 }
1449− sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);
1449+ sig_data = kmalloc(struct_size(sig_data, ctx, len), GFP_KERNEL);
14501450 if (!sig_data) {
14511451 if (audit_sig_sid)
14521452 security_release_secctx(ctx, len);
kernel/audit_tree.c+1−1
@@ -94,7 +94,7 @@ static struct audit_tree *alloc_tree(const char *s) · 93 unmodified lines
9494 {
9595 struct audit_tree *tree;
9696
97− tree = kmalloc(sizeof(struct audit_tree) + strlen(s) + 1, GFP_KERNEL);
97+ tree = kmalloc(struct_size(tree, pathname, strlen(s) + 1), GFP_KERNEL);
9898 if (tree) {
9999 refcount_set(&tree->count, 1);
100100 tree->goner = 0;
kernel/auditfilter.c+1−1
@@ -637,7 +637,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) · 636 unmodified lines
637637 void *bufp;
638638 int i;
639639
640− data = kmalloc(sizeof(*data) + krule->buflen, GFP_KERNEL);
640+ data = kmalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
641641 if (unlikely(!data))
642642 return NULL;
643643 memset(data, 0, sizeof(*data));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t