History

Merge tag 'audit-pr-20210629' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit

Pull audit updates from Paul Moore: "Another merge window, another small audit pull request. Four patches in total: one is cosmetic, one removes an unnecessary initialization, one renames some enum values to prevent name collisions, and one converts list_del()/list_add() to list_move(). None of these are earth shattering and all pass the audit-testsuite tests while merging cleanly on top of your tree from earlier today" * tag 'audit-pr-20210629' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit: audit: remove unnecessary 'ret' initialization audit: remove trailing spaces and tabs audit: Use list_move instead of list_del/list_add audit: Rename enum audit_state constants to avoid AUDIT_DISABLED redefinition audit: add blank line after variable declarations

Linus Torvalds committed 5 years ago

Commit 290fe0f2 parents 6bd344e 0ecc6175 files · +53 −37Browse files

Unified · Split

5 files
  1. include/uapi/linux/audit.h +2 −2
  2. kernel/audit.h +5 −5
  3. kernel/audit_tree.c +4 −8
  4. kernel/auditsc.c +42 −21
  5. security/lsm_audit.c +0 −1
include/uapi/linux/audit.h+2−2
@@ -48,7 +48,7 @@ · 47 unmodified lines
4848 * 2500 - 2999 future user space (maybe integrity labels and related events)
4949 *
5050 * Messages from 1000-1199 are bi-directional. 1200-1299 & 2100 - 2999 are
51− * exclusively user space. 1300-2099 is kernel --> user space
51+ * exclusively user space. 1300-2099 is kernel --> user space
5252 * communication.
5353 */
5454 #define AUDIT_GET 1000 /* Get status */
@@ -78,7 +78,7 @@ · 23 unmodified lines
7878 #define AUDIT_LAST_USER_MSG 1199
7979 #define AUDIT_FIRST_USER_MSG2 2100 /* More user space messages */
8080 #define AUDIT_LAST_USER_MSG2 2999
81−
81+
8282 #define AUDIT_DAEMON_START 1200 /* Daemon startup record */
8383 #define AUDIT_DAEMON_END 1201 /* Daemon normal stop record */
8484 #define AUDIT_DAEMON_ABORT 1202 /* Daemon error stop record */
kernel/audit.h+5−5
@@ -1,5 +1,5 @@
11 /* SPDX-License-Identifier: GPL-2.0-or-later */
2−/* audit -- definition of audit_context structure and supporting types
2+/* audit -- definition of audit_context structure and supporting types
33 *
44 * Copyright 2003-2004 Red Hat, Inc.
55 * Copyright 2005 Hewlett-Packard Development Company, L.P.
@@ -21,16 +21,16 @@ · 15 unmodified lines
2121 a per-task filter. At syscall entry, the audit_state is augmented by
2222 the syscall filter. */
2323 enum audit_state {
24− AUDIT_DISABLED, /* Do not create per-task audit_context.
24+ AUDIT_STATE_DISABLED, /* Do not create per-task audit_context.
2525 * No syscall-specific audit records can
2626 * be generated. */
27− AUDIT_BUILD_CONTEXT, /* Create the per-task audit_context,
27+ AUDIT_STATE_BUILD, /* Create the per-task audit_context,
2828 * and fill it in at syscall
2929 * entry time. This makes a full
3030 * syscall record available if some
3131 * other part of the kernel decides it
3232 * should be recorded. */
33− AUDIT_RECORD_CONTEXT /* Create the per-task audit_context,
33+ AUDIT_STATE_RECORD /* Create the per-task audit_context,
3434 * always fill it in at syscall entry
3535 * time, and always write out the audit
3636 * record at syscall exit time. */
@@ -322,7 +322,7 @@ static inline int audit_signal_info_syscall(struct task_struct *t) · 285 unmodified lines
322322 return 0;
323323 }
324324
325−#define audit_filter_inodes(t, c) AUDIT_DISABLED
325+#define audit_filter_inodes(t, c) AUDIT_STATE_DISABLED
326326 #endif /* CONFIG_AUDITSYSCALL */
327327
328328 extern char *audit_unpack_string(void **bufp, size_t *remain, size_t len);
kernel/audit_tree.c+4−8
@@ -689,8 +689,7 @@ void audit_trim_trees(void) · 688 unmodified lines
689689
690690 tree = container_of(cursor.next, struct audit_tree, list);
691691 get_tree(tree);
692− list_del(&cursor);
693− list_add(&cursor, &tree->list);
692+ list_move(&cursor, &tree->list);
694693 mutex_unlock(&audit_filter_mutex);
695694
696695 err = kern_path(tree->pathname, 0, &path);
@@ -899,8 +898,7 @@ int audit_tag_tree(char *old, char *new) · 202 unmodified lines
899898
900899 tree = container_of(cursor.next, struct audit_tree, list);
901900 get_tree(tree);
902− list_del(&cursor);
903− list_add(&cursor, &tree->list);
901+ list_move(&cursor, &tree->list);
904902 mutex_unlock(&audit_filter_mutex);
905903
906904 err = kern_path(tree->pathname, 0, &path2);
@@ -925,8 +923,7 @@ int audit_tag_tree(char *old, char *new) · 18 unmodified lines
925923 mutex_lock(&audit_filter_mutex);
926924 spin_lock(&hash_lock);
927925 if (!tree->goner) {
928− list_del(&tree->list);
929− list_add(&tree->list, &tree_list);
926+ list_move(&tree->list, &tree_list);
930927 }
931928 spin_unlock(&hash_lock);
932929 put_tree(tree);
@@ -937,8 +934,7 @@ int audit_tag_tree(char *old, char *new) · 4 unmodified lines
937934
938935 tree = container_of(barrier.prev, struct audit_tree, list);
939936 get_tree(tree);
940− list_del(&tree->list);
941− list_add(&tree->list, &barrier);
937+ list_move(&tree->list, &barrier);
942938 mutex_unlock(&audit_filter_mutex);
943939
944940 if (!failed) {
kernel/auditsc.c+42−21
@@ -160,6 +160,7 @@ static const struct audit_nfcfgop_tab audit_nfcfgs[] = { · 159 unmodified lines
160160 static int audit_match_perm(struct audit_context *ctx, int mask)
161161 {
162162 unsigned n;
163+
163164 if (unlikely(!ctx))
164165 return 0;
165166 n = ctx->major;
@@ -231,7 +232,7 @@ static void audit_set_auditable(struct audit_context *ctx) · 65 unmodified lines
231232 {
232233 if (!ctx->prio) {
233234 ctx->prio = 1;
234− ctx->current_state = AUDIT_RECORD_CONTEXT;
235+ ctx->current_state = AUDIT_STATE_RECORD;
235236 }
236237 }
237238
@@ -239,6 +240,7 @@ static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) · 1 unmodified line
239240 {
240241 struct audit_tree_refs *p = ctx->trees;
241242 int left = ctx->tree_count;
243+
242244 if (likely(left)) {
243245 p->c[--left] = chunk;
244246 ctx->tree_count = left;
@@ -259,6 +261,7 @@ static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk) · 14 unmodified lines
259261 static int grow_tree_refs(struct audit_context *ctx)
260262 {
261263 struct audit_tree_refs *p = ctx->trees;
264+
262265 ctx->trees = kzalloc(sizeof(struct audit_tree_refs), GFP_KERNEL);
263266 if (!ctx->trees) {
264267 ctx->trees = p;
@@ -277,6 +280,7 @@ static void unroll_tree_refs(struct audit_context *ctx, · 12 unmodified lines
277280 {
278281 struct audit_tree_refs *q;
279282 int n;
283+
280284 if (!p) {
281285 /* we started with empty chain */
282286 p = ctx->first_trees;
@@ -303,6 +307,7 @@ static void unroll_tree_refs(struct audit_context *ctx, · 20 unmodified lines
303307 static void free_tree_refs(struct audit_context *ctx)
304308 {
305309 struct audit_tree_refs *p, *q;
310+
306311 for (p = ctx->first_trees; p; p = q) {
307312 q = p->next;
308313 kfree(p);
@@ -313,6 +318,7 @@ static int match_tree_refs(struct audit_context *ctx, struct audit_tree *tree) · 4 unmodified lines
313318 {
314319 struct audit_tree_refs *p;
315320 int n;
321+
316322 if (!tree)
317323 return 0;
318324 /* full ones */
@@ -337,13 +343,13 @@ static int audit_compare_uid(kuid_t uid, · 18 unmodified lines
337343 {
338344 struct audit_names *n;
339345 int rc;
340−
346+
341347 if (name) {
342348 rc = audit_uid_comparator(uid, f->op, name->uid);
343349 if (rc)
344350 return rc;
345351 }
346−
352+
347353 if (ctx) {
348354 list_for_each_entry(n, &ctx->names_list, list) {
349355 rc = audit_uid_comparator(uid, f->op, n->uid);
@@ -361,13 +367,13 @@ static int audit_compare_gid(kgid_t gid, · 11 unmodified lines
361367 {
362368 struct audit_names *n;
363369 int rc;
364−
370+
365371 if (name) {
366372 rc = audit_gid_comparator(gid, f->op, name->gid);
367373 if (rc)
368374 return rc;
369375 }
370−
376+
371377 if (ctx) {
372378 list_for_each_entry(n, &ctx->names_list, list) {
373379 rc = audit_gid_comparator(gid, f->op, n->gid);
@@ -751,10 +757,10 @@ static int audit_filter_rules(struct task_struct *tsk, · 377 unmodified lines
751757 }
752758 switch (rule->action) {
753759 case AUDIT_NEVER:
754− *state = AUDIT_DISABLED;
760+ *state = AUDIT_STATE_DISABLED;
755761 break;
756762 case AUDIT_ALWAYS:
757− *state = AUDIT_RECORD_CONTEXT;
763+ *state = AUDIT_STATE_RECORD;
758764 break;
759765 }
760766 return 1;
@@ -773,14 +779,14 @@ static enum audit_state audit_filter_task(struct task_struct *tsk, char **key) · 12 unmodified lines
773779 list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) {
774780 if (audit_filter_rules(tsk, &e->rule, NULL, NULL,
775781 &state, true)) {
776− if (state == AUDIT_RECORD_CONTEXT)
782+ if (state == AUDIT_STATE_RECORD)
777783 *key = kstrdup(e->rule.filterkey, GFP_ATOMIC);
778784 rcu_read_unlock();
779785 return state;
780786 }
781787 }
782788 rcu_read_unlock();
783− return AUDIT_BUILD_CONTEXT;
789+ return AUDIT_STATE_BUILD;
784790 }
785791
786792 static int audit_in_mask(const struct audit_krule *rule, unsigned long val)
@@ -802,7 +808,7 @@ static int audit_in_mask(const struct audit_krule *rule, unsigned long val) · 15 unmodified lines
802808 /* At syscall exit time, this filter is called if the audit_state is
803809 * not low enough that auditing cannot take place, but is also not
804810 * high enough that we already know we have to write an audit record
805− * (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
811+ * (i.e., the state is AUDIT_STATE_BUILD).
806812 */
807813 static void audit_filter_syscall(struct task_struct *tsk,
808814 struct audit_context *ctx)
@@ -923,7 +929,7 @@ static inline struct audit_context *audit_alloc_context(enum audit_state state) · 114 unmodified lines
923929 if (!context)
924930 return NULL;
925931 context->state = state;
926− context->prio = state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
932+ context->prio = state == AUDIT_STATE_RECORD ? ~0ULL : 0;
927933 INIT_LIST_HEAD(&context->killed_trees);
928934 INIT_LIST_HEAD(&context->names_list);
929935 context->fds[0] = -1;
@@ -950,7 +956,7 @@ int audit_alloc(struct task_struct *tsk) · 20 unmodified lines
950956 return 0; /* Return if not auditing. */
951957
952958 state = audit_filter_task(tsk, &key);
953− if (state == AUDIT_DISABLED) {
959+ if (state == AUDIT_STATE_DISABLED) {
954960 clear_task_syscall_work(tsk, SYSCALL_AUDIT);
955961 return 0;
956962 }
@@ -1225,6 +1231,7 @@ static void show_special(struct audit_context *context, int *call_panic) · 268 unmodified lines
12251231 switch (context->type) {
12261232 case AUDIT_SOCKETCALL: {
12271233 int nargs = context->socketcall.nargs;
1234+
12281235 audit_log_format(ab, "nargs=%d", nargs);
12291236 for (i = 0; i < nargs; i++)
12301237 audit_log_format(ab, " a%d=%lx", i,
@@ -1240,6 +1247,7 @@ static void show_special(struct audit_context *context, int *call_panic) · 9 unmodified lines
12401247 if (osid) {
12411248 char *ctx = NULL;
12421249 u32 len;
1250+
12431251 if (security_secid_to_secctx(osid, &ctx, &len)) {
12441252 audit_log_format(ab, " osid=%u", osid);
12451253 *call_panic = 1;
@@ -1289,6 +1297,7 @@ static void show_special(struct audit_context *context, int *call_panic) · 43 unmodified lines
12891297 break;
12901298 case AUDIT_MQ_GETSETATTR: {
12911299 struct mq_attr *attr = &context->mq_getsetattr.mqstat;
1300+
12921301 audit_log_format(ab,
12931302 "mqdes=%d mq_flags=0x%lx mq_maxmsg=%ld mq_msgsize=%ld "
12941303 "mq_curmsgs=%ld ",
@@ -1325,6 +1334,7 @@ static void show_special(struct audit_context *context, int *call_panic) · 30 unmodified lines
13251334 static inline int audit_proctitle_rtrim(char *proctitle, int len)
13261335 {
13271336 char *end = proctitle + len - 1;
1337+
13281338 while (end > proctitle && !isprint(*end))
13291339 end--;
13301340
@@ -1513,6 +1523,7 @@ static void audit_log_exit(void) · 182 unmodified lines
15131523
15141524 case AUDIT_BPRM_FCAPS: {
15151525 struct audit_aux_data_bprm_fcaps *axs = (void *)aux;
1526+
15161527 audit_log_format(ab, "fver=%x", axs->fcap_ver);
15171528 audit_log_cap(ab, "fp", &axs->fcap.permitted);
15181529 audit_log_cap(ab, "fi", &axs->fcap.inheritable);
@@ -1628,7 +1639,7 @@ void __audit_free(struct task_struct *tsk) · 109 unmodified lines
16281639
16291640 audit_filter_syscall(tsk, context);
16301641 audit_filter_inodes(tsk, context);
1631− if (context->current_state == AUDIT_RECORD_CONTEXT)
1642+ if (context->current_state == AUDIT_STATE_RECORD)
16321643 audit_log_exit();
16331644 }
16341645
@@ -1647,7 +1658,7 @@ void __audit_free(struct task_struct *tsk) · 12 unmodified lines
16471658 * Fill in audit context at syscall entry. This only happens if the
16481659 * audit context was created when the task was created and the state or
16491660 * filters demand the audit context be built. If the state from the
1650− * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
1661+ * per-task filter or from the per-syscall filter is AUDIT_STATE_RECORD,
16511662 * then the record will be written at syscall exit time (otherwise, it
16521663 * will only be written if another part of the kernel requests that it
16531664 * be written).
@@ -1664,11 +1675,11 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2, · 10 unmodified lines
16641675 BUG_ON(context->in_syscall || context->name_count);
16651676
16661677 state = context->state;
1667− if (state == AUDIT_DISABLED)
1678+ if (state == AUDIT_STATE_DISABLED)
16681679 return;
16691680
16701681 context->dummy = !audit_n_rules;
1671− if (!context->dummy && state == AUDIT_BUILD_CONTEXT) {
1682+ if (!context->dummy && state == AUDIT_STATE_BUILD) {
16721683 context->prio = 0;
16731684 if (auditd_test_task(current))
16741685 return;
@@ -1693,7 +1704,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2, · 18 unmodified lines
16931704 * @return_code: return value of the syscall
16941705 *
16951706 * Tear down after system call. If the audit context has been marked as
1696− * auditable (either because of the AUDIT_RECORD_CONTEXT state from
1707+ * auditable (either because of the AUDIT_STATE_RECORD state from
16971708 * filtering, or because some other part of the kernel wrote an audit
16981709 * message), then write out the syscall information. In call cases,
16991710 * free the names stored from getname().
@@ -1735,12 +1746,12 @@ void __audit_syscall_exit(int success, long return_code) · 35 unmodified lines
17351746
17361747 audit_filter_syscall(current, context);
17371748 audit_filter_inodes(current, context);
1738− if (context->current_state == AUDIT_RECORD_CONTEXT)
1749+ if (context->current_state == AUDIT_STATE_RECORD)
17391750 audit_log_exit();
17401751 }
17411752
17421753 context->in_syscall = 0;
1743− context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
1754+ context->prio = context->state == AUDIT_STATE_RECORD ? ~0ULL : 0;
17441755
17451756 audit_free_module(context);
17461757 audit_free_names(context);
@@ -1753,7 +1764,7 @@ void __audit_syscall_exit(int success, long return_code) · 6 unmodified lines
17531764 context->sockaddr_len = 0;
17541765 context->type = 0;
17551766 context->fds[0] = -1;
1756− if (context->state != AUDIT_RECORD_CONTEXT) {
1767+ if (context->state != AUDIT_STATE_RECORD) {
17571768 kfree(context->filterkey);
17581769 context->filterkey = NULL;
17591770 }
@@ -1765,6 +1776,7 @@ static inline void handle_one(const struct inode *inode) · 5 unmodified lines
17651776 struct audit_tree_refs *p;
17661777 struct audit_chunk *chunk;
17671778 int count;
1779+
17681780 if (likely(!inode->i_fsnotify_marks))
17691781 return;
17701782 context = audit_context();
@@ -1806,8 +1818,10 @@ retry: · 35 unmodified lines
18061818 seq = read_seqbegin(&rename_lock);
18071819 for(;;) {
18081820 struct inode *inode = d_backing_inode(d);
1821+
18091822 if (inode && unlikely(inode->i_fsnotify_marks)) {
18101823 struct audit_chunk *chunk;
1824+
18111825 chunk = audit_tree_lookup(inode);
18121826 if (chunk) {
18131827 if (unlikely(!put_tree_ref(context, chunk))) {
@@ -2203,7 +2217,7 @@ int auditsc_get_stamp(struct audit_context *ctx, · 389 unmodified lines
22032217 *serial = ctx->serial;
22042218 if (!ctx->prio) {
22052219 ctx->prio = 1;
2206− ctx->current_state = AUDIT_RECORD_CONTEXT;
2220+ ctx->current_state = AUDIT_STATE_RECORD;
22072221 }
22082222 return 1;
22092223 }
@@ -2285,6 +2299,7 @@ void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification) · 75 unmodified lines
22852299 void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
22862300 {
22872301 struct audit_context *context = audit_context();
2302+
22882303 context->mq_getsetattr.mqdes = mqdes;
22892304 context->mq_getsetattr.mqstat = *mqstat;
22902305 context->type = AUDIT_MQ_GETSETATTR;
@@ -2298,6 +2313,7 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) · 7 unmodified lines
22982313 void __audit_ipc_obj(struct kern_ipc_perm *ipcp)
22992314 {
23002315 struct audit_context *context = audit_context();
2316+
23012317 context->ipc.uid = ipcp->uid;
23022318 context->ipc.gid = ipcp->gid;
23032319 context->ipc.mode = ipcp->mode;
@@ -2362,6 +2378,7 @@ int __audit_socketcall(int nargs, unsigned long *args) · 58 unmodified lines
23622378 void __audit_fd_pair(int fd1, int fd2)
23632379 {
23642380 struct audit_context *context = audit_context();
2381+
23652382 context->fds[0] = fd1;
23662383 context->fds[1] = fd2;
23672384 }
@@ -2379,6 +2396,7 @@ int __audit_sockaddr(int len, void *a) · 11 unmodified lines
23792396
23802397 if (!context->sockaddr) {
23812398 void *p = kmalloc(sizeof(struct sockaddr_storage), GFP_KERNEL);
2399+
23822400 if (!p)
23832401 return -ENOMEM;
23842402 context->sockaddr = p;
@@ -2510,6 +2528,7 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, · 125 unmodified lines
25102528 void __audit_log_capset(const struct cred *new, const struct cred *old)
25112529 {
25122530 struct audit_context *context = audit_context();
2531+
25132532 context->capset.pid = task_tgid_nr(current);
25142533 context->capset.cap.effective = new->cap_effective;
25152534 context->capset.cap.inheritable = new->cap_effective;
@@ -2521,6 +2540,7 @@ void __audit_log_capset(const struct cred *new, const struct cred *old) · 5 unmodified lines
25212540 void __audit_mmap_fd(int fd, int flags)
25222541 {
25232542 struct audit_context *context = audit_context();
2543+
25242544 context->mmap.fd = fd;
25252545 context->mmap.flags = flags;
25262546 context->type = AUDIT_MMAP;
@@ -2686,6 +2706,7 @@ void audit_seccomp_actions_logged(const char *names, const char *old_names, · 159 unmodified lines
26862706 struct list_head *audit_killed_trees(void)
26872707 {
26882708 struct audit_context *ctx = audit_context();
2709+
26892710 if (likely(!ctx || !ctx->in_syscall))
26902711 return NULL;
26912712 return &ctx->killed_trees;
security/lsm_audit.c+0−1
@@ -119,7 +119,6 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb, · 118 unmodified lines
119119 return -EINVAL;
120120 ad->u.net->v6info.saddr = ip6->saddr;
121121 ad->u.net->v6info.daddr = ip6->daddr;
122− ret = 0;
123122 /* IPv6 can have several extension header before the Transport header
124123 * skip them */
125124 offset = skb_network_offset(skb);