hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/security/apparmor/label.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AppArmor security module
34 *
45 * This file contains AppArmor label definitions
56 *
67 * Copyright 2017 Canonical Ltd.
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU General Public License as
10
- * published by the Free Software Foundation, version 2 of the
11
- * License.
128 */
139
1410 #include <linux/audit.h>
....@@ -80,7 +76,7 @@
8076
8177 AA_BUG(!orig);
8278 AA_BUG(!new);
83
- lockdep_assert_held_exclusive(&labels_set(orig)->lock);
79
+ lockdep_assert_held_write(&labels_set(orig)->lock);
8480
8581 tmp = rcu_dereference_protected(orig->proxy->label,
8682 &labels_ns(orig)->lock);
....@@ -313,10 +309,8 @@
313309 }
314310
315311
316
-static void label_destroy(struct aa_label *label)
312
+void aa_label_destroy(struct aa_label *label)
317313 {
318
- struct aa_label *tmp;
319
-
320314 AA_BUG(!label);
321315
322316 if (!label_isprofile(label)) {
....@@ -332,16 +326,13 @@
332326 }
333327 }
334328
335
- if (rcu_dereference_protected(label->proxy->label, true) == label)
336
- rcu_assign_pointer(label->proxy->label, NULL);
337
-
329
+ if (label->proxy) {
330
+ if (rcu_dereference_protected(label->proxy->label, true) == label)
331
+ rcu_assign_pointer(label->proxy->label, NULL);
332
+ aa_put_proxy(label->proxy);
333
+ }
338334 aa_free_secid(label->secid);
339335
340
- tmp = rcu_dereference_protected(label->proxy->label, true);
341
- if (tmp == label)
342
- rcu_assign_pointer(label->proxy->label, NULL);
343
-
344
- aa_put_proxy(label->proxy);
345336 label->proxy = (struct aa_proxy *) PROXY_POISON + 1;
346337 }
347338
....@@ -350,7 +341,7 @@
350341 if (!label)
351342 return;
352343
353
- label_destroy(label);
344
+ aa_label_destroy(label);
354345 kfree(label);
355346 }
356347
....@@ -603,7 +594,7 @@
603594
604595 AA_BUG(!ls);
605596 AA_BUG(!label);
606
- lockdep_assert_held_exclusive(&ls->lock);
597
+ lockdep_assert_held_write(&ls->lock);
607598
608599 if (new)
609600 __aa_proxy_redirect(label, new);
....@@ -640,7 +631,7 @@
640631 AA_BUG(!ls);
641632 AA_BUG(!old);
642633 AA_BUG(!new);
643
- lockdep_assert_held_exclusive(&ls->lock);
634
+ lockdep_assert_held_write(&ls->lock);
644635 AA_BUG(new->flags & FLAG_IN_TREE);
645636
646637 if (!label_is_stale(old))
....@@ -677,7 +668,7 @@
677668 AA_BUG(!ls);
678669 AA_BUG(!label);
679670 AA_BUG(labels_set(label) != ls);
680
- lockdep_assert_held_exclusive(&ls->lock);
671
+ lockdep_assert_held_write(&ls->lock);
681672 AA_BUG(label->flags & FLAG_IN_TREE);
682673
683674 /* Figure out where to put new node */
....@@ -1641,9 +1632,9 @@
16411632 AA_BUG(!str && size != 0);
16421633 AA_BUG(!label);
16431634
1644
- if (flags & FLAG_ABS_ROOT) {
1635
+ if (AA_DEBUG_LABEL && (flags & FLAG_ABS_ROOT)) {
16451636 ns = root_ns;
1646
- len = snprintf(str, size, "=");
1637
+ len = snprintf(str, size, "_");
16471638 update_for_len(total, len, size, str);
16481639 } else if (!ns) {
16491640 ns = labels_ns(label);
....@@ -1754,7 +1745,7 @@
17541745 if (!use_label_hname(ns, label, flags) ||
17551746 display_mode(ns, label, flags)) {
17561747 len = aa_label_asxprint(&name, ns, label, flags, gfp);
1757
- if (len == -1) {
1748
+ if (len < 0) {
17581749 AA_DEBUG("label print error");
17591750 return;
17601751 }
....@@ -1782,17 +1773,17 @@
17821773 int len;
17831774
17841775 len = aa_label_asxprint(&str, ns, label, flags, gfp);
1785
- if (len == -1) {
1776
+ if (len < 0) {
17861777 AA_DEBUG("label print error");
17871778 return;
17881779 }
1789
- seq_printf(f, "%s", str);
1780
+ seq_puts(f, str);
17901781 kfree(str);
17911782 } else if (display_mode(ns, label, flags))
17921783 seq_printf(f, "%s (%s)", label->hname,
17931784 label_modename(ns, label, flags));
17941785 else
1795
- seq_printf(f, "%s", label->hname);
1786
+ seq_puts(f, label->hname);
17961787 }
17971788
17981789 void aa_label_xprintk(struct aa_ns *ns, struct aa_label *label, int flags,
....@@ -1805,7 +1796,7 @@
18051796 int len;
18061797
18071798 len = aa_label_asxprint(&str, ns, label, flags, gfp);
1808
- if (len == -1) {
1799
+ if (len < 0) {
18091800 AA_DEBUG("label print error");
18101801 return;
18111802 }
....@@ -1905,7 +1896,8 @@
19051896 AA_BUG(!str);
19061897
19071898 str = skipn_spaces(str, n);
1908
- if (str == NULL || (*str == '=' && base != &root_ns->unconfined->label))
1899
+ if (str == NULL || (AA_DEBUG_LABEL && *str == '_' &&
1900
+ base != &root_ns->unconfined->label))
19091901 return ERR_PTR(-EINVAL);
19101902
19111903 len = label_count_strn_entries(str, end - str);