Skip to content

Commit f567e7f

Browse files
committed
apparmor: extend policydb permission set by making use of the xbits
The policydb permission set has left the xbits unused. Make them available for mediation. Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent c1ed5da commit f567e7f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

security/apparmor/apparmorfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,7 @@ static struct aa_sfs_entry aa_sfs_entry_versions[] = {
23342334
AA_SFS_FILE_BOOLEAN("v6", 1),
23352335
AA_SFS_FILE_BOOLEAN("v7", 1),
23362336
AA_SFS_FILE_BOOLEAN("v8", 1),
2337+
AA_SFS_FILE_BOOLEAN("v9", 1),
23372338
{ }
23382339
};
23392340

security/apparmor/include/file.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static inline u16 dfa_map_xindex(u16 mask)
142142
*/
143143
#define dfa_user_allow(dfa, state) (((ACCEPT_TABLE(dfa)[state]) & 0x7f) | \
144144
((ACCEPT_TABLE(dfa)[state]) & 0x80000000))
145+
#define dfa_user_xbits(dfa, state) (((ACCEPT_TABLE(dfa)[state]) >> 7) & 0x7f)
145146
#define dfa_user_audit(dfa, state) ((ACCEPT_TABLE2(dfa)[state]) & 0x7f)
146147
#define dfa_user_quiet(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 7) & 0x7f)
147148
#define dfa_user_xindex(dfa, state) \
@@ -150,6 +151,8 @@ static inline u16 dfa_map_xindex(u16 mask)
150151
#define dfa_other_allow(dfa, state) ((((ACCEPT_TABLE(dfa)[state]) >> 14) & \
151152
0x7f) | \
152153
((ACCEPT_TABLE(dfa)[state]) & 0x80000000))
154+
#define dfa_other_xbits(dfa, state) \
155+
((((ACCEPT_TABLE(dfa)[state]) >> 7) >> 14) & 0x7f)
153156
#define dfa_other_audit(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 14) & 0x7f)
154157
#define dfa_other_quiet(dfa, state) \
155158
((((ACCEPT_TABLE2(dfa)[state]) >> 7) >> 14) & 0x7f)

security/apparmor/lib.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,39 @@ static u32 map_other(u32 x)
322322
((x & 0x60) << 19); /* SETOPT/GETOPT */
323323
}
324324

325+
static u32 map_xbits(u32 x)
326+
{
327+
return ((x & 0x1) << 7) |
328+
((x & 0x7e) << 9);
329+
}
330+
325331
void aa_compute_perms(struct aa_dfa *dfa, unsigned int state,
326332
struct aa_perms *perms)
327333
{
334+
/* This mapping is convulated due to history.
335+
* v1-v4: only file perms
336+
* v5: added policydb which dropped in perm user conditional to
337+
* gain new perm bits, but had to map around the xbits because
338+
* the userspace compiler was still munging them.
339+
* v9: adds using the xbits in policydb because the compiler now
340+
* supports treating policydb permission bits different.
341+
* Unfortunately there is not way to force auditing on the
342+
* perms represented by the xbits
343+
*/
328344
*perms = (struct aa_perms) {
329-
.allow = dfa_user_allow(dfa, state),
345+
.allow = dfa_user_allow(dfa, state) |
346+
map_xbits(dfa_user_xbits(dfa, state)),
330347
.audit = dfa_user_audit(dfa, state),
331-
.quiet = dfa_user_quiet(dfa, state),
348+
.quiet = dfa_user_quiet(dfa, state) |
349+
map_xbits(dfa_other_xbits(dfa, state)),
332350
};
333351

334-
/* for v5 perm mapping in the policydb, the other set is used
352+
/* for v5-v9 perm mapping in the policydb, the other set is used
335353
* to extend the general perm set
336354
*/
337355
perms->allow |= map_other(dfa_other_allow(dfa, state));
338356
perms->audit |= map_other(dfa_other_audit(dfa, state));
339357
perms->quiet |= map_other(dfa_other_quiet(dfa, state));
340-
// perms->xindex = dfa_user_xindex(dfa, state);
341358
}
342359

343360
/**

security/apparmor/mount.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ static struct aa_perms compute_mnt_perms(struct aa_dfa *dfa,
217217
.allow = dfa_user_allow(dfa, state),
218218
.audit = dfa_user_audit(dfa, state),
219219
.quiet = dfa_user_quiet(dfa, state),
220-
.xindex = dfa_user_xindex(dfa, state),
221220
};
222221

223222
return perms;

0 commit comments

Comments
 (0)