Skip to content

Commit b01d3fb

Browse files
author
James Morris
committed
Merge branch 'for-security' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor into next
2 parents 6041e83 + 2d4cee7 commit b01d3fb

13 files changed

Lines changed: 189 additions & 52 deletions

File tree

‎security/apparmor/Makefile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ clean-files := capability_names.h rlim_names.h
1515
# to
1616
# [1] = "dac_override",
1717
quiet_cmd_make-caps = GEN $@
18-
cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ;\
18+
cmd_make-caps = echo "static const char const *capability_names[] = {" > $@ ;\
1919
sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
2020
-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
2121
echo "};" >> $@
@@ -43,7 +43,8 @@ cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ;\
4343
# to
4444
# #define AA_FS_RLIMIT_MASK "fsize stack"
4545
quiet_cmd_make-rlim = GEN $@
46-
cmd_make-rlim = echo "static const char *rlim_names[RLIM_NLIMITS] = {" > $@ ;\
46+
cmd_make-rlim = echo "static const char const *rlim_names[RLIM_NLIMITS] = {" \
47+
> $@ ;\
4748
sed $< >> $@ -r -n \
4849
-e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
4950
echo "};" >> $@ ;\

‎security/apparmor/audit.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "include/audit.h"
2020
#include "include/policy.h"
2121

22-
const char *op_table[] = {
22+
const char *const op_table[] = {
2323
"null",
2424

2525
"sysctl",
@@ -73,15 +73,15 @@ const char *op_table[] = {
7373
"profile_remove"
7474
};
7575

76-
const char *audit_mode_names[] = {
76+
const char *const audit_mode_names[] = {
7777
"normal",
7878
"quiet_denied",
7979
"quiet",
8080
"noquiet",
8181
"all"
8282
};
8383

84-
static char *aa_audit_type[] = {
84+
static const char *const aa_audit_type[] = {
8585
"AUDIT",
8686
"ALLOWED",
8787
"DENIED",

‎security/apparmor/domain.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,12 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
372372
state = profile->file.start;
373373

374374
/* buffer freed below, name is pointer into buffer */
375-
error = aa_get_name(&bprm->file->f_path, profile->path_flags, &buffer,
376-
&name);
375+
error = aa_path_name(&bprm->file->f_path, profile->path_flags, &buffer,
376+
&name, &info);
377377
if (error) {
378378
if (profile->flags &
379379
(PFLAG_IX_ON_NAME_ERROR | PFLAG_UNCONFINED))
380380
error = 0;
381-
info = "Exec failed name resolution";
382381
name = bprm->filename;
383382
goto audit;
384383
}

‎security/apparmor/file.c‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,16 @@ int aa_path_perm(int op, struct aa_profile *profile, struct path *path,
278278
int error;
279279

280280
flags |= profile->path_flags | (S_ISDIR(cond->mode) ? PATH_IS_DIR : 0);
281-
error = aa_get_name(path, flags, &buffer, &name);
281+
error = aa_path_name(path, flags, &buffer, &name, &info);
282282
if (error) {
283283
if (error == -ENOENT && is_deleted(path->dentry)) {
284284
/* Access to open files that are deleted are
285285
* give a pass (implicit delegation)
286286
*/
287287
error = 0;
288+
info = NULL;
288289
perms.allow = request;
289-
} else if (error == -ENOENT)
290-
info = "Failed name lookup - deleted entry";
291-
else if (error == -ESTALE)
292-
info = "Failed name lookup - disconnected path";
293-
else if (error == -ENAMETOOLONG)
294-
info = "Failed name lookup - name too long";
295-
else
296-
info = "Failed name lookup";
290+
}
297291
} else {
298292
aa_str_perms(profile->file.dfa, profile->file.start, name, cond,
299293
&perms);
@@ -364,12 +358,14 @@ int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
364358
lperms = nullperms;
365359

366360
/* buffer freed below, lname is pointer in buffer */
367-
error = aa_get_name(&link, profile->path_flags, &buffer, &lname);
361+
error = aa_path_name(&link, profile->path_flags, &buffer, &lname,
362+
&info);
368363
if (error)
369364
goto audit;
370365

371366
/* buffer2 freed below, tname is pointer in buffer2 */
372-
error = aa_get_name(&target, profile->path_flags, &buffer2, &tname);
367+
error = aa_path_name(&target, profile->path_flags, &buffer2, &tname,
368+
&info);
373369
if (error)
374370
goto audit;
375371

‎security/apparmor/include/apparmor.h‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
#include "match.h"
2121

22+
/*
23+
* Class of mediation types in the AppArmor policy db
24+
*/
25+
#define AA_CLASS_ENTRY 0
26+
#define AA_CLASS_UNKNOWN 1
27+
#define AA_CLASS_FILE 2
28+
#define AA_CLASS_CAP 3
29+
#define AA_CLASS_NET 4
30+
#define AA_CLASS_RLIMITS 5
31+
#define AA_CLASS_DOMAIN 6
32+
33+
#define AA_CLASS_LAST AA_CLASS_DOMAIN
34+
2235
/* Control parameters settable through module/boot flags */
2336
extern enum audit_mode aa_g_audit;
2437
extern bool aa_g_audit_header;
@@ -81,7 +94,7 @@ static inline unsigned int aa_dfa_null_transition(struct aa_dfa *dfa,
8194
unsigned int start)
8295
{
8396
/* the null transition only needs the string's null terminator byte */
84-
return aa_dfa_match_len(dfa, start, "", 1);
97+
return aa_dfa_next(dfa, start, 0);
8598
}
8699

87100
static inline bool mediated_filesystem(struct inode *inode)

‎security/apparmor/include/audit.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
struct aa_profile;
2727

28-
extern const char *audit_mode_names[];
28+
extern const char *const audit_mode_names[];
2929
#define AUDIT_MAX_INDEX 5
3030

3131
enum audit_mode {
@@ -47,7 +47,7 @@ enum audit_type {
4747
AUDIT_APPARMOR_AUTO
4848
};
4949

50-
extern const char *op_table[];
50+
extern const char *const op_table[];
5151
enum aa_ops {
5252
OP_NULL,
5353

‎security/apparmor/include/match.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
116116
const char *str, int len);
117117
unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
118118
const char *str);
119+
unsigned int aa_dfa_next(struct aa_dfa *dfa, unsigned int state,
120+
const char c);
121+
119122
void aa_dfa_free_kref(struct kref *kref);
120123

121124
/**

‎security/apparmor/include/path.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum path_flags {
2626
PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */
2727
};
2828

29-
int aa_get_name(struct path *path, int flags, char **buffer, const char **name);
29+
int aa_path_name(struct path *path, int flags, char **buffer,
30+
const char **name, const char **info);
3031

3132
#endif /* __AA_PATH_H */

‎security/apparmor/include/policy.h‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "file.h"
3030
#include "resource.h"
3131

32-
extern const char *profile_mode_names[];
32+
extern const char *const profile_mode_names[];
3333
#define APPARMOR_NAMES_MAX_INDEX 3
3434

3535
#define COMPLAIN_MODE(_profile) \
@@ -129,6 +129,17 @@ struct aa_namespace {
129129
struct list_head sub_ns;
130130
};
131131

132+
/* struct aa_policydb - match engine for a policy
133+
* dfa: dfa pattern match
134+
* start: set of start states for the different classes of data
135+
*/
136+
struct aa_policydb {
137+
/* Generic policy DFA specific rule types will be subsections of it */
138+
struct aa_dfa *dfa;
139+
unsigned int start[AA_CLASS_LAST + 1];
140+
141+
};
142+
132143
/* struct aa_profile - basic confinement data
133144
* @base - base components of the profile (name, refcount, lists, lock ...)
134145
* @parent: parent of profile
@@ -143,6 +154,7 @@ struct aa_namespace {
143154
* @flags: flags controlling profile behavior
144155
* @path_flags: flags controlling path generation behavior
145156
* @size: the memory consumed by this profiles rules
157+
* @policy: general match rules governing policy
146158
* @file: The set of rules governing basic file access and domain transitions
147159
* @caps: capabilities for the profile
148160
* @rlimits: rlimits for the profile
@@ -179,6 +191,7 @@ struct aa_profile {
179191
u32 path_flags;
180192
int size;
181193

194+
struct aa_policydb policy;
182195
struct aa_file_rules file;
183196
struct aa_caps caps;
184197
struct aa_rlimit rlimits;

‎security/apparmor/match.c‎

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,12 @@ unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
335335
}
336336

337337
/**
338-
* aa_dfa_next_state - traverse @dfa to find state @str stops at
338+
* aa_dfa_match - traverse @dfa to find state @str stops at
339339
* @dfa: the dfa to match @str against (NOT NULL)
340340
* @start: the state of the dfa to start matching in
341341
* @str: the null terminated string of bytes to match against the dfa (NOT NULL)
342342
*
343-
* aa_dfa_next_state will match @str against the dfa and return the state it
343+
* aa_dfa_match will match @str against the dfa and return the state it
344344
* finished matching in. The final state can be used to look up the accepting
345345
* label, or as the start state of a continuing match.
346346
*
@@ -349,5 +349,79 @@ unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
349349
unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
350350
const char *str)
351351
{
352-
return aa_dfa_match_len(dfa, start, str, strlen(str));
352+
u16 *def = DEFAULT_TABLE(dfa);
353+
u32 *base = BASE_TABLE(dfa);
354+
u16 *next = NEXT_TABLE(dfa);
355+
u16 *check = CHECK_TABLE(dfa);
356+
unsigned int state = start, pos;
357+
358+
if (state == 0)
359+
return 0;
360+
361+
/* current state is <state>, matching character *str */
362+
if (dfa->tables[YYTD_ID_EC]) {
363+
/* Equivalence class table defined */
364+
u8 *equiv = EQUIV_TABLE(dfa);
365+
/* default is direct to next state */
366+
while (*str) {
367+
pos = base[state] + equiv[(u8) *str++];
368+
if (check[pos] == state)
369+
state = next[pos];
370+
else
371+
state = def[state];
372+
}
373+
} else {
374+
/* default is direct to next state */
375+
while (*str) {
376+
pos = base[state] + (u8) *str++;
377+
if (check[pos] == state)
378+
state = next[pos];
379+
else
380+
state = def[state];
381+
}
382+
}
383+
384+
return state;
385+
}
386+
387+
/**
388+
* aa_dfa_next - step one character to the next state in the dfa
389+
* @dfa: the dfa to tranverse (NOT NULL)
390+
* @state: the state to start in
391+
* @c: the input character to transition on
392+
*
393+
* aa_dfa_match will step through the dfa by one input character @c
394+
*
395+
* Returns: state reach after input @c
396+
*/
397+
unsigned int aa_dfa_next(struct aa_dfa *dfa, unsigned int state,
398+
const char c)
399+
{
400+
u16 *def = DEFAULT_TABLE(dfa);
401+
u32 *base = BASE_TABLE(dfa);
402+
u16 *next = NEXT_TABLE(dfa);
403+
u16 *check = CHECK_TABLE(dfa);
404+
unsigned int pos;
405+
406+
/* current state is <state>, matching character *str */
407+
if (dfa->tables[YYTD_ID_EC]) {
408+
/* Equivalence class table defined */
409+
u8 *equiv = EQUIV_TABLE(dfa);
410+
/* default is direct to next state */
411+
412+
pos = base[state] + equiv[(u8) c];
413+
if (check[pos] == state)
414+
state = next[pos];
415+
else
416+
state = def[state];
417+
} else {
418+
/* default is direct to next state */
419+
pos = base[state] + (u8) c;
420+
if (check[pos] == state)
421+
state = next[pos];
422+
else
423+
state = def[state];
424+
}
425+
426+
return state;
353427
}

0 commit comments

Comments
 (0)