]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - kernel/auditfilter.c
KVM: x86/speculation: Disable Fill buffer clear within guests
[mirror_ubuntu-jammy-kernel.git] / kernel / auditfilter.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* auditfilter.c -- filtering of audit events
3 *
4 * Copyright 2003-2004 Red Hat, Inc.
5 * Copyright 2005 Hewlett-Packard Development Company, L.P.
6 * Copyright 2005 IBM Corporation
7 */
8
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
11 #include <linux/kernel.h>
12 #include <linux/audit.h>
13 #include <linux/kthread.h>
14 #include <linux/mutex.h>
15 #include <linux/fs.h>
16 #include <linux/namei.h>
17 #include <linux/netlink.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/security.h>
21 #include <net/net_namespace.h>
22 #include <net/sock.h>
23 #include "audit.h"
24
25 /*
26 * Locking model:
27 *
28 * audit_filter_mutex:
29 * Synchronizes writes and blocking reads of audit's filterlist
30 * data. Rcu is used to traverse the filterlist and access
31 * contents of structs audit_entry, audit_watch and opaque
32 * LSM rules during filtering. If modified, these structures
33 * must be copied and replace their counterparts in the filterlist.
34 * An audit_parent struct is not accessed during filtering, so may
35 * be written directly provided audit_filter_mutex is held.
36 */
37
38 /* Audit filter lists, defined in <linux/audit.h> */
39 struct list_head audit_filter_list[AUDIT_NR_FILTERS] = {
40 LIST_HEAD_INIT(audit_filter_list[0]),
41 LIST_HEAD_INIT(audit_filter_list[1]),
42 LIST_HEAD_INIT(audit_filter_list[2]),
43 LIST_HEAD_INIT(audit_filter_list[3]),
44 LIST_HEAD_INIT(audit_filter_list[4]),
45 LIST_HEAD_INIT(audit_filter_list[5]),
46 LIST_HEAD_INIT(audit_filter_list[6]),
47 #if AUDIT_NR_FILTERS != 7
48 #error Fix audit_filter_list initialiser
49 #endif
50 };
51 static struct list_head audit_rules_list[AUDIT_NR_FILTERS] = {
52 LIST_HEAD_INIT(audit_rules_list[0]),
53 LIST_HEAD_INIT(audit_rules_list[1]),
54 LIST_HEAD_INIT(audit_rules_list[2]),
55 LIST_HEAD_INIT(audit_rules_list[3]),
56 LIST_HEAD_INIT(audit_rules_list[4]),
57 LIST_HEAD_INIT(audit_rules_list[5]),
58 LIST_HEAD_INIT(audit_rules_list[6]),
59 };
60
61 DEFINE_MUTEX(audit_filter_mutex);
62
63 static void audit_free_lsm_field(struct audit_field *f)
64 {
65 switch (f->type) {
66 case AUDIT_SUBJ_USER:
67 case AUDIT_SUBJ_ROLE:
68 case AUDIT_SUBJ_TYPE:
69 case AUDIT_SUBJ_SEN:
70 case AUDIT_SUBJ_CLR:
71 case AUDIT_OBJ_USER:
72 case AUDIT_OBJ_ROLE:
73 case AUDIT_OBJ_TYPE:
74 case AUDIT_OBJ_LEV_LOW:
75 case AUDIT_OBJ_LEV_HIGH:
76 kfree(f->lsm_str);
77 security_audit_rule_free(f->lsm_rules);
78 }
79 }
80
81 static inline void audit_free_rule(struct audit_entry *e)
82 {
83 int i;
84 struct audit_krule *erule = &e->rule;
85
86 /* some rules don't have associated watches */
87 if (erule->watch)
88 audit_put_watch(erule->watch);
89 if (erule->fields)
90 for (i = 0; i < erule->field_count; i++)
91 audit_free_lsm_field(&erule->fields[i]);
92 kfree(erule->fields);
93 kfree(erule->filterkey);
94 kfree(e);
95 }
96
97 void audit_free_rule_rcu(struct rcu_head *head)
98 {
99 struct audit_entry *e = container_of(head, struct audit_entry, rcu);
100 audit_free_rule(e);
101 }
102
103 /* Initialize an audit filterlist entry. */
104 static inline struct audit_entry *audit_init_entry(u32 field_count)
105 {
106 struct audit_entry *entry;
107 struct audit_field *fields;
108
109 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
110 if (unlikely(!entry))
111 return NULL;
112
113 fields = kcalloc(field_count, sizeof(*fields), GFP_KERNEL);
114 if (unlikely(!fields)) {
115 kfree(entry);
116 return NULL;
117 }
118 entry->rule.fields = fields;
119
120 return entry;
121 }
122
123 /* Unpack a filter field's string representation from user-space
124 * buffer. */
125 char *audit_unpack_string(void **bufp, size_t *remain, size_t len)
126 {
127 char *str;
128
129 if (!*bufp || (len == 0) || (len > *remain))
130 return ERR_PTR(-EINVAL);
131
132 /* Of the currently implemented string fields, PATH_MAX
133 * defines the longest valid length.
134 */
135 if (len > PATH_MAX)
136 return ERR_PTR(-ENAMETOOLONG);
137
138 str = kmalloc(len + 1, GFP_KERNEL);
139 if (unlikely(!str))
140 return ERR_PTR(-ENOMEM);
141
142 memcpy(str, *bufp, len);
143 str[len] = 0;
144 *bufp += len;
145 *remain -= len;
146
147 return str;
148 }
149
150 /* Translate an inode field to kernel representation. */
151 static inline int audit_to_inode(struct audit_krule *krule,
152 struct audit_field *f)
153 {
154 if (krule->listnr != AUDIT_FILTER_EXIT ||
155 krule->inode_f || krule->watch || krule->tree ||
156 (f->op != Audit_equal && f->op != Audit_not_equal))
157 return -EINVAL;
158
159 krule->inode_f = f;
160 return 0;
161 }
162
163 static __u32 *classes[AUDIT_SYSCALL_CLASSES];
164
165 int __init audit_register_class(int class, unsigned *list)
166 {
167 __u32 *p = kcalloc(AUDIT_BITMASK_SIZE, sizeof(__u32), GFP_KERNEL);
168 if (!p)
169 return -ENOMEM;
170 while (*list != ~0U) {
171 unsigned n = *list++;
172 if (n >= AUDIT_BITMASK_SIZE * 32 - AUDIT_SYSCALL_CLASSES) {
173 kfree(p);
174 return -EINVAL;
175 }
176 p[AUDIT_WORD(n)] |= AUDIT_BIT(n);
177 }
178 if (class >= AUDIT_SYSCALL_CLASSES || classes[class]) {
179 kfree(p);
180 return -EINVAL;
181 }
182 classes[class] = p;
183 return 0;
184 }
185
186 int audit_match_class(int class, unsigned syscall)
187 {
188 if (unlikely(syscall >= AUDIT_BITMASK_SIZE * 32))
189 return 0;
190 if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class]))
191 return 0;
192 return classes[class][AUDIT_WORD(syscall)] & AUDIT_BIT(syscall);
193 }
194
195 #ifdef CONFIG_AUDITSYSCALL
196 static inline int audit_match_class_bits(int class, u32 *mask)
197 {
198 int i;
199
200 if (classes[class]) {
201 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
202 if (mask[i] & classes[class][i])
203 return 0;
204 }
205 return 1;
206 }
207
208 static int audit_match_signal(struct audit_entry *entry)
209 {
210 struct audit_field *arch = entry->rule.arch_f;
211
212 if (!arch) {
213 /* When arch is unspecified, we must check both masks on biarch
214 * as syscall number alone is ambiguous. */
215 return (audit_match_class_bits(AUDIT_CLASS_SIGNAL,
216 entry->rule.mask) &&
217 audit_match_class_bits(AUDIT_CLASS_SIGNAL_32,
218 entry->rule.mask));
219 }
220
221 switch(audit_classify_arch(arch->val)) {
222 case 0: /* native */
223 return (audit_match_class_bits(AUDIT_CLASS_SIGNAL,
224 entry->rule.mask));
225 case 1: /* 32bit on biarch */
226 return (audit_match_class_bits(AUDIT_CLASS_SIGNAL_32,
227 entry->rule.mask));
228 default:
229 return 1;
230 }
231 }
232 #endif
233
234 /* Common user-space to kernel rule translation. */
235 static inline struct audit_entry *audit_to_entry_common(struct audit_rule_data *rule)
236 {
237 unsigned listnr;
238 struct audit_entry *entry;
239 int i, err;
240
241 err = -EINVAL;
242 listnr = rule->flags & ~AUDIT_FILTER_PREPEND;
243 switch(listnr) {
244 default:
245 goto exit_err;
246 #ifdef CONFIG_AUDITSYSCALL
247 case AUDIT_FILTER_ENTRY:
248 pr_err("AUDIT_FILTER_ENTRY is deprecated\n");
249 goto exit_err;
250 case AUDIT_FILTER_EXIT:
251 case AUDIT_FILTER_TASK:
252 #endif
253 case AUDIT_FILTER_USER:
254 case AUDIT_FILTER_EXCLUDE:
255 case AUDIT_FILTER_FS:
256 ;
257 }
258 if (unlikely(rule->action == AUDIT_POSSIBLE)) {
259 pr_err("AUDIT_POSSIBLE is deprecated\n");
260 goto exit_err;
261 }
262 if (rule->action != AUDIT_NEVER && rule->action != AUDIT_ALWAYS)
263 goto exit_err;
264 if (rule->field_count > AUDIT_MAX_FIELDS)
265 goto exit_err;
266
267 err = -ENOMEM;
268 entry = audit_init_entry(rule->field_count);
269 if (!entry)
270 goto exit_err;
271
272 entry->rule.flags = rule->flags & AUDIT_FILTER_PREPEND;
273 entry->rule.listnr = listnr;
274 entry->rule.action = rule->action;
275 entry->rule.field_count = rule->field_count;
276
277 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
278 entry->rule.mask[i] = rule->mask[i];
279
280 for (i = 0; i < AUDIT_SYSCALL_CLASSES; i++) {
281 int bit = AUDIT_BITMASK_SIZE * 32 - i - 1;
282 __u32 *p = &entry->rule.mask[AUDIT_WORD(bit)];
283 __u32 *class;
284
285 if (!(*p & AUDIT_BIT(bit)))
286 continue;
287 *p &= ~AUDIT_BIT(bit);
288 class = classes[i];
289 if (class) {
290 int j;
291 for (j = 0; j < AUDIT_BITMASK_SIZE; j++)
292 entry->rule.mask[j] |= class[j];
293 }
294 }
295
296 return entry;
297
298 exit_err:
299 return ERR_PTR(err);
300 }
301
302 static u32 audit_ops[] =
303 {
304 [Audit_equal] = AUDIT_EQUAL,
305 [Audit_not_equal] = AUDIT_NOT_EQUAL,
306 [Audit_bitmask] = AUDIT_BIT_MASK,
307 [Audit_bittest] = AUDIT_BIT_TEST,
308 [Audit_lt] = AUDIT_LESS_THAN,
309 [Audit_gt] = AUDIT_GREATER_THAN,
310 [Audit_le] = AUDIT_LESS_THAN_OR_EQUAL,
311 [Audit_ge] = AUDIT_GREATER_THAN_OR_EQUAL,
312 };
313
314 static u32 audit_to_op(u32 op)
315 {
316 u32 n;
317 for (n = Audit_equal; n < Audit_bad && audit_ops[n] != op; n++)
318 ;
319 return n;
320 }
321
322 /* check if an audit field is valid */
323 static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
324 {
325 switch (f->type) {
326 case AUDIT_MSGTYPE:
327 if (entry->rule.listnr != AUDIT_FILTER_EXCLUDE &&
328 entry->rule.listnr != AUDIT_FILTER_USER)
329 return -EINVAL;
330 break;
331 case AUDIT_FSTYPE:
332 if (entry->rule.listnr != AUDIT_FILTER_FS)
333 return -EINVAL;
334 break;
335 }
336
337 switch (entry->rule.listnr) {
338 case AUDIT_FILTER_FS:
339 switch(f->type) {
340 case AUDIT_FSTYPE:
341 case AUDIT_FILTERKEY:
342 break;
343 default:
344 return -EINVAL;
345 }
346 }
347
348 /* Check for valid field type and op */
349 switch (f->type) {
350 case AUDIT_ARG0:
351 case AUDIT_ARG1:
352 case AUDIT_ARG2:
353 case AUDIT_ARG3:
354 case AUDIT_PERS: /* <uapi/linux/personality.h> */
355 case AUDIT_DEVMINOR:
356 /* all ops are valid */
357 break;
358 case AUDIT_UID:
359 case AUDIT_EUID:
360 case AUDIT_SUID:
361 case AUDIT_FSUID:
362 case AUDIT_LOGINUID:
363 case AUDIT_OBJ_UID:
364 case AUDIT_GID:
365 case AUDIT_EGID:
366 case AUDIT_SGID:
367 case AUDIT_FSGID:
368 case AUDIT_OBJ_GID:
369 case AUDIT_PID:
370 case AUDIT_MSGTYPE:
371 case AUDIT_PPID:
372 case AUDIT_DEVMAJOR:
373 case AUDIT_EXIT:
374 case AUDIT_SUCCESS:
375 case AUDIT_INODE:
376 case AUDIT_SESSIONID:
377 case AUDIT_SUBJ_SEN:
378 case AUDIT_SUBJ_CLR:
379 case AUDIT_OBJ_LEV_LOW:
380 case AUDIT_OBJ_LEV_HIGH:
381 case AUDIT_SADDR_FAM:
382 /* bit ops are only useful on syscall args */
383 if (f->op == Audit_bitmask || f->op == Audit_bittest)
384 return -EINVAL;
385 break;
386 case AUDIT_SUBJ_USER:
387 case AUDIT_SUBJ_ROLE:
388 case AUDIT_SUBJ_TYPE:
389 case AUDIT_OBJ_USER:
390 case AUDIT_OBJ_ROLE:
391 case AUDIT_OBJ_TYPE:
392 case AUDIT_WATCH:
393 case AUDIT_DIR:
394 case AUDIT_FILTERKEY:
395 case AUDIT_LOGINUID_SET:
396 case AUDIT_ARCH:
397 case AUDIT_FSTYPE:
398 case AUDIT_PERM:
399 case AUDIT_FILETYPE:
400 case AUDIT_FIELD_COMPARE:
401 case AUDIT_EXE:
402 /* only equal and not equal valid ops */
403 if (f->op != Audit_not_equal && f->op != Audit_equal)
404 return -EINVAL;
405 break;
406 default:
407 /* field not recognized */
408 return -EINVAL;
409 }
410
411 /* Check for select valid field values */
412 switch (f->type) {
413 case AUDIT_LOGINUID_SET:
414 if ((f->val != 0) && (f->val != 1))
415 return -EINVAL;
416 break;
417 case AUDIT_PERM:
418 if (f->val & ~15)
419 return -EINVAL;
420 break;
421 case AUDIT_FILETYPE:
422 if (f->val & ~S_IFMT)
423 return -EINVAL;
424 break;
425 case AUDIT_FIELD_COMPARE:
426 if (f->val > AUDIT_MAX_FIELD_COMPARE)
427 return -EINVAL;
428 break;
429 case AUDIT_SADDR_FAM:
430 if (f->val >= AF_MAX)
431 return -EINVAL;
432 break;
433 default:
434 break;
435 }
436
437 return 0;
438 }
439
440 /* Translate struct audit_rule_data to kernel's rule representation. */
441 static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
442 size_t datasz)
443 {
444 int err = 0;
445 struct audit_entry *entry;
446 void *bufp;
447 size_t remain = datasz - sizeof(struct audit_rule_data);
448 int i;
449 char *str;
450 struct audit_fsnotify_mark *audit_mark;
451
452 entry = audit_to_entry_common(data);
453 if (IS_ERR(entry))
454 goto exit_nofree;
455
456 bufp = data->buf;
457 for (i = 0; i < data->field_count; i++) {
458 struct audit_field *f = &entry->rule.fields[i];
459 u32 f_val;
460
461 err = -EINVAL;
462
463 f->op = audit_to_op(data->fieldflags[i]);
464 if (f->op == Audit_bad)
465 goto exit_free;
466
467 f->type = data->fields[i];
468 f_val = data->values[i];
469
470 /* Support legacy tests for a valid loginuid */
471 if ((f->type == AUDIT_LOGINUID) && (f_val == AUDIT_UID_UNSET)) {
472 f->type = AUDIT_LOGINUID_SET;
473 f_val = 0;
474 entry->rule.pflags |= AUDIT_LOGINUID_LEGACY;
475 }
476
477 err = audit_field_valid(entry, f);
478 if (err)
479 goto exit_free;
480
481 err = -EINVAL;
482 switch (f->type) {
483 case AUDIT_LOGINUID:
484 case AUDIT_UID:
485 case AUDIT_EUID:
486 case AUDIT_SUID:
487 case AUDIT_FSUID:
488 case AUDIT_OBJ_UID:
489 f->uid = make_kuid(current_user_ns(), f_val);
490 if (!uid_valid(f->uid))
491 goto exit_free;
492 break;
493 case AUDIT_GID:
494 case AUDIT_EGID:
495 case AUDIT_SGID:
496 case AUDIT_FSGID:
497 case AUDIT_OBJ_GID:
498 f->gid = make_kgid(current_user_ns(), f_val);
499 if (!gid_valid(f->gid))
500 goto exit_free;
501 break;
502 case AUDIT_ARCH:
503 f->val = f_val;
504 entry->rule.arch_f = f;
505 break;
506 case AUDIT_SUBJ_USER:
507 case AUDIT_SUBJ_ROLE:
508 case AUDIT_SUBJ_TYPE:
509 case AUDIT_SUBJ_SEN:
510 case AUDIT_SUBJ_CLR:
511 case AUDIT_OBJ_USER:
512 case AUDIT_OBJ_ROLE:
513 case AUDIT_OBJ_TYPE:
514 case AUDIT_OBJ_LEV_LOW:
515 case AUDIT_OBJ_LEV_HIGH:
516 str = audit_unpack_string(&bufp, &remain, f_val);
517 if (IS_ERR(str)) {
518 err = PTR_ERR(str);
519 goto exit_free;
520 }
521 entry->rule.buflen += f_val;
522 f->lsm_isset = true;
523 f->lsm_str = str;
524 err = security_audit_rule_init(f->type, f->op, str,
525 f->lsm_rules);
526 /* Keep currently invalid fields around in case they
527 * become valid after a policy reload. */
528 if (err == -EINVAL) {
529 pr_warn("audit rule for LSM \'%s\' is invalid\n",
530 str);
531 err = 0;
532 } else if (err)
533 goto exit_free;
534 break;
535 case AUDIT_WATCH:
536 str = audit_unpack_string(&bufp, &remain, f_val);
537 if (IS_ERR(str)) {
538 err = PTR_ERR(str);
539 goto exit_free;
540 }
541 err = audit_to_watch(&entry->rule, str, f_val, f->op);
542 if (err) {
543 kfree(str);
544 goto exit_free;
545 }
546 entry->rule.buflen += f_val;
547 break;
548 case AUDIT_DIR:
549 str = audit_unpack_string(&bufp, &remain, f_val);
550 if (IS_ERR(str)) {
551 err = PTR_ERR(str);
552 goto exit_free;
553 }
554 err = audit_make_tree(&entry->rule, str, f->op);
555 kfree(str);
556 if (err)
557 goto exit_free;
558 entry->rule.buflen += f_val;
559 break;
560 case AUDIT_INODE:
561 f->val = f_val;
562 err = audit_to_inode(&entry->rule, f);
563 if (err)
564 goto exit_free;
565 break;
566 case AUDIT_FILTERKEY:
567 if (entry->rule.filterkey || f_val > AUDIT_MAX_KEY_LEN)
568 goto exit_free;
569 str = audit_unpack_string(&bufp, &remain, f_val);
570 if (IS_ERR(str)) {
571 err = PTR_ERR(str);
572 goto exit_free;
573 }
574 entry->rule.buflen += f_val;
575 entry->rule.filterkey = str;
576 break;
577 case AUDIT_EXE:
578 if (entry->rule.exe || f_val > PATH_MAX)
579 goto exit_free;
580 str = audit_unpack_string(&bufp, &remain, f_val);
581 if (IS_ERR(str)) {
582 err = PTR_ERR(str);
583 goto exit_free;
584 }
585 audit_mark = audit_alloc_mark(&entry->rule, str, f_val);
586 if (IS_ERR(audit_mark)) {
587 kfree(str);
588 err = PTR_ERR(audit_mark);
589 goto exit_free;
590 }
591 entry->rule.buflen += f_val;
592 entry->rule.exe = audit_mark;
593 break;
594 default:
595 f->val = f_val;
596 break;
597 }
598 }
599
600 if (entry->rule.inode_f && entry->rule.inode_f->op == Audit_not_equal)
601 entry->rule.inode_f = NULL;
602
603 exit_nofree:
604 return entry;
605
606 exit_free:
607 if (entry->rule.tree)
608 audit_put_tree(entry->rule.tree); /* that's the temporary one */
609 if (entry->rule.exe)
610 audit_remove_mark(entry->rule.exe); /* that's the template one */
611 audit_free_rule(entry);
612 return ERR_PTR(err);
613 }
614
615 /* Pack a filter field's string representation into data block. */
616 static inline size_t audit_pack_string(void **bufp, const char *str)
617 {
618 size_t len = strlen(str);
619
620 memcpy(*bufp, str, len);
621 *bufp += len;
622
623 return len;
624 }
625
626 /* Translate kernel rule representation to struct audit_rule_data. */
627 static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
628 {
629 struct audit_rule_data *data;
630 void *bufp;
631 int i;
632
633 data = kmalloc(sizeof(*data) + krule->buflen, GFP_KERNEL);
634 if (unlikely(!data))
635 return NULL;
636 memset(data, 0, sizeof(*data));
637
638 data->flags = krule->flags | krule->listnr;
639 data->action = krule->action;
640 data->field_count = krule->field_count;
641 bufp = data->buf;
642 for (i = 0; i < data->field_count; i++) {
643 struct audit_field *f = &krule->fields[i];
644
645 data->fields[i] = f->type;
646 data->fieldflags[i] = audit_ops[f->op];
647 switch(f->type) {
648 case AUDIT_SUBJ_USER:
649 case AUDIT_SUBJ_ROLE:
650 case AUDIT_SUBJ_TYPE:
651 case AUDIT_SUBJ_SEN:
652 case AUDIT_SUBJ_CLR:
653 case AUDIT_OBJ_USER:
654 case AUDIT_OBJ_ROLE:
655 case AUDIT_OBJ_TYPE:
656 case AUDIT_OBJ_LEV_LOW:
657 case AUDIT_OBJ_LEV_HIGH:
658 data->buflen += data->values[i] =
659 audit_pack_string(&bufp, f->lsm_str);
660 break;
661 case AUDIT_WATCH:
662 data->buflen += data->values[i] =
663 audit_pack_string(&bufp,
664 audit_watch_path(krule->watch));
665 break;
666 case AUDIT_DIR:
667 data->buflen += data->values[i] =
668 audit_pack_string(&bufp,
669 audit_tree_path(krule->tree));
670 break;
671 case AUDIT_FILTERKEY:
672 data->buflen += data->values[i] =
673 audit_pack_string(&bufp, krule->filterkey);
674 break;
675 case AUDIT_EXE:
676 data->buflen += data->values[i] =
677 audit_pack_string(&bufp, audit_mark_path(krule->exe));
678 break;
679 case AUDIT_LOGINUID_SET:
680 if (krule->pflags & AUDIT_LOGINUID_LEGACY && !f->val) {
681 data->fields[i] = AUDIT_LOGINUID;
682 data->values[i] = AUDIT_UID_UNSET;
683 break;
684 }
685 fallthrough; /* if set */
686 default:
687 data->values[i] = f->val;
688 }
689 }
690 for (i = 0; i < AUDIT_BITMASK_SIZE; i++) data->mask[i] = krule->mask[i];
691
692 return data;
693 }
694
695 /* Compare two rules in kernel format. Considered success if rules
696 * don't match. */
697 static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
698 {
699 int i;
700
701 if (a->flags != b->flags ||
702 a->pflags != b->pflags ||
703 a->listnr != b->listnr ||
704 a->action != b->action ||
705 a->field_count != b->field_count)
706 return 1;
707
708 for (i = 0; i < a->field_count; i++) {
709 if (a->fields[i].type != b->fields[i].type ||
710 a->fields[i].op != b->fields[i].op)
711 return 1;
712
713 switch(a->fields[i].type) {
714 case AUDIT_SUBJ_USER:
715 case AUDIT_SUBJ_ROLE:
716 case AUDIT_SUBJ_TYPE:
717 case AUDIT_SUBJ_SEN:
718 case AUDIT_SUBJ_CLR:
719 case AUDIT_OBJ_USER:
720 case AUDIT_OBJ_ROLE:
721 case AUDIT_OBJ_TYPE:
722 case AUDIT_OBJ_LEV_LOW:
723 case AUDIT_OBJ_LEV_HIGH:
724 if (strcmp(a->fields[i].lsm_str, b->fields[i].lsm_str))
725 return 1;
726 break;
727 case AUDIT_WATCH:
728 if (strcmp(audit_watch_path(a->watch),
729 audit_watch_path(b->watch)))
730 return 1;
731 break;
732 case AUDIT_DIR:
733 if (strcmp(audit_tree_path(a->tree),
734 audit_tree_path(b->tree)))
735 return 1;
736 break;
737 case AUDIT_FILTERKEY:
738 /* both filterkeys exist based on above type compare */
739 if (strcmp(a->filterkey, b->filterkey))
740 return 1;
741 break;
742 case AUDIT_EXE:
743 /* both paths exist based on above type compare */
744 if (strcmp(audit_mark_path(a->exe),
745 audit_mark_path(b->exe)))
746 return 1;
747 break;
748 case AUDIT_UID:
749 case AUDIT_EUID:
750 case AUDIT_SUID:
751 case AUDIT_FSUID:
752 case AUDIT_LOGINUID:
753 case AUDIT_OBJ_UID:
754 if (!uid_eq(a->fields[i].uid, b->fields[i].uid))
755 return 1;
756 break;
757 case AUDIT_GID:
758 case AUDIT_EGID:
759 case AUDIT_SGID:
760 case AUDIT_FSGID:
761 case AUDIT_OBJ_GID:
762 if (!gid_eq(a->fields[i].gid, b->fields[i].gid))
763 return 1;
764 break;
765 default:
766 if (a->fields[i].val != b->fields[i].val)
767 return 1;
768 }
769 }
770
771 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
772 if (a->mask[i] != b->mask[i])
773 return 1;
774
775 return 0;
776 }
777
778 /* Duplicate LSM field information. The lsm_rules is opaque, so must be
779 * re-initialized. */
780 static inline int audit_dupe_lsm_field(struct audit_field *df,
781 struct audit_field *sf)
782 {
783 int ret = 0;
784 char *lsm_str;
785
786 /* our own copy of lsm_str */
787 lsm_str = kstrdup(sf->lsm_str, GFP_KERNEL);
788 if (unlikely(!lsm_str))
789 return -ENOMEM;
790 df->lsm_str = lsm_str;
791
792 /* our own (refreshed) copy of lsm_rules */
793 ret = security_audit_rule_init(df->type, df->op, df->lsm_str,
794 df->lsm_rules);
795 /* Keep currently invalid fields around in case they
796 * become valid after a policy reload. */
797 if (ret == -EINVAL) {
798 pr_warn("audit rule for LSM \'%s\' is invalid\n",
799 df->lsm_str);
800 ret = 0;
801 }
802
803 return ret;
804 }
805
806 /* Duplicate an audit rule. This will be a deep copy with the exception
807 * of the watch - that pointer is carried over. The LSM specific fields
808 * will be updated in the copy. The point is to be able to replace the old
809 * rule with the new rule in the filterlist, then free the old rule.
810 * The rlist element is undefined; list manipulations are handled apart from
811 * the initial copy. */
812 struct audit_entry *audit_dupe_rule(struct audit_krule *old)
813 {
814 u32 fcount = old->field_count;
815 struct audit_entry *entry;
816 struct audit_krule *new;
817 char *fk;
818 int i, err = 0;
819
820 entry = audit_init_entry(fcount);
821 if (unlikely(!entry))
822 return ERR_PTR(-ENOMEM);
823
824 new = &entry->rule;
825 new->flags = old->flags;
826 new->pflags = old->pflags;
827 new->listnr = old->listnr;
828 new->action = old->action;
829 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
830 new->mask[i] = old->mask[i];
831 new->prio = old->prio;
832 new->buflen = old->buflen;
833 new->inode_f = old->inode_f;
834 new->field_count = old->field_count;
835
836 /*
837 * note that we are OK with not refcounting here; audit_match_tree()
838 * never dereferences tree and we can't get false positives there
839 * since we'd have to have rule gone from the list *and* removed
840 * before the chunks found by lookup had been allocated, i.e. before
841 * the beginning of list scan.
842 */
843 new->tree = old->tree;
844 memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount);
845
846 /* deep copy this information, updating the lsm_rules fields, because
847 * the originals will all be freed when the old rule is freed. */
848 for (i = 0; i < fcount; i++) {
849 switch (new->fields[i].type) {
850 case AUDIT_SUBJ_USER:
851 case AUDIT_SUBJ_ROLE:
852 case AUDIT_SUBJ_TYPE:
853 case AUDIT_SUBJ_SEN:
854 case AUDIT_SUBJ_CLR:
855 case AUDIT_OBJ_USER:
856 case AUDIT_OBJ_ROLE:
857 case AUDIT_OBJ_TYPE:
858 case AUDIT_OBJ_LEV_LOW:
859 case AUDIT_OBJ_LEV_HIGH:
860 err = audit_dupe_lsm_field(&new->fields[i],
861 &old->fields[i]);
862 break;
863 case AUDIT_FILTERKEY:
864 fk = kstrdup(old->filterkey, GFP_KERNEL);
865 if (unlikely(!fk))
866 err = -ENOMEM;
867 else
868 new->filterkey = fk;
869 break;
870 case AUDIT_EXE:
871 err = audit_dupe_exe(new, old);
872 break;
873 }
874 if (err) {
875 if (new->exe)
876 audit_remove_mark(new->exe);
877 audit_free_rule(entry);
878 return ERR_PTR(err);
879 }
880 }
881
882 if (old->watch) {
883 audit_get_watch(old->watch);
884 new->watch = old->watch;
885 }
886
887 return entry;
888 }
889
890 /* Find an existing audit rule.
891 * Caller must hold audit_filter_mutex to prevent stale rule data. */
892 static struct audit_entry *audit_find_rule(struct audit_entry *entry,
893 struct list_head **p)
894 {
895 struct audit_entry *e, *found = NULL;
896 struct list_head *list;
897 int h;
898
899 if (entry->rule.inode_f) {
900 h = audit_hash_ino(entry->rule.inode_f->val);
901 *p = list = &audit_inode_hash[h];
902 } else if (entry->rule.watch) {
903 /* we don't know the inode number, so must walk entire hash */
904 for (h = 0; h < AUDIT_INODE_BUCKETS; h++) {
905 list = &audit_inode_hash[h];
906 list_for_each_entry(e, list, list)
907 if (!audit_compare_rule(&entry->rule, &e->rule)) {
908 found = e;
909 goto out;
910 }
911 }
912 goto out;
913 } else {
914 *p = list = &audit_filter_list[entry->rule.listnr];
915 }
916
917 list_for_each_entry(e, list, list)
918 if (!audit_compare_rule(&entry->rule, &e->rule)) {
919 found = e;
920 goto out;
921 }
922
923 out:
924 return found;
925 }
926
927 static u64 prio_low = ~0ULL/2;
928 static u64 prio_high = ~0ULL/2 - 1;
929
930 /* Add rule to given filterlist if not a duplicate. */
931 static inline int audit_add_rule(struct audit_entry *entry)
932 {
933 struct audit_entry *e;
934 struct audit_watch *watch = entry->rule.watch;
935 struct audit_tree *tree = entry->rule.tree;
936 struct list_head *list;
937 int err = 0;
938 #ifdef CONFIG_AUDITSYSCALL
939 int dont_count = 0;
940
941 /* If any of these, don't count towards total */
942 switch(entry->rule.listnr) {
943 case AUDIT_FILTER_USER:
944 case AUDIT_FILTER_EXCLUDE:
945 case AUDIT_FILTER_FS:
946 dont_count = 1;
947 }
948 #endif
949
950 mutex_lock(&audit_filter_mutex);
951 e = audit_find_rule(entry, &list);
952 if (e) {
953 mutex_unlock(&audit_filter_mutex);
954 err = -EEXIST;
955 /* normally audit_add_tree_rule() will free it on failure */
956 if (tree)
957 audit_put_tree(tree);
958 return err;
959 }
960
961 if (watch) {
962 /* audit_filter_mutex is dropped and re-taken during this call */
963 err = audit_add_watch(&entry->rule, &list);
964 if (err) {
965 mutex_unlock(&audit_filter_mutex);
966 /*
967 * normally audit_add_tree_rule() will free it
968 * on failure
969 */
970 if (tree)
971 audit_put_tree(tree);
972 return err;
973 }
974 }
975 if (tree) {
976 err = audit_add_tree_rule(&entry->rule);
977 if (err) {
978 mutex_unlock(&audit_filter_mutex);
979 return err;
980 }
981 }
982
983 entry->rule.prio = ~0ULL;
984 if (entry->rule.listnr == AUDIT_FILTER_EXIT) {
985 if (entry->rule.flags & AUDIT_FILTER_PREPEND)
986 entry->rule.prio = ++prio_high;
987 else
988 entry->rule.prio = --prio_low;
989 }
990
991 if (entry->rule.flags & AUDIT_FILTER_PREPEND) {
992 list_add(&entry->rule.list,
993 &audit_rules_list[entry->rule.listnr]);
994 list_add_rcu(&entry->list, list);
995 entry->rule.flags &= ~AUDIT_FILTER_PREPEND;
996 } else {
997 list_add_tail(&entry->rule.list,
998 &audit_rules_list[entry->rule.listnr]);
999 list_add_tail_rcu(&entry->list, list);
1000 }
1001 #ifdef CONFIG_AUDITSYSCALL
1002 if (!dont_count)
1003 audit_n_rules++;
1004
1005 if (!audit_match_signal(entry))
1006 audit_signals++;
1007 #endif
1008 mutex_unlock(&audit_filter_mutex);
1009
1010 return err;
1011 }
1012
1013 /* Remove an existing rule from filterlist. */
1014 int audit_del_rule(struct audit_entry *entry)
1015 {
1016 struct audit_entry *e;
1017 struct audit_tree *tree = entry->rule.tree;
1018 struct list_head *list;
1019 int ret = 0;
1020 #ifdef CONFIG_AUDITSYSCALL
1021 int dont_count = 0;
1022
1023 /* If any of these, don't count towards total */
1024 switch(entry->rule.listnr) {
1025 case AUDIT_FILTER_USER:
1026 case AUDIT_FILTER_EXCLUDE:
1027 case AUDIT_FILTER_FS:
1028 dont_count = 1;
1029 }
1030 #endif
1031
1032 mutex_lock(&audit_filter_mutex);
1033 e = audit_find_rule(entry, &list);
1034 if (!e) {
1035 ret = -ENOENT;
1036 goto out;
1037 }
1038
1039 if (e->rule.watch)
1040 audit_remove_watch_rule(&e->rule);
1041
1042 if (e->rule.tree)
1043 audit_remove_tree_rule(&e->rule);
1044
1045 if (e->rule.exe)
1046 audit_remove_mark_rule(&e->rule);
1047
1048 #ifdef CONFIG_AUDITSYSCALL
1049 if (!dont_count)
1050 audit_n_rules--;
1051
1052 if (!audit_match_signal(entry))
1053 audit_signals--;
1054 #endif
1055
1056 list_del_rcu(&e->list);
1057 list_del(&e->rule.list);
1058 call_rcu(&e->rcu, audit_free_rule_rcu);
1059
1060 out:
1061 mutex_unlock(&audit_filter_mutex);
1062
1063 if (tree)
1064 audit_put_tree(tree); /* that's the temporary one */
1065
1066 return ret;
1067 }
1068
1069 /* List rules using struct audit_rule_data. */
1070 static void audit_list_rules(int seq, struct sk_buff_head *q)
1071 {
1072 struct sk_buff *skb;
1073 struct audit_krule *r;
1074 int i;
1075
1076 /* This is a blocking read, so use audit_filter_mutex instead of rcu
1077 * iterator to sync with list writers. */
1078 for (i=0; i<AUDIT_NR_FILTERS; i++) {
1079 list_for_each_entry(r, &audit_rules_list[i], list) {
1080 struct audit_rule_data *data;
1081
1082 data = audit_krule_to_data(r);
1083 if (unlikely(!data))
1084 break;
1085 skb = audit_make_reply(seq, AUDIT_LIST_RULES, 0, 1,
1086 data,
1087 sizeof(*data) + data->buflen);
1088 if (skb)
1089 skb_queue_tail(q, skb);
1090 kfree(data);
1091 }
1092 }
1093 skb = audit_make_reply(seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
1094 if (skb)
1095 skb_queue_tail(q, skb);
1096 }
1097
1098 /* Log rule additions and removals */
1099 static void audit_log_rule_change(char *action, struct audit_krule *rule, int res)
1100 {
1101 struct audit_buffer *ab;
1102
1103 if (!audit_enabled)
1104 return;
1105
1106 ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONFIG_CHANGE);
1107 if (!ab)
1108 return;
1109 audit_log_session_info(ab);
1110 audit_log_task_context(ab, NULL);
1111 audit_log_format(ab, " op=%s", action);
1112 audit_log_key(ab, rule->filterkey);
1113 audit_log_format(ab, " list=%d res=%d", rule->listnr, res);
1114 audit_log_end(ab);
1115 }
1116
1117 /**
1118 * audit_rule_change - apply all rules to the specified message type
1119 * @type: audit message type
1120 * @seq: netlink audit message sequence (serial) number
1121 * @data: payload data
1122 * @datasz: size of payload data
1123 */
1124 int audit_rule_change(int type, int seq, void *data, size_t datasz)
1125 {
1126 int err = 0;
1127 struct audit_entry *entry;
1128
1129 switch (type) {
1130 case AUDIT_ADD_RULE:
1131 entry = audit_data_to_entry(data, datasz);
1132 if (IS_ERR(entry))
1133 return PTR_ERR(entry);
1134 err = audit_add_rule(entry);
1135 audit_log_rule_change("add_rule", &entry->rule, !err);
1136 break;
1137 case AUDIT_DEL_RULE:
1138 entry = audit_data_to_entry(data, datasz);
1139 if (IS_ERR(entry))
1140 return PTR_ERR(entry);
1141 err = audit_del_rule(entry);
1142 audit_log_rule_change("remove_rule", &entry->rule, !err);
1143 break;
1144 default:
1145 WARN_ON(1);
1146 return -EINVAL;
1147 }
1148
1149 if (err || type == AUDIT_DEL_RULE) {
1150 if (entry->rule.exe)
1151 audit_remove_mark(entry->rule.exe);
1152 audit_free_rule(entry);
1153 }
1154
1155 return err;
1156 }
1157
1158 /**
1159 * audit_list_rules_send - list the audit rules
1160 * @request_skb: skb of request we are replying to (used to target the reply)
1161 * @seq: netlink audit message sequence (serial) number
1162 */
1163 int audit_list_rules_send(struct sk_buff *request_skb, int seq)
1164 {
1165 struct task_struct *tsk;
1166 struct audit_netlink_list *dest;
1167
1168 /* We can't just spew out the rules here because we might fill
1169 * the available socket buffer space and deadlock waiting for
1170 * auditctl to read from it... which isn't ever going to
1171 * happen if we're actually running in the context of auditctl
1172 * trying to _send_ the stuff */
1173
1174 dest = kmalloc(sizeof(*dest), GFP_KERNEL);
1175 if (!dest)
1176 return -ENOMEM;
1177 dest->net = get_net(sock_net(NETLINK_CB(request_skb).sk));
1178 dest->portid = NETLINK_CB(request_skb).portid;
1179 skb_queue_head_init(&dest->q);
1180
1181 mutex_lock(&audit_filter_mutex);
1182 audit_list_rules(seq, &dest->q);
1183 mutex_unlock(&audit_filter_mutex);
1184
1185 tsk = kthread_run(audit_send_list_thread, dest, "audit_send_list");
1186 if (IS_ERR(tsk)) {
1187 skb_queue_purge(&dest->q);
1188 put_net(dest->net);
1189 kfree(dest);
1190 return PTR_ERR(tsk);
1191 }
1192
1193 return 0;
1194 }
1195
1196 int audit_comparator(u32 left, u32 op, u32 right)
1197 {
1198 switch (op) {
1199 case Audit_equal:
1200 return (left == right);
1201 case Audit_not_equal:
1202 return (left != right);
1203 case Audit_lt:
1204 return (left < right);
1205 case Audit_le:
1206 return (left <= right);
1207 case Audit_gt:
1208 return (left > right);
1209 case Audit_ge:
1210 return (left >= right);
1211 case Audit_bitmask:
1212 return (left & right);
1213 case Audit_bittest:
1214 return ((left & right) == right);
1215 default:
1216 return 0;
1217 }
1218 }
1219
1220 int audit_uid_comparator(kuid_t left, u32 op, kuid_t right)
1221 {
1222 switch (op) {
1223 case Audit_equal:
1224 return uid_eq(left, right);
1225 case Audit_not_equal:
1226 return !uid_eq(left, right);
1227 case Audit_lt:
1228 return uid_lt(left, right);
1229 case Audit_le:
1230 return uid_lte(left, right);
1231 case Audit_gt:
1232 return uid_gt(left, right);
1233 case Audit_ge:
1234 return uid_gte(left, right);
1235 case Audit_bitmask:
1236 case Audit_bittest:
1237 default:
1238 return 0;
1239 }
1240 }
1241
1242 int audit_gid_comparator(kgid_t left, u32 op, kgid_t right)
1243 {
1244 switch (op) {
1245 case Audit_equal:
1246 return gid_eq(left, right);
1247 case Audit_not_equal:
1248 return !gid_eq(left, right);
1249 case Audit_lt:
1250 return gid_lt(left, right);
1251 case Audit_le:
1252 return gid_lte(left, right);
1253 case Audit_gt:
1254 return gid_gt(left, right);
1255 case Audit_ge:
1256 return gid_gte(left, right);
1257 case Audit_bitmask:
1258 case Audit_bittest:
1259 default:
1260 return 0;
1261 }
1262 }
1263
1264 /**
1265 * parent_len - find the length of the parent portion of a pathname
1266 * @path: pathname of which to determine length
1267 */
1268 int parent_len(const char *path)
1269 {
1270 int plen;
1271 const char *p;
1272
1273 plen = strlen(path);
1274
1275 if (plen == 0)
1276 return plen;
1277
1278 /* disregard trailing slashes */
1279 p = path + plen - 1;
1280 while ((*p == '/') && (p > path))
1281 p--;
1282
1283 /* walk backward until we find the next slash or hit beginning */
1284 while ((*p != '/') && (p > path))
1285 p--;
1286
1287 /* did we find a slash? Then increment to include it in path */
1288 if (*p == '/')
1289 p++;
1290
1291 return p - path;
1292 }
1293
1294 /**
1295 * audit_compare_dname_path - compare given dentry name with last component in
1296 * given path. Return of 0 indicates a match.
1297 * @dname: dentry name that we're comparing
1298 * @path: full pathname that we're comparing
1299 * @parentlen: length of the parent if known. Passing in AUDIT_NAME_FULL
1300 * here indicates that we must compute this value.
1301 */
1302 int audit_compare_dname_path(const struct qstr *dname, const char *path, int parentlen)
1303 {
1304 int dlen, pathlen;
1305 const char *p;
1306
1307 dlen = dname->len;
1308 pathlen = strlen(path);
1309 if (pathlen < dlen)
1310 return 1;
1311
1312 parentlen = parentlen == AUDIT_NAME_FULL ? parent_len(path) : parentlen;
1313 if (pathlen - parentlen != dlen)
1314 return 1;
1315
1316 p = path + parentlen;
1317
1318 return strncmp(p, dname->name, dlen);
1319 }
1320
1321 int audit_filter(int msgtype, unsigned int listtype)
1322 {
1323 struct audit_entry *e;
1324 int ret = 1; /* Audit by default */
1325
1326 rcu_read_lock();
1327 list_for_each_entry_rcu(e, &audit_filter_list[listtype], list) {
1328 int i, result = 0;
1329
1330 for (i = 0; i < e->rule.field_count; i++) {
1331 struct audit_field *f = &e->rule.fields[i];
1332 pid_t pid;
1333 struct lsmblob blob;
1334
1335 switch (f->type) {
1336 case AUDIT_PID:
1337 pid = task_pid_nr(current);
1338 result = audit_comparator(pid, f->op, f->val);
1339 break;
1340 case AUDIT_UID:
1341 result = audit_uid_comparator(current_uid(), f->op, f->uid);
1342 break;
1343 case AUDIT_GID:
1344 result = audit_gid_comparator(current_gid(), f->op, f->gid);
1345 break;
1346 case AUDIT_LOGINUID:
1347 result = audit_uid_comparator(audit_get_loginuid(current),
1348 f->op, f->uid);
1349 break;
1350 case AUDIT_LOGINUID_SET:
1351 result = audit_comparator(audit_loginuid_set(current),
1352 f->op, f->val);
1353 break;
1354 case AUDIT_MSGTYPE:
1355 result = audit_comparator(msgtype, f->op, f->val);
1356 break;
1357 case AUDIT_SUBJ_USER:
1358 case AUDIT_SUBJ_ROLE:
1359 case AUDIT_SUBJ_TYPE:
1360 case AUDIT_SUBJ_SEN:
1361 case AUDIT_SUBJ_CLR:
1362 if (f->lsm_isset) {
1363 security_task_getsecid_subj(current, &blob);
1364 result = security_audit_rule_match(
1365 &blob, f->type, f->op,
1366 f->lsm_rules);
1367 }
1368 break;
1369 case AUDIT_EXE:
1370 result = audit_exe_compare(current, e->rule.exe);
1371 if (f->op == Audit_not_equal)
1372 result = !result;
1373 break;
1374 default:
1375 goto unlock_and_return;
1376 }
1377 if (result < 0) /* error */
1378 goto unlock_and_return;
1379 if (!result)
1380 break;
1381 }
1382 if (result > 0) {
1383 if (e->rule.action == AUDIT_NEVER || listtype == AUDIT_FILTER_EXCLUDE)
1384 ret = 0;
1385 break;
1386 }
1387 }
1388 unlock_and_return:
1389 rcu_read_unlock();
1390 return ret;
1391 }
1392
1393 static int update_lsm_rules(struct audit_krule *r)
1394 {
1395 struct audit_entry *entry = container_of(r, struct audit_entry, rule);
1396 struct audit_entry *nentry;
1397 int err = 0;
1398
1399 if (!security_audit_rule_known(r))
1400 return 0;
1401
1402 nentry = audit_dupe_rule(r);
1403 if (entry->rule.exe)
1404 audit_remove_mark(entry->rule.exe);
1405 if (IS_ERR(nentry)) {
1406 /* save the first error encountered for the
1407 * return value */
1408 err = PTR_ERR(nentry);
1409 audit_panic("error updating LSM filters");
1410 if (r->watch)
1411 list_del(&r->rlist);
1412 list_del_rcu(&entry->list);
1413 list_del(&r->list);
1414 } else {
1415 if (r->watch || r->tree)
1416 list_replace_init(&r->rlist, &nentry->rule.rlist);
1417 list_replace_rcu(&entry->list, &nentry->list);
1418 list_replace(&r->list, &nentry->rule.list);
1419 }
1420 call_rcu(&entry->rcu, audit_free_rule_rcu);
1421
1422 return err;
1423 }
1424
1425 /* This function will re-initialize the lsm_rules field of all applicable rules.
1426 * It will traverse the filter lists serarching for rules that contain LSM
1427 * specific filter fields. When such a rule is found, it is copied, the
1428 * LSM field is re-initialized, and the old rule is replaced with the
1429 * updated rule. */
1430 int audit_update_lsm_rules(void)
1431 {
1432 struct audit_krule *r, *n;
1433 int i, err = 0;
1434
1435 /* audit_filter_mutex synchronizes the writers */
1436 mutex_lock(&audit_filter_mutex);
1437
1438 for (i = 0; i < AUDIT_NR_FILTERS; i++) {
1439 list_for_each_entry_safe(r, n, &audit_rules_list[i], list) {
1440 int res = update_lsm_rules(r);
1441 if (!err)
1442 err = res;
1443 }
1444 }
1445 mutex_unlock(&audit_filter_mutex);
1446
1447 return err;
1448 }