diff options
author | Will Deacon <will.deacon@arm.com> | 2017-10-03 14:25:26 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-10-10 05:50:17 -0400 |
commit | 26c4eb192c6224e5297496cead36404b62fb071b (patch) | |
tree | df7303338d50849ac975d9fc1e808a900a22fcc9 /security | |
parent | 0dc208b5d5feedc795cbf124539decd182c8e99e (diff) |
locking/rwsem, security/apparmor: Replace homebrew use of write_can_lock() with lockdep
The lockdep subsystem provides a robust way to assert that a lock is
held, so use that instead of write_can_lock, which can give incorrect
results for qrwlocks.
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: paulmck@linux.vnet.ibm.com
Link: http://lkml.kernel.org/r/1507055129-12300-1-git-send-email-will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'security')
-rw-r--r-- | security/apparmor/include/lib.h | 11 | ||||
-rw-r--r-- | security/apparmor/label.c | 8 |
2 files changed, 4 insertions, 15 deletions
diff --git a/security/apparmor/include/lib.h b/security/apparmor/include/lib.h index 436b3a722357..f546707a2bbb 100644 --- a/security/apparmor/include/lib.h +++ b/security/apparmor/include/lib.h | |||
@@ -19,17 +19,6 @@ | |||
19 | 19 | ||
20 | #include "match.h" | 20 | #include "match.h" |
21 | 21 | ||
22 | /* Provide our own test for whether a write lock is held for asserts | ||
23 | * this is because on none SMP systems write_can_lock will always | ||
24 | * resolve to true, which is what you want for code making decisions | ||
25 | * based on it, but wrong for asserts checking that the lock is held | ||
26 | */ | ||
27 | #ifdef CONFIG_SMP | ||
28 | #define write_is_locked(X) !write_can_lock(X) | ||
29 | #else | ||
30 | #define write_is_locked(X) (1) | ||
31 | #endif /* CONFIG_SMP */ | ||
32 | |||
33 | /* | 22 | /* |
34 | * DEBUG remains global (no per profile flag) since it is mostly used in sysctl | 23 | * DEBUG remains global (no per profile flag) since it is mostly used in sysctl |
35 | * which is not related to profile accesses. | 24 | * which is not related to profile accesses. |
diff --git a/security/apparmor/label.c b/security/apparmor/label.c index c5b99b954580..ad28e03a6f30 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c | |||
@@ -80,7 +80,7 @@ void __aa_proxy_redirect(struct aa_label *orig, struct aa_label *new) | |||
80 | 80 | ||
81 | AA_BUG(!orig); | 81 | AA_BUG(!orig); |
82 | AA_BUG(!new); | 82 | AA_BUG(!new); |
83 | AA_BUG(!write_is_locked(&labels_set(orig)->lock)); | 83 | lockdep_assert_held_exclusive(&labels_set(orig)->lock); |
84 | 84 | ||
85 | tmp = rcu_dereference_protected(orig->proxy->label, | 85 | tmp = rcu_dereference_protected(orig->proxy->label, |
86 | &labels_ns(orig)->lock); | 86 | &labels_ns(orig)->lock); |
@@ -571,7 +571,7 @@ static bool __label_remove(struct aa_label *label, struct aa_label *new) | |||
571 | 571 | ||
572 | AA_BUG(!ls); | 572 | AA_BUG(!ls); |
573 | AA_BUG(!label); | 573 | AA_BUG(!label); |
574 | AA_BUG(!write_is_locked(&ls->lock)); | 574 | lockdep_assert_held_exclusive(&ls->lock); |
575 | 575 | ||
576 | if (new) | 576 | if (new) |
577 | __aa_proxy_redirect(label, new); | 577 | __aa_proxy_redirect(label, new); |
@@ -608,7 +608,7 @@ static bool __label_replace(struct aa_label *old, struct aa_label *new) | |||
608 | AA_BUG(!ls); | 608 | AA_BUG(!ls); |
609 | AA_BUG(!old); | 609 | AA_BUG(!old); |
610 | AA_BUG(!new); | 610 | AA_BUG(!new); |
611 | AA_BUG(!write_is_locked(&ls->lock)); | 611 | lockdep_assert_held_exclusive(&ls->lock); |
612 | AA_BUG(new->flags & FLAG_IN_TREE); | 612 | AA_BUG(new->flags & FLAG_IN_TREE); |
613 | 613 | ||
614 | if (!label_is_stale(old)) | 614 | if (!label_is_stale(old)) |
@@ -645,7 +645,7 @@ static struct aa_label *__label_insert(struct aa_labelset *ls, | |||
645 | AA_BUG(!ls); | 645 | AA_BUG(!ls); |
646 | AA_BUG(!label); | 646 | AA_BUG(!label); |
647 | AA_BUG(labels_set(label) != ls); | 647 | AA_BUG(labels_set(label) != ls); |
648 | AA_BUG(!write_is_locked(&ls->lock)); | 648 | lockdep_assert_held_exclusive(&ls->lock); |
649 | AA_BUG(label->flags & FLAG_IN_TREE); | 649 | AA_BUG(label->flags & FLAG_IN_TREE); |
650 | 650 | ||
651 | /* Figure out where to put new node */ | 651 | /* Figure out where to put new node */ |