Skip to content

Commit ca916e8

Browse files
committed
apparmor: add cross check permission helper macros
The cross check permission helper macros will help simplify code that does cross task permission checks like ptrace. Signed-off-by: John Johansen <[email protected]>
1 parent 86b92cb commit ca916e8

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

security/apparmor/include/perms.h

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,47 @@ struct aa_perms {
9292
extern struct aa_perms nullperms;
9393
extern struct aa_perms allperms;
9494

95-
struct aa_profile;
95+
96+
#define xcheck(FN1, FN2) \
97+
({ \
98+
int e, error = FN1; \
99+
e = FN2; \
100+
if (e) \
101+
error = e; \
102+
error; \
103+
})
104+
105+
106+
/*
107+
* TODO: update for labels pointing to labels instead of profiles
108+
* TODO: optimize the walk, currently does subwalk of L2 for each P in L1
109+
* gah this doesn't allow for label compound check!!!!
110+
*/
111+
#define xcheck_ns_profile_profile(P1, P2, FN, args...) \
112+
({ \
113+
int ____e = 0; \
114+
if (P1->ns == P2->ns) \
115+
____e = FN((P1), (P2), args); \
116+
(____e); \
117+
})
118+
119+
#define xcheck_ns_profile_label(P, L, FN, args...) \
120+
({ \
121+
struct aa_profile *__p2; \
122+
fn_for_each((L), __p2, \
123+
xcheck_ns_profile_profile((P), __p2, (FN), args)); \
124+
})
125+
126+
#define xcheck_ns_labels(L1, L2, FN, args...) \
127+
({ \
128+
struct aa_profile *__p1; \
129+
fn_for_each((L1), __p1, FN(__p1, (L2), args)); \
130+
})
131+
132+
/* Do the cross check but applying FN at the profiles level */
133+
#define xcheck_labels_profiles(L1, L2, FN, args...) \
134+
xcheck_ns_labels((L1), (L2), xcheck_ns_profile_label, (FN), args)
135+
96136

97137
void aa_perm_mask_to_str(char *str, const char *chrs, u32 mask);
98138
void aa_audit_perm_names(struct audit_buffer *ab, const char **names, u32 mask);

0 commit comments

Comments
 (0)