Skip to content

Commit f8259b2

Browse files
rgbriggspcmoore
authored andcommitted
audit: eliminate unnecessary extra layer of watch references
The audit watch count was imbalanced, adding an unnecessary layer of watch references. Only add the second reference when it is added to a parent. Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <pmoore@redhat.com>
1 parent 0b08c5e commit f8259b2

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

‎kernel/audit_watch.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ int audit_to_watch(struct audit_krule *krule, char *path, int len, u32 op)
203203
if (IS_ERR(watch))
204204
return PTR_ERR(watch);
205205

206-
audit_get_watch(watch);
207206
krule->watch = watch;
208207

209208
return 0;
@@ -387,8 +386,7 @@ static void audit_add_to_parent(struct audit_krule *krule,
387386

388387
watch_found = 1;
389388

390-
/* put krule's and initial refs to temporary watch */
391-
audit_put_watch(watch);
389+
/* put krule's ref to temporary watch */
392390
audit_put_watch(watch);
393391

394392
audit_get_watch(w);
@@ -400,6 +398,7 @@ static void audit_add_to_parent(struct audit_krule *krule,
400398
audit_get_parent(parent);
401399
watch->parent = parent;
402400

401+
audit_get_watch(watch);
403402
list_add(&watch->wlist, &parent->watches);
404403
}
405404
list_add(&krule->rlist, &watch->rules);

‎kernel/auditfilter.c‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,6 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
549549
return entry;
550550

551551
exit_free:
552-
if (entry->rule.watch)
553-
audit_put_watch(entry->rule.watch); /* matches initial get */
554552
if (entry->rule.tree)
555553
audit_put_tree(entry->rule.tree); /* that's the temporary one */
556554
audit_free_rule(entry);
@@ -881,7 +879,7 @@ static inline int audit_add_rule(struct audit_entry *entry)
881879
/* normally audit_add_tree_rule() will free it on failure */
882880
if (tree)
883881
audit_put_tree(tree);
884-
goto error;
882+
return err;
885883
}
886884

887885
if (watch) {
@@ -895,14 +893,14 @@ static inline int audit_add_rule(struct audit_entry *entry)
895893
*/
896894
if (tree)
897895
audit_put_tree(tree);
898-
goto error;
896+
return err;
899897
}
900898
}
901899
if (tree) {
902900
err = audit_add_tree_rule(&entry->rule);
903901
if (err) {
904902
mutex_unlock(&audit_filter_mutex);
905-
goto error;
903+
return err;
906904
}
907905
}
908906

@@ -933,19 +931,13 @@ static inline int audit_add_rule(struct audit_entry *entry)
933931
#endif
934932
mutex_unlock(&audit_filter_mutex);
935933

936-
return 0;
937-
938-
error:
939-
if (watch)
940-
audit_put_watch(watch); /* tmp watch, matches initial get */
941934
return err;
942935
}
943936

944937
/* Remove an existing rule from filterlist. */
945938
static inline int audit_del_rule(struct audit_entry *entry)
946939
{
947940
struct audit_entry *e;
948-
struct audit_watch *watch = entry->rule.watch;
949941
struct audit_tree *tree = entry->rule.tree;
950942
struct list_head *list;
951943
int ret = 0;
@@ -986,8 +978,6 @@ static inline int audit_del_rule(struct audit_entry *entry)
986978
mutex_unlock(&audit_filter_mutex);
987979

988980
out:
989-
if (watch)
990-
audit_put_watch(watch); /* match initial get */
991981
if (tree)
992982
audit_put_tree(tree); /* that's the temporary one */
993983

0 commit comments

Comments
 (0)