Skip to content

Commit 626abcd

Browse files
rgbriggspcmoore
authored andcommitted
audit: add syscall information to CONFIG_CHANGE records
Tie syscall information to all CONFIG_CHANGE calls since they are all a result of user actions. Exclude user records from syscall context: Since the function audit_log_common_recv_msg() is shared by a number of AUDIT_CONFIG_CHANGE and the entire range of AUDIT_USER_* record types, and since the AUDIT_CONFIG_CHANGE message type has been converted to a syscall accompanied record type, special-case the AUDIT_USER_* range of messages so they remain standalone records. See: linux-audit/audit-kernel#59 See: linux-audit/audit-kernel#50 Signed-off-by: Richard Guy Briggs <rgb@redhat.com> [PM: fix line lengths in kernel/audit.c] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 9e36a5d commit 626abcd

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎kernel/audit.c‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old,
396396
struct audit_buffer *ab;
397397
int rc = 0;
398398

399-
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
399+
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONFIG_CHANGE);
400400
if (unlikely(!ab))
401401
return rc;
402402
audit_log_format(ab, "op=set %s=%u old=%u ", function_name, new, old);
@@ -1053,7 +1053,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
10531053
return err;
10541054
}
10551055

1056-
static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
1056+
static void audit_log_common_recv_msg(struct audit_context *context,
1057+
struct audit_buffer **ab, u16 msg_type)
10571058
{
10581059
uid_t uid = from_kuid(&init_user_ns, current_uid());
10591060
pid_t pid = task_tgid_nr(current);
@@ -1063,14 +1064,20 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)
10631064
return;
10641065
}
10651066

1066-
*ab = audit_log_start(NULL, GFP_KERNEL, msg_type);
1067+
*ab = audit_log_start(context, GFP_KERNEL, msg_type);
10671068
if (unlikely(!*ab))
10681069
return;
10691070
audit_log_format(*ab, "pid=%d uid=%u ", pid, uid);
10701071
audit_log_session_info(*ab);
10711072
audit_log_task_context(*ab);
10721073
}
10731074

1075+
static inline void audit_log_user_recv_msg(struct audit_buffer **ab,
1076+
u16 msg_type)
1077+
{
1078+
audit_log_common_recv_msg(NULL, ab, msg_type);
1079+
}
1080+
10741081
int is_audit_feature_set(int i)
10751082
{
10761083
return af.features & AUDIT_FEATURE_TO_MASK(i);
@@ -1338,7 +1345,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
13381345
if (err)
13391346
break;
13401347
}
1341-
audit_log_common_recv_msg(&ab, msg_type);
1348+
audit_log_user_recv_msg(&ab, msg_type);
13421349
if (msg_type != AUDIT_USER_TTY)
13431350
audit_log_format(ab, " msg='%.*s'",
13441351
AUDIT_MESSAGE_TEXT_MAX,
@@ -1361,7 +1368,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
13611368
if (nlmsg_len(nlh) < sizeof(struct audit_rule_data))
13621369
return -EINVAL;
13631370
if (audit_enabled == AUDIT_LOCKED) {
1364-
audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE);
1371+
audit_log_common_recv_msg(audit_context(), &ab,
1372+
AUDIT_CONFIG_CHANGE);
13651373
audit_log_format(ab, " op=%s audit_enabled=%d res=0",
13661374
msg_type == AUDIT_ADD_RULE ?
13671375
"add_rule" : "remove_rule",
@@ -1376,7 +1384,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
13761384
break;
13771385
case AUDIT_TRIM:
13781386
audit_trim_trees();
1379-
audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE);
1387+
audit_log_common_recv_msg(audit_context(), &ab,
1388+
AUDIT_CONFIG_CHANGE);
13801389
audit_log_format(ab, " op=trim res=1");
13811390
audit_log_end(ab);
13821391
break;
@@ -1406,8 +1415,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
14061415
/* OK, here comes... */
14071416
err = audit_tag_tree(old, new);
14081417

1409-
audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE);
1410-
1418+
audit_log_common_recv_msg(audit_context(), &ab,
1419+
AUDIT_CONFIG_CHANGE);
14111420
audit_log_format(ab, " op=make_equiv old=");
14121421
audit_log_untrustedstring(ab, old);
14131422
audit_log_format(ab, " new=");
@@ -1474,7 +1483,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
14741483
old.enabled = t & AUDIT_TTY_ENABLE;
14751484
old.log_passwd = !!(t & AUDIT_TTY_LOG_PASSWD);
14761485

1477-
audit_log_common_recv_msg(&ab, AUDIT_CONFIG_CHANGE);
1486+
audit_log_common_recv_msg(audit_context(), &ab,
1487+
AUDIT_CONFIG_CHANGE);
14781488
audit_log_format(ab, " op=tty_set old-enabled=%d new-enabled=%d"
14791489
" old-log_passwd=%d new-log_passwd=%d res=%d",
14801490
old.enabled, s.enabled, old.log_passwd,

‎kernel/audit_fsnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void audit_mark_log_rule_change(struct audit_fsnotify_mark *audit_mark, c
127127

128128
if (!audit_enabled)
129129
return;
130-
ab = audit_log_start(NULL, GFP_NOFS, AUDIT_CONFIG_CHANGE);
130+
ab = audit_log_start(audit_context(), GFP_NOFS, AUDIT_CONFIG_CHANGE);
131131
if (unlikely(!ab))
132132
return;
133133
audit_log_session_info(ab);

‎kernel/audit_watch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watc
242242

243243
if (!audit_enabled)
244244
return;
245-
ab = audit_log_start(NULL, GFP_NOFS, AUDIT_CONFIG_CHANGE);
245+
ab = audit_log_start(audit_context(), GFP_NOFS, AUDIT_CONFIG_CHANGE);
246246
if (!ab)
247247
return;
248248
audit_log_session_info(ab);

‎kernel/auditfilter.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re
10911091
if (!audit_enabled)
10921092
return;
10931093

1094-
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
1094+
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONFIG_CHANGE);
10951095
if (!ab)
10961096
return;
10971097
audit_log_session_info(ab);

0 commit comments

Comments
 (0)