hc
2023-11-06 36f0949ef9854b82a9a3154d970da4e3b8d12a61
kernel/security/apparmor/include/path.h
....@@ -40,8 +40,10 @@
4040
4141 #include <linux/percpu.h>
4242 #include <linux/preempt.h>
43
+#include <linux/locallock.h>
4344
4445 DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
46
+DECLARE_LOCAL_IRQ_LOCK(aa_buffers_lock);
4547
4648 #define ASSIGN(FN, A, X, N) ((X) = FN(A, N))
4749 #define EVAL1(FN, A, X) ASSIGN(FN, A, X, 0) /*X = FN(0)*/
....@@ -51,7 +53,17 @@
5153
5254 #define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
5355
54
-#ifdef CONFIG_DEBUG_PREEMPT
56
+#ifdef CONFIG_PREEMPT_RT_BASE
57
+static inline void AA_BUG_PREEMPT_ENABLED(const char *s)
58
+{
59
+ struct local_irq_lock *lv;
60
+
61
+ lv = this_cpu_ptr(&aa_buffers_lock);
62
+ WARN_ONCE(lv->owner != current,
63
+ "__get_buffer without aa_buffers_lock\n");
64
+}
65
+
66
+#elif defined(CONFIG_DEBUG_PREEMPT)
5567 #define AA_BUG_PREEMPT_ENABLED(X) AA_BUG(preempt_count() <= 0, X)
5668 #else
5769 #define AA_BUG_PREEMPT_ENABLED(X) /* nop */
....@@ -67,14 +79,15 @@
6779
6880 #define get_buffers(X...) \
6981 do { \
70
- struct aa_buffers *__cpu_var = get_cpu_ptr(&aa_buffers); \
82
+ struct aa_buffers *__cpu_var; \
83
+ __cpu_var = get_locked_ptr(aa_buffers_lock, &aa_buffers); \
7184 __get_buffers(__cpu_var, X); \
7285 } while (0)
7386
7487 #define put_buffers(X, Y...) \
7588 do { \
7689 __put_buffers(X, Y); \
77
- put_cpu_ptr(&aa_buffers); \
90
+ put_locked_ptr(aa_buffers_lock, &aa_buffers); \
7891 } while (0)
7992
8093 #endif /* __AA_PATH_H */