aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2018-05-04 05:18:07 -0400
committerJohn Johansen <john.johansen@canonical.com>2018-06-07 04:49:21 -0400
commit38125c2c2beb3c770d8fcdbcd846bd95938866d3 (patch)
treef40478007c4c3350f5bd83ae94931c5b98de513e
parent52e7128ebbdd7b05ba8615efbe410e88a5925a1d (diff)
apparmor: improve get_buffers macro by using get_cpu_ptr
Refactor get_buffers so the cpu_ptr can be obtained in the outer layer, instead of inside the macro. This also enables us to cleanup the code and use get_cpu_ptr, to handle the preempt_disable() Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Seth Arnold <seth.arnold@canonical.com>
-rw-r--r--security/apparmor/include/path.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
index e042b994f2b8..b6380c5f0097 100644
--- a/security/apparmor/include/path.h
+++ b/security/apparmor/include/path.h
@@ -43,10 +43,11 @@ struct aa_buffers {
43 43
44DECLARE_PER_CPU(struct aa_buffers, aa_buffers); 44DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
45 45
46#define ASSIGN(FN, X, N) ((X) = FN(N)) 46#define ASSIGN(FN, A, X, N) ((X) = FN(A, N))
47#define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/ 47#define EVAL1(FN, A, X) ASSIGN(FN, A, X, 0) /*X = FN(0)*/
48#define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1); EVAL1(FN, Y); } while (0) 48#define EVAL2(FN, A, X, Y...) \
49#define EVAL(FN, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, X) 49 do { ASSIGN(FN, A, X, 1); EVAL1(FN, A, Y); } while (0)
50#define EVAL(FN, A, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, A, X)
50 51
51#define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++) 52#define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
52 53
@@ -56,26 +57,24 @@ DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
56#define AA_BUG_PREEMPT_ENABLED(X) /* nop */ 57#define AA_BUG_PREEMPT_ENABLED(X) /* nop */
57#endif 58#endif
58 59
59#define __get_buffer(N) ({ \ 60#define __get_buffer(C, N) ({ \
60 struct aa_buffers *__cpu_var; \
61 AA_BUG_PREEMPT_ENABLED("__get_buffer without preempt disabled"); \ 61 AA_BUG_PREEMPT_ENABLED("__get_buffer without preempt disabled"); \
62 __cpu_var = this_cpu_ptr(&aa_buffers); \ 62 (C)->buf[(N)]; })
63 __cpu_var->buf[(N)]; })
64 63
65#define __get_buffers(X...) EVAL(__get_buffer, X) 64#define __get_buffers(C, X...) EVAL(__get_buffer, C, X)
66 65
67#define __put_buffers(X, Y...) ((void)&(X)) 66#define __put_buffers(X, Y...) ((void)&(X))
68 67
69#define get_buffers(X...) \ 68#define get_buffers(X...) \
70do { \ 69do { \
71 preempt_disable(); \ 70 struct aa_buffers *__cpu_var = get_cpu_ptr(&aa_buffers); \
72 __get_buffers(X); \ 71 __get_buffers(__cpu_var, X); \
73} while (0) 72} while (0)
74 73
75#define put_buffers(X, Y...) \ 74#define put_buffers(X, Y...) \
76do { \ 75do { \
77 __put_buffers(X, Y); \ 76 __put_buffers(X, Y); \
78 preempt_enable(); \ 77 put_cpu_ptr(&aa_buffers); \
79} while (0) 78} while (0)
80 79
81#endif /* __AA_PATH_H */ 80#endif /* __AA_PATH_H */