Commit 852b0a89 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'apparmor-pr-2018-01-12' of...

Merge tag 'apparmor-pr-2018-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor

Pull apparmor regression fixes from John Johansen:
 "This fixes a couple bugs I have been working with Matthew Garrett on
  this week. Specifically a regression in the handling of a conflicting
  profile attachment and label match restrictions for ptrace when
  profiles are stacked.

  Summary:

   - fix ptrace label match when matching stacked labels

   - fix regression in profile conflict logic"

* tag 'apparmor-pr-2018-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor:
  apparmor: Fix regression in profile conflict logic
  apparmor: fix ptrace label match when matching stacked labels
parents 8e66791a 1a3881d3
...@@ -330,10 +330,7 @@ static struct aa_profile *__attach_match(const char *name, ...@@ -330,10 +330,7 @@ static struct aa_profile *__attach_match(const char *name,
continue; continue;
if (profile->xmatch) { if (profile->xmatch) {
if (profile->xmatch_len == len) { if (profile->xmatch_len >= len) {
conflict = true;
continue;
} else if (profile->xmatch_len > len) {
unsigned int state; unsigned int state;
u32 perm; u32 perm;
...@@ -342,6 +339,10 @@ static struct aa_profile *__attach_match(const char *name, ...@@ -342,6 +339,10 @@ static struct aa_profile *__attach_match(const char *name,
perm = dfa_user_allow(profile->xmatch, state); perm = dfa_user_allow(profile->xmatch, state);
/* any accepting state means a valid match. */ /* any accepting state means a valid match. */
if (perm & MAY_EXEC) { if (perm & MAY_EXEC) {
if (profile->xmatch_len == len) {
conflict = true;
continue;
}
candidate = profile; candidate = profile;
len = profile->xmatch_len; len = profile->xmatch_len;
conflict = false; conflict = false;
......
...@@ -133,6 +133,9 @@ extern struct aa_perms allperms; ...@@ -133,6 +133,9 @@ extern struct aa_perms allperms;
#define xcheck_labels_profiles(L1, L2, FN, args...) \ #define xcheck_labels_profiles(L1, L2, FN, args...) \
xcheck_ns_labels((L1), (L2), xcheck_ns_profile_label, (FN), args) xcheck_ns_labels((L1), (L2), xcheck_ns_profile_label, (FN), args)
#define xcheck_labels(L1, L2, P, FN1, FN2) \
xcheck(fn_for_each((L1), (P), (FN1)), fn_for_each((L2), (P), (FN2)))
void aa_perm_mask_to_str(char *str, const char *chrs, u32 mask); void aa_perm_mask_to_str(char *str, const char *chrs, u32 mask);
void aa_audit_perm_names(struct audit_buffer *ab, const char **names, u32 mask); void aa_audit_perm_names(struct audit_buffer *ab, const char **names, u32 mask);
......
...@@ -64,40 +64,48 @@ static void audit_ptrace_cb(struct audit_buffer *ab, void *va) ...@@ -64,40 +64,48 @@ static void audit_ptrace_cb(struct audit_buffer *ab, void *va)
FLAGS_NONE, GFP_ATOMIC); FLAGS_NONE, GFP_ATOMIC);
} }
/* assumes check for PROFILE_MEDIATES is already done */
/* TODO: conditionals */ /* TODO: conditionals */
static int profile_ptrace_perm(struct aa_profile *profile, static int profile_ptrace_perm(struct aa_profile *profile,
struct aa_profile *peer, u32 request, struct aa_label *peer, u32 request,
struct common_audit_data *sa) struct common_audit_data *sa)
{ {
struct aa_perms perms = { }; struct aa_perms perms = { };
/* need because of peer in cross check */ aad(sa)->peer = peer;
if (profile_unconfined(profile) || aa_profile_match_label(profile, peer, AA_CLASS_PTRACE, request,
!PROFILE_MEDIATES(profile, AA_CLASS_PTRACE))
return 0;
aad(sa)->peer = &peer->label;
aa_profile_match_label(profile, &peer->label, AA_CLASS_PTRACE, request,
&perms); &perms);
aa_apply_modes_to_perms(profile, &perms); aa_apply_modes_to_perms(profile, &perms);
return aa_check_perms(profile, &perms, request, sa, audit_ptrace_cb); return aa_check_perms(profile, &perms, request, sa, audit_ptrace_cb);
} }
static int cross_ptrace_perm(struct aa_profile *tracer, static int profile_tracee_perm(struct aa_profile *tracee,
struct aa_profile *tracee, u32 request, struct aa_label *tracer, u32 request,
struct common_audit_data *sa)
{
if (profile_unconfined(tracee) || unconfined(tracer) ||
!PROFILE_MEDIATES(tracee, AA_CLASS_PTRACE))
return 0;
return profile_ptrace_perm(tracee, tracer, request, sa);
}
static int profile_tracer_perm(struct aa_profile *tracer,
struct aa_label *tracee, u32 request,
struct common_audit_data *sa) struct common_audit_data *sa)
{ {
if (profile_unconfined(tracer))
return 0;
if (PROFILE_MEDIATES(tracer, AA_CLASS_PTRACE)) if (PROFILE_MEDIATES(tracer, AA_CLASS_PTRACE))
return xcheck(profile_ptrace_perm(tracer, tracee, request, sa), return profile_ptrace_perm(tracer, tracee, request, sa);
profile_ptrace_perm(tracee, tracer,
request << PTRACE_PERM_SHIFT, /* profile uses the old style capability check for ptrace */
sa)); if (&tracer->label == tracee)
/* policy uses the old style capability check for ptrace */
if (profile_unconfined(tracer) || tracer == tracee)
return 0; return 0;
aad(sa)->label = &tracer->label; aad(sa)->label = &tracer->label;
aad(sa)->peer = &tracee->label; aad(sa)->peer = tracee;
aad(sa)->request = 0; aad(sa)->request = 0;
aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1); aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1);
...@@ -115,10 +123,13 @@ static int cross_ptrace_perm(struct aa_profile *tracer, ...@@ -115,10 +123,13 @@ static int cross_ptrace_perm(struct aa_profile *tracer,
int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee, int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
u32 request) u32 request)
{ {
struct aa_profile *profile;
u32 xrequest = request << PTRACE_PERM_SHIFT;
DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE); DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm, return xcheck_labels(tracer, tracee, profile,
request, &sa); profile_tracer_perm(profile, tracee, request, &sa),
profile_tracee_perm(profile, tracer, xrequest, &sa));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment