Skip to content

Commit aa7c043

Browse files
rgbriggspcmoore
authored andcommitted
audit: eliminate unnecessary extra layer of watch parent references
The audit watch parent count was imbalanced, adding an unnecessary layer of watch parent references. Decrement the additional parent reference when a watch is reused, already having a reference to the parent. audit_find_parent() gets a reference to the parent, if the parent is already known. This additional parental reference is not needed if the watch is subsequently found by audit_add_to_parent(), and consumed if the watch does not already exist, so we need to put the parent if the watch is found, and do nothing if this new watch is added to the parent. If the parent wasn't already known, it is created with a refcount of 1 and added to the audit_watch_group, then incremented by one to be subsequently consumed by the newly created watch in audit_add_to_parent(). The rule points to the watch, not to the parent, so the rule's refcount gets bumped, not the parent's. See LKML, 2015-07-16 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <pmoore@redhat.com>
1 parent f8259b2 commit aa7c043

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎kernel/audit_watch.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,12 @@ static void audit_add_to_parent(struct audit_krule *krule,
391391

392392
audit_get_watch(w);
393393
krule->watch = watch = w;
394+
395+
audit_put_parent(parent);
394396
break;
395397
}
396398

397399
if (!watch_found) {
398-
audit_get_parent(parent);
399400
watch->parent = parent;
400401

401402
audit_get_watch(watch);
@@ -436,9 +437,6 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
436437

437438
audit_add_to_parent(krule, parent);
438439

439-
/* match get in audit_find_parent or audit_init_parent */
440-
audit_put_parent(parent);
441-
442440
h = audit_hash_ino((u32)watch->ino);
443441
*list = &audit_inode_hash[h];
444442
error:

0 commit comments

Comments
 (0)