Skip to content

Commit e85188f

Browse files
eparisAl Viro
authored andcommitted
Audit: dereferencing krule as if it were an audit_watch
audit_update_watch() runs all of the rules for a given watch and duplicates them, attaches a new watch to them, and then when it finishes that process and has called free on all of the old rules (ok maybe still inside the rcu grace period) it proceeds to use the last element from list_for_each_entry_safe() as if it were a krule rather than being the audit_watch which was anchoring the list to output a message about audit rules changing. This patch unfies the audit message from two different places into a helper function and calls it from the correct location in audit_update_rules(). We will now get an audit message about the config changing for each rule (with each rules filterkey) rather than the previous garbage. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent b87ce6e commit e85188f

1 file changed

Lines changed: 24 additions & 34 deletions

File tree

‎kernel/auditfilter.c‎

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,27 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old,
977977
return entry;
978978
}
979979

980+
static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watch *w, char *op)
981+
{
982+
if (audit_enabled) {
983+
struct audit_buffer *ab;
984+
ab = audit_log_start(NULL, GFP_NOFS, AUDIT_CONFIG_CHANGE);
985+
audit_log_format(ab, "auid=%u ses=%u op=",
986+
audit_get_loginuid(current),
987+
audit_get_sessionid(current));
988+
audit_log_string(ab, op);
989+
audit_log_format(ab, " path=");
990+
audit_log_untrustedstring(ab, w->path);
991+
if (r->filterkey) {
992+
audit_log_format(ab, " key=");
993+
audit_log_untrustedstring(ab, r->filterkey);
994+
} else
995+
audit_log_format(ab, " key=(null)");
996+
audit_log_format(ab, " list=%d res=1", r->listnr);
997+
audit_log_end(ab);
998+
}
999+
}
1000+
9801001
/* Update inode info in audit rules based on filesystem event. */
9811002
static void audit_update_watch(struct audit_parent *parent,
9821003
const char *dname, dev_t dev,
@@ -1023,24 +1044,11 @@ static void audit_update_watch(struct audit_parent *parent,
10231044
&nentry->rule.list);
10241045
}
10251046

1047+
audit_watch_log_rule_change(r, owatch, "updated rules");
1048+
10261049
call_rcu(&oentry->rcu, audit_free_rule_rcu);
10271050
}
10281051

1029-
if (audit_enabled) {
1030-
struct audit_buffer *ab;
1031-
ab = audit_log_start(NULL, GFP_NOFS,
1032-
AUDIT_CONFIG_CHANGE);
1033-
audit_log_format(ab, "auid=%u ses=%u",
1034-
audit_get_loginuid(current),
1035-
audit_get_sessionid(current));
1036-
audit_log_format(ab,
1037-
" op=updated rules specifying path=");
1038-
audit_log_untrustedstring(ab, owatch->path);
1039-
audit_log_format(ab, " with dev=%u ino=%lu\n",
1040-
dev, ino);
1041-
audit_log_format(ab, " list=%d res=1", r->listnr);
1042-
audit_log_end(ab);
1043-
}
10441052
audit_remove_watch(owatch);
10451053
goto add_watch_to_parent; /* event applies to a single watch */
10461054
}
@@ -1065,25 +1073,7 @@ static void audit_remove_parent_watches(struct audit_parent *parent)
10651073
list_for_each_entry_safe(w, nextw, &parent->watches, wlist) {
10661074
list_for_each_entry_safe(r, nextr, &w->rules, rlist) {
10671075
e = container_of(r, struct audit_entry, rule);
1068-
if (audit_enabled) {
1069-
struct audit_buffer *ab;
1070-
ab = audit_log_start(NULL, GFP_NOFS,
1071-
AUDIT_CONFIG_CHANGE);
1072-
audit_log_format(ab, "auid=%u ses=%u",
1073-
audit_get_loginuid(current),
1074-
audit_get_sessionid(current));
1075-
audit_log_format(ab, " op=remove rule path=");
1076-
audit_log_untrustedstring(ab, w->path);
1077-
if (r->filterkey) {
1078-
audit_log_format(ab, " key=");
1079-
audit_log_untrustedstring(ab,
1080-
r->filterkey);
1081-
} else
1082-
audit_log_format(ab, " key=(null)");
1083-
audit_log_format(ab, " list=%d res=1",
1084-
r->listnr);
1085-
audit_log_end(ab);
1086-
}
1076+
audit_watch_log_rule_change(r, w, "remove rule");
10871077
list_del(&r->rlist);
10881078
list_del(&r->list);
10891079
list_del_rcu(&e->list);

0 commit comments

Comments
 (0)