Skip to content

Commit 463f202

Browse files
committed
Merge tag 'apparmor-pr-2018-06-13' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor
Pull AppArmor updates from John Johansen: "Features - add support for mapping secids and using secctxes - add the ability to get a task's secid - add support for audit rule filtering Cleanups: - multiple typo fixes - Convert to use match_string() helper - update git and wiki locations in AppArmor docs - improve get_buffers macro by using get_cpu_ptr - Use an IDR to allocate apparmor secids Bug fixes: - fix '*seclen' is never less than zero - fix mediation of prlimit - fix memory leak when deduping profile load - fix ptrace read check - fix memory leak of rule on error exit path" * tag 'apparmor-pr-2018-06-13' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor: (21 commits) apparmor: fix ptrace read check apparmor: fix memory leak when deduping profile load apparmor: fix mediation of prlimit apparmor: fixup secid map conversion to using IDR apparmor: Use an IDR to allocate apparmor secids apparmor: Fix memory leak of rule on error exit path apparmor: modify audit rule support to support profile stacks apparmor: Add support for audit rule filtering apparmor: update git and wiki locations in AppArmor docs apparmor: Convert to use match_string() helper apparmor: improve get_buffers macro by using get_cpu_ptr apparmor: fix '*seclen' is never less than zero apparmor: fix typo "preconfinement" apparmor: fix typo "independent" apparmor: fix typo "traverse" apparmor: fix typo "type" apparmor: fix typo "replace" apparmor: fix typo "comparison" apparmor: fix typo "loosen" apparmor: add the ability to get a task's secid ...
2 parents 050e9ba + 338d0be commit 463f202

File tree

15 files changed

+313
-74
lines changed

15 files changed

+313
-74
lines changed

Documentation/admin-guide/LSM/apparmor.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Links
4444

4545
Mailing List - [email protected]
4646

47-
Wiki - http://apparmor.wiki.kernel.org/
47+
Wiki - http://wiki.apparmor.net
4848

49-
User space tools - https://launchpad.net/apparmor
49+
User space tools - https://gitlab.com/apparmor
5050

51-
Kernel module - git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
51+
Kernel module - git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor

security/apparmor/audit.c

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "include/audit.h"
2020
#include "include/policy.h"
2121
#include "include/policy_ns.h"
22-
22+
#include "include/secid.h"
2323

2424
const char *const audit_mode_names[] = {
2525
"normal",
@@ -163,3 +163,91 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
163163

164164
return aad(sa)->error;
165165
}
166+
167+
struct aa_audit_rule {
168+
struct aa_label *label;
169+
};
170+
171+
void aa_audit_rule_free(void *vrule)
172+
{
173+
struct aa_audit_rule *rule = vrule;
174+
175+
if (rule) {
176+
if (!IS_ERR(rule->label))
177+
aa_put_label(rule->label);
178+
kfree(rule);
179+
}
180+
}
181+
182+
int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
183+
{
184+
struct aa_audit_rule *rule;
185+
186+
switch (field) {
187+
case AUDIT_SUBJ_ROLE:
188+
if (op != Audit_equal && op != Audit_not_equal)
189+
return -EINVAL;
190+
break;
191+
default:
192+
return -EINVAL;
193+
}
194+
195+
rule = kzalloc(sizeof(struct aa_audit_rule), GFP_KERNEL);
196+
197+
if (!rule)
198+
return -ENOMEM;
199+
200+
/* Currently rules are treated as coming from the root ns */
201+
rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr,
202+
GFP_KERNEL, true, false);
203+
if (IS_ERR(rule->label)) {
204+
aa_audit_rule_free(rule);
205+
return PTR_ERR(rule->label);
206+
}
207+
208+
*vrule = rule;
209+
return 0;
210+
}
211+
212+
int aa_audit_rule_known(struct audit_krule *rule)
213+
{
214+
int i;
215+
216+
for (i = 0; i < rule->field_count; i++) {
217+
struct audit_field *f = &rule->fields[i];
218+
219+
switch (f->type) {
220+
case AUDIT_SUBJ_ROLE:
221+
return 1;
222+
}
223+
}
224+
225+
return 0;
226+
}
227+
228+
int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
229+
struct audit_context *actx)
230+
{
231+
struct aa_audit_rule *rule = vrule;
232+
struct aa_label *label;
233+
int found = 0;
234+
235+
label = aa_secid_to_label(sid);
236+
237+
if (!label)
238+
return -ENOENT;
239+
240+
if (aa_label_is_subset(label, rule->label))
241+
found = 1;
242+
243+
switch (field) {
244+
case AUDIT_SUBJ_ROLE:
245+
switch (op) {
246+
case Audit_equal:
247+
return found;
248+
case Audit_not_equal:
249+
return !found;
250+
}
251+
}
252+
return 0;
253+
}

security/apparmor/domain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ static struct aa_label *handle_onexec(struct aa_label *label,
839839
cond, unsafe));
840840

841841
} else {
842-
/* TODO: determine how much we want to losen this */
842+
/* TODO: determine how much we want to loosen this */
843843
error = fn_for_each_in_ns(label, profile,
844844
profile_onexec(profile, onexec, stack, bprm,
845845
buffer, cond, unsafe));

security/apparmor/include/audit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,10 @@ static inline int complain_error(int error)
189189
return error;
190190
}
191191

192+
void aa_audit_rule_free(void *vrule);
193+
int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule);
194+
int aa_audit_rule_known(struct audit_krule *rule);
195+
int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
196+
struct audit_context *actx);
197+
192198
#endif /* __AA_AUDIT_H */

security/apparmor/include/label.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void __aa_labelset_update_subtree(struct aa_ns *ns);
281281

282282
void aa_label_free(struct aa_label *label);
283283
void aa_label_kref(struct kref *kref);
284-
bool aa_label_init(struct aa_label *label, int size);
284+
bool aa_label_init(struct aa_label *label, int size, gfp_t gfp);
285285
struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp);
286286

287287
bool aa_label_is_subset(struct aa_label *set, struct aa_label *sub);

security/apparmor/include/path.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ struct aa_buffers {
4343

4444
DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
4545

46-
#define ASSIGN(FN, X, N) ((X) = FN(N))
47-
#define EVAL1(FN, X) ASSIGN(FN, X, 0) /*X = FN(0)*/
48-
#define EVAL2(FN, X, Y...) do { ASSIGN(FN, X, 1); EVAL1(FN, Y); } while (0)
49-
#define EVAL(FN, X...) CONCATENATE(EVAL, COUNT_ARGS(X))(FN, X)
46+
#define ASSIGN(FN, A, X, N) ((X) = FN(A, N))
47+
#define EVAL1(FN, A, X) ASSIGN(FN, A, X, 0) /*X = FN(0)*/
48+
#define EVAL2(FN, A, X, Y...) \
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)
5051

5152
#define for_each_cpu_buffer(I) for ((I) = 0; (I) < MAX_PATH_BUFFERS; (I)++)
5253

@@ -56,26 +57,24 @@ DECLARE_PER_CPU(struct aa_buffers, aa_buffers);
5657
#define AA_BUG_PREEMPT_ENABLED(X) /* nop */
5758
#endif
5859

59-
#define __get_buffer(N) ({ \
60-
struct aa_buffers *__cpu_var; \
60+
#define __get_buffer(C, N) ({ \
6161
AA_BUG_PREEMPT_ENABLED("__get_buffer without preempt disabled"); \
62-
__cpu_var = this_cpu_ptr(&aa_buffers); \
63-
__cpu_var->buf[(N)]; })
62+
(C)->buf[(N)]; })
6463

65-
#define __get_buffers(X...) EVAL(__get_buffer, X)
64+
#define __get_buffers(C, X...) EVAL(__get_buffer, C, X)
6665

6766
#define __put_buffers(X, Y...) ((void)&(X))
6867

69-
#define get_buffers(X...) \
70-
do { \
71-
preempt_disable(); \
72-
__get_buffers(X); \
68+
#define get_buffers(X...) \
69+
do { \
70+
struct aa_buffers *__cpu_var = get_cpu_ptr(&aa_buffers); \
71+
__get_buffers(__cpu_var, X); \
7372
} while (0)
7473

75-
#define put_buffers(X, Y...) \
76-
do { \
77-
__put_buffers(X, Y); \
78-
preempt_enable(); \
74+
#define put_buffers(X, Y...) \
75+
do { \
76+
__put_buffers(X, Y); \
77+
put_cpu_ptr(&aa_buffers); \
7978
} while (0)
8079

8180
#endif /* __AA_PATH_H */

security/apparmor/include/secid.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This file contains AppArmor security identifier (secid) definitions
55
*
6-
* Copyright 2009-2010 Canonical Ltd.
6+
* Copyright 2009-2018 Canonical Ltd.
77
*
88
* This program is free software; you can redistribute it and/or
99
* modify it under the terms of the GNU General Public License as
@@ -14,13 +14,24 @@
1414
#ifndef __AA_SECID_H
1515
#define __AA_SECID_H
1616

17+
#include <linux/slab.h>
1718
#include <linux/types.h>
1819

20+
struct aa_label;
21+
1922
/* secid value that will not be allocated */
2023
#define AA_SECID_INVALID 0
21-
#define AA_SECID_ALLOC AA_SECID_INVALID
2224

23-
u32 aa_alloc_secid(void);
25+
struct aa_label *aa_secid_to_label(u32 secid);
26+
int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
27+
int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
28+
void apparmor_release_secctx(char *secdata, u32 seclen);
29+
30+
31+
int aa_alloc_secid(struct aa_label *label, gfp_t gfp);
2432
void aa_free_secid(u32 secid);
33+
void aa_secid_update(u32 secid, struct aa_label *label);
34+
35+
void aa_secids_init(void);
2536

2637
#endif /* __AA_SECID_H */

security/apparmor/label.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int ns_cmp(struct aa_ns *a, struct aa_ns *b)
128128
}
129129

130130
/**
131-
* profile_cmp - profile comparision for set ordering
131+
* profile_cmp - profile comparison for set ordering
132132
* @a: profile to compare (NOT NULL)
133133
* @b: profile to compare (NOT NULL)
134134
*
@@ -157,7 +157,7 @@ static int profile_cmp(struct aa_profile *a, struct aa_profile *b)
157157
}
158158

159159
/**
160-
* vec_cmp - label comparision for set ordering
160+
* vec_cmp - label comparison for set ordering
161161
* @a: label to compare (NOT NULL)
162162
* @vec: vector of profiles to compare (NOT NULL)
163163
* @n: length of @vec
@@ -402,13 +402,12 @@ static void label_free_or_put_new(struct aa_label *label, struct aa_label *new)
402402
aa_put_label(new);
403403
}
404404

405-
bool aa_label_init(struct aa_label *label, int size)
405+
bool aa_label_init(struct aa_label *label, int size, gfp_t gfp)
406406
{
407407
AA_BUG(!label);
408408
AA_BUG(size < 1);
409409

410-
label->secid = aa_alloc_secid();
411-
if (label->secid == AA_SECID_INVALID)
410+
if (aa_alloc_secid(label, gfp) < 0)
412411
return false;
413412

414413
label->size = size; /* doesn't include null */
@@ -441,7 +440,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
441440
if (!new)
442441
goto fail;
443442

444-
if (!aa_label_init(new, size))
443+
if (!aa_label_init(new, size, gfp))
445444
goto fail;
446445

447446
if (!proxy) {
@@ -463,7 +462,7 @@ struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp)
463462

464463

465464
/**
466-
* label_cmp - label comparision for set ordering
465+
* label_cmp - label comparison for set ordering
467466
* @a: label to compare (NOT NULL)
468467
* @b: label to compare (NOT NULL)
469468
*
@@ -2011,7 +2010,7 @@ static struct aa_label *labelset_next_stale(struct aa_labelset *ls)
20112010

20122011
/**
20132012
* __label_update - insert updated version of @label into labelset
2014-
* @label - the label to update/repace
2013+
* @label - the label to update/replace
20152014
*
20162015
* Returns: new label that is up to date
20172016
* else NULL on failure

security/apparmor/lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ int aa_profile_label_perm(struct aa_profile *profile, struct aa_profile *target,
408408
* @request: requested perms
409409
* @deny: Returns: explicit deny set
410410
* @sa: initialized audit structure (MAY BE NULL if not auditing)
411-
* @cb: callback fn for tpye specific fields (MAY BE NULL)
411+
* @cb: callback fn for type specific fields (MAY BE NULL)
412412
*
413413
* Returns: 0 if permission else error code
414414
*

0 commit comments

Comments
 (0)