Skip to content

Commit 9d96098

Browse files
eparisAl Viro
authored andcommitted
Audit: clean up all op= output to include string quoting
A number of places in the audit system we send an op= followed by a string that includes spaces. Somehow this works but it's just wrong. This patch moves all of those that I could find to be quoted. Example: Change From: type=CONFIG_CHANGE msg=audit(1244666690.117:31): auid=0 ses=1 subj=unconfined_u:unconfined_r:auditctl_t:s0-s0:c0.c1023 op=remove rule key="number2" list=4 res=0 Change To: type=CONFIG_CHANGE msg=audit(1244666690.117:31): auid=0 ses=1 subj=unconfined_u:unconfined_r:auditctl_t:s0-s0:c0.c1023 op="remove rule" key="number2" list=4 res=0 Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 35fe4d0 commit 9d96098

6 files changed

Lines changed: 24 additions & 24 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ extern void audit_log_untrustedstring(struct audit_buffer *ab,
599599
extern void audit_log_d_path(struct audit_buffer *ab,
600600
const char *prefix,
601601
struct path *path);
602+
extern void audit_log_key(struct audit_buffer *ab,
603+
char *key);
602604
extern void audit_log_lost(const char *message);
603605
extern int audit_update_lsm_rules(void);
604606

@@ -621,6 +623,7 @@ extern int audit_enabled;
621623
#define audit_log_n_untrustedstring(a,n,s) do { ; } while (0)
622624
#define audit_log_untrustedstring(a,s) do { ; } while (0)
623625
#define audit_log_d_path(b, p, d) do { ; } while (0)
626+
#define audit_log_key(b, k) do { ; } while (0)
624627
#define audit_enabled 0
625628
#endif
626629
#endif

‎kernel/audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,15 @@ void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
14501450
kfree(pathname);
14511451
}
14521452

1453+
void audit_log_key(struct audit_buffer *ab, char *key)
1454+
{
1455+
audit_log_format(ab, " key=");
1456+
if (key)
1457+
audit_log_untrustedstring(ab, key);
1458+
else
1459+
audit_log_format(ab, "(null)");
1460+
}
1461+
14531462
/**
14541463
* audit_log_end - end one audit record
14551464
* @ab: the audit_buffer

‎kernel/audit_tree.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,11 @@ static void kill_rules(struct audit_tree *tree)
441441
if (rule->tree) {
442442
/* not a half-baked one */
443443
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
444-
audit_log_format(ab, "op=remove rule dir=");
444+
audit_log_format(ab, "op=");
445+
audit_log_string(ab, "remove rule");
446+
audit_log_format(ab, " dir=");
445447
audit_log_untrustedstring(ab, rule->tree->pathname);
446-
if (rule->filterkey) {
447-
audit_log_format(ab, " key=");
448-
audit_log_untrustedstring(ab, rule->filterkey);
449-
} else
450-
audit_log_format(ab, " key=(null)");
448+
audit_log_key(ab, rule->filterkey);
451449
audit_log_format(ab, " list=%d res=1", rule->listnr);
452450
audit_log_end(ab);
453451
rule->tree = NULL;

‎kernel/audit_watch.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watc
234234
audit_log_string(ab, op);
235235
audit_log_format(ab, " path=");
236236
audit_log_untrustedstring(ab, w->path);
237-
if (r->filterkey) {
238-
audit_log_format(ab, " key=");
239-
audit_log_untrustedstring(ab, r->filterkey);
240-
} else
241-
audit_log_format(ab, " key=(null)");
237+
audit_log_key(ab, r->filterkey);
242238
audit_log_format(ab, " list=%d res=1", r->listnr);
243239
audit_log_end(ab);
244240
}

‎kernel/auditfilter.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,9 @@ static void audit_log_rule_change(uid_t loginuid, u32 sessionid, u32 sid,
10791079
security_release_secctx(ctx, len);
10801080
}
10811081
}
1082-
audit_log_format(ab, " op=%s rule key=", action);
1083-
if (rule->filterkey)
1084-
audit_log_untrustedstring(ab, rule->filterkey);
1085-
else
1086-
audit_log_format(ab, "(null)");
1082+
audit_log_format(ab, " op=");
1083+
audit_log_string(ab, action);
1084+
audit_log_key(ab, rule->filterkey);
10871085
audit_log_format(ab, " list=%d res=%d", rule->listnr, res);
10881086
audit_log_end(ab);
10891087
}
@@ -1147,7 +1145,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
11471145
return PTR_ERR(entry);
11481146

11491147
err = audit_add_rule(entry);
1150-
audit_log_rule_change(loginuid, sessionid, sid, "add",
1148+
audit_log_rule_change(loginuid, sessionid, sid, "add rule",
11511149
&entry->rule, !err);
11521150

11531151
if (err)
@@ -1163,7 +1161,7 @@ int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
11631161
return PTR_ERR(entry);
11641162

11651163
err = audit_del_rule(entry);
1166-
audit_log_rule_change(loginuid, sessionid, sid, "remove",
1164+
audit_log_rule_change(loginuid, sessionid, sid, "remove rule",
11671165
&entry->rule, !err);
11681166

11691167
audit_free_rule(entry);

‎kernel/auditsc.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ static int audit_log_single_execve_arg(struct audit_context *context,
11371137
if (has_cntl)
11381138
audit_log_n_hex(*ab, buf, to_send);
11391139
else
1140-
audit_log_format(*ab, "\"%s\"", buf);
1140+
audit_log_string(*ab, buf);
11411141

11421142
p += to_send;
11431143
len_left -= to_send;
@@ -1372,11 +1372,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
13721372

13731373

13741374
audit_log_task_info(ab, tsk);
1375-
if (context->filterkey) {
1376-
audit_log_format(ab, " key=");
1377-
audit_log_untrustedstring(ab, context->filterkey);
1378-
} else
1379-
audit_log_format(ab, " key=(null)");
1375+
audit_log_key(ab, context->filterkey);
13801376
audit_log_end(ab);
13811377

13821378
for (aux = context->aux; aux; aux = aux->next) {

0 commit comments

Comments
 (0)