Skip to content

Commit 0eae328

Browse files
committed
Merge tag 'audit-pr-20251201' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit
Pull audit updates from Paul Moore: - Consolidate the loops in __audit_inode_child() to improve performance When logging a child inode in __audit_inode_child(), we first run through the list of recorded inodes looking for the parent and then we repeat the search looking for a matching child entry. This pull request consolidates both searches into one pass through the recorded inodes, resuling in approximately a 50% reduction in audit overhead. See the commit description for the testing details. - Combine kmalloc()/memset() into kzalloc() in audit_krule_to_data() - Comment fixes * tag 'audit-pr-20251201' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit: audit: merge loops in __audit_inode_child() audit: Use kzalloc() instead of kmalloc()/memset() in audit_krule_to_data() audit: fix comment misindentation in audit.h
2 parents 51e3b98 + c8a3dfe commit 0eae328

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

kernel/audit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct audit_context {
138138
struct audit_aux_data *aux_pids;
139139
struct sockaddr_storage *sockaddr;
140140
size_t sockaddr_len;
141-
/* Save things to print about task_struct */
141+
/* Save things to print about task_struct */
142142
pid_t ppid;
143143
kuid_t uid, euid, suid, fsuid;
144144
kgid_t gid, egid, sgid, fsgid;

kernel/auditfilter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,9 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
638638
void *bufp;
639639
int i;
640640

641-
data = kmalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
641+
data = kzalloc(struct_size(data, buf, krule->buflen), GFP_KERNEL);
642642
if (unlikely(!data))
643643
return NULL;
644-
memset(data, 0, sizeof(*data));
645644

646645
data->flags = krule->flags | krule->listnr;
647646
data->action = krule->action;

kernel/auditsc.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,41 +2416,36 @@ void __audit_inode_child(struct inode *parent,
24162416
if (inode)
24172417
handle_one(inode);
24182418

2419-
/* look for a parent entry first */
24202419
list_for_each_entry(n, &context->names_list, list) {
2421-
if (!n->name ||
2422-
(n->type != AUDIT_TYPE_PARENT &&
2423-
n->type != AUDIT_TYPE_UNKNOWN))
2420+
/* can only match entries that have a name */
2421+
if (!n->name)
24242422
continue;
24252423

2426-
if (n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
2427-
!audit_compare_dname_path(dname,
2428-
n->name->name, n->name_len)) {
2429-
if (n->type == AUDIT_TYPE_UNKNOWN)
2430-
n->type = AUDIT_TYPE_PARENT;
2424+
/* look for a parent entry first */
2425+
if (!found_parent &&
2426+
(n->type == AUDIT_TYPE_PARENT || n->type == AUDIT_TYPE_UNKNOWN) &&
2427+
(n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
2428+
!audit_compare_dname_path(dname, n->name->name, n->name_len))) {
2429+
n->type = AUDIT_TYPE_PARENT;
24312430
found_parent = n;
2432-
break;
2433-
}
2434-
}
2435-
2436-
cond_resched();
2437-
2438-
/* is there a matching child entry? */
2439-
list_for_each_entry(n, &context->names_list, list) {
2440-
/* can only match entries that have a name */
2441-
if (!n->name ||
2442-
(n->type != type && n->type != AUDIT_TYPE_UNKNOWN))
2431+
if (found_child)
2432+
break;
24432433
continue;
2434+
}
24442435

2445-
if (!strcmp(dname->name, n->name->name) ||
2446-
!audit_compare_dname_path(dname, n->name->name,
2436+
/* is there a matching child entry? */
2437+
if (!found_child &&
2438+
(n->type == type || n->type == AUDIT_TYPE_UNKNOWN) &&
2439+
(!strcmp(dname->name, n->name->name) ||
2440+
!audit_compare_dname_path(dname, n->name->name,
24472441
found_parent ?
24482442
found_parent->name_len :
2449-
AUDIT_NAME_FULL)) {
2443+
AUDIT_NAME_FULL))) {
24502444
if (n->type == AUDIT_TYPE_UNKNOWN)
24512445
n->type = type;
24522446
found_child = n;
2453-
break;
2447+
if (found_parent)
2448+
break;
24542449
}
24552450
}
24562451

0 commit comments

Comments
 (0)