Skip to content

Commit 2d679f3

Browse files
committed
apparmor: switch from file_perms to aa_perms
Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent aa9aeea commit 2d679f3

5 files changed

Lines changed: 29 additions & 48 deletions

File tree

‎security/apparmor/domain.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ static int may_change_ptraced_domain(struct aa_profile *to_profile)
9393
*
9494
* Returns: permission set
9595
*/
96-
static struct file_perms change_profile_perms(struct aa_profile *profile,
97-
struct aa_ns *ns,
98-
const char *name, u32 request,
99-
unsigned int start)
96+
static struct aa_perms change_profile_perms(struct aa_profile *profile,
97+
struct aa_ns *ns,
98+
const char *name, u32 request,
99+
unsigned int start)
100100
{
101-
struct file_perms perms;
101+
struct aa_perms perms;
102102
struct path_cond cond = { };
103103
unsigned int state;
104104

@@ -342,7 +342,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
342342
struct aa_ns *ns;
343343
char *buffer = NULL;
344344
unsigned int state;
345-
struct file_perms perms = {};
345+
struct aa_perms perms = {};
346346
struct path_cond cond = {
347347
file_inode(bprm->file)->i_uid,
348348
file_inode(bprm->file)->i_mode
@@ -400,7 +400,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
400400
/* find exec permissions for name */
401401
state = aa_str_perms(profile->file.dfa, state, name, &cond, &perms);
402402
if (ctx->onexec) {
403-
struct file_perms cp;
403+
struct aa_perms cp;
404404
info = "change_profile onexec";
405405
new_profile = aa_get_newest_profile(ctx->onexec);
406406
if (!(perms.allow & AA_MAY_ONEXEC))
@@ -609,7 +609,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, bool permtest)
609609
struct aa_profile *profile, *previous_profile, *hat = NULL;
610610
char *name = NULL;
611611
int i;
612-
struct file_perms perms = {};
612+
struct aa_perms perms = {};
613613
const char *target = NULL, *info = NULL;
614614
int error = 0;
615615

@@ -748,7 +748,7 @@ int aa_change_profile(const char *fqname, bool onexec,
748748
{
749749
const struct cred *cred;
750750
struct aa_profile *profile, *target = NULL;
751-
struct file_perms perms = {};
751+
struct aa_perms perms = {};
752752
const char *info = NULL, *op;
753753
int error = 0;
754754
u32 request;

‎security/apparmor/file.c‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "include/path.h"
2020
#include "include/policy.h"
2121

22-
struct file_perms nullperms;
23-
2422
static u32 map_mask_to_chr_mask(u32 mask)
2523
{
2624
u32 m = mask & PERMS_CHRS_MASK;
@@ -92,7 +90,7 @@ static void file_audit_cb(struct audit_buffer *ab, void *va)
9290
*
9391
* Returns: %0 or error on failure
9492
*/
95-
int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
93+
int aa_audit_file(struct aa_profile *profile, struct aa_perms *perms,
9694
const char *op, u32 request, const char *name,
9795
const char *target, kuid_t ouid, const char *info, int error)
9896
{
@@ -170,7 +168,7 @@ static u32 map_old_perms(u32 old)
170168
}
171169

172170
/**
173-
* compute_perms - convert dfa compressed perms to internal perms
171+
* aa_compute_fperms - convert dfa compressed perms to internal perms
174172
* @dfa: dfa to compute perms for (NOT NULL)
175173
* @state: state in dfa
176174
* @cond: conditions to consider (NOT NULL)
@@ -180,17 +178,21 @@ static u32 map_old_perms(u32 old)
180178
*
181179
* Returns: computed permission set
182180
*/
183-
static struct file_perms compute_perms(struct aa_dfa *dfa, unsigned int state,
184-
struct path_cond *cond)
181+
struct aa_perms aa_compute_fperms(struct aa_dfa *dfa, unsigned int state,
182+
struct path_cond *cond)
185183
{
186-
struct file_perms perms;
184+
struct aa_perms perms;
187185

188186
/* FIXME: change over to new dfa format
189187
* currently file perms are encoded in the dfa, new format
190188
* splits the permissions from the dfa. This mapping can be
191189
* done at profile load
192190
*/
193-
perms.kill = 0;
191+
perms.deny = 0;
192+
perms.kill = perms.stop = 0;
193+
perms.complain = perms.cond = 0;
194+
perms.hide = 0;
195+
perms.prompt = 0;
194196

195197
if (uid_eq(current_fsuid(), cond->uid)) {
196198
perms.allow = map_old_perms(dfa_user_allow(dfa, state));
@@ -226,16 +228,11 @@ static struct file_perms compute_perms(struct aa_dfa *dfa, unsigned int state,
226228
*/
227229
unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start,
228230
const char *name, struct path_cond *cond,
229-
struct file_perms *perms)
231+
struct aa_perms *perms)
230232
{
231233
unsigned int state;
232-
if (!dfa) {
233-
*perms = nullperms;
234-
return DFA_NOMATCH;
235-
}
236-
237234
state = aa_dfa_match(dfa, start, name);
238-
*perms = compute_perms(dfa, state, cond);
235+
*perms = aa_compute_fperms(dfa, state, cond);
239236

240237
return state;
241238
}
@@ -269,7 +266,7 @@ int aa_path_perm(const char *op, struct aa_profile *profile,
269266
struct path_cond *cond)
270267
{
271268
char *buffer = NULL;
272-
struct file_perms perms = {};
269+
struct aa_perms perms = {};
273270
const char *name, *info = NULL;
274271
int error;
275272

@@ -348,7 +345,7 @@ int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
348345
};
349346
char *buffer = NULL, *buffer2 = NULL;
350347
const char *lname, *tname = NULL, *info = NULL;
351-
struct file_perms lperms, perms;
348+
struct aa_perms lperms, perms;
352349
u32 request = AA_MAY_LINK;
353350
unsigned int state;
354351
int error;

‎security/apparmor/include/file.h‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,6 @@ struct path_cond {
9090
umode_t mode;
9191
};
9292

93-
/* struct file_perms - file permission
94-
* @allow: mask of permissions that are allowed
95-
* @audit: mask of permissions to force an audit message for
96-
* @quiet: mask of permissions to quiet audit messages for
97-
* @kill: mask of permissions that when matched will kill the task
98-
* @xindex: exec transition index if @allow contains MAY_EXEC
99-
*
100-
* The @audit and @queit mask should be mutually exclusive.
101-
*/
102-
struct file_perms {
103-
u32 allow;
104-
u32 audit;
105-
u32 quiet;
106-
u32 kill;
107-
u16 xindex;
108-
};
109-
110-
extern struct file_perms nullperms;
111-
11293
#define COMBINED_PERM_MASK(X) ((X).allow | (X).audit | (X).quiet | (X).kill)
11394

11495
/* FIXME: split perms from dfa and match this to description
@@ -159,7 +140,7 @@ static inline u16 dfa_map_xindex(u16 mask)
159140
#define dfa_other_xindex(dfa, state) \
160141
dfa_map_xindex((ACCEPT_TABLE(dfa)[state] >> 14) & 0x3fff)
161142

162-
int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
143+
int aa_audit_file(struct aa_profile *profile, struct aa_perms *perms,
163144
const char *op, u32 request, const char *name,
164145
const char *target, kuid_t ouid, const char *info, int error);
165146

@@ -182,9 +163,11 @@ struct aa_file_rules {
182163
/* TODO: add delegate table */
183164
};
184165

166+
struct aa_perms aa_compute_fperms(struct aa_dfa *dfa, unsigned int state,
167+
struct path_cond *cond);
185168
unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start,
186169
const char *name, struct path_cond *cond,
187-
struct file_perms *perms);
170+
struct aa_perms *perms);
188171

189172
int aa_path_perm(const char *op, struct aa_profile *profile,
190173
const struct path *path, int flags, u32 request,

‎security/apparmor/include/perms.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct aa_perms {
8888
};
8989

9090
#define ALL_PERMS_MASK 0xffffffff
91-
91+
extern struct aa_perms nullperms;
9292
extern struct aa_perms allperms;
9393

9494
struct aa_profile;

‎security/apparmor/lib.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "include/perms.h"
2525
#include "include/policy.h"
2626

27+
struct aa_perms nullperms;
2728
struct aa_perms allperms = { .allow = ALL_PERMS_MASK,
2829
.quiet = ALL_PERMS_MASK,
2930
.hide = ALL_PERMS_MASK };

0 commit comments

Comments
 (0)