- apparmor: fix ptrace label match when matching stacked labels
- apparmor: Fix regression in profile conflict logic -----BEGIN PGP SIGNATURE----- iQIcBAABCgAGBQJaWWwtAAoJEAUvNnAY1cPY/0gP/iHnqNR705LOuLzy7Iya0Iy+ n8J9Tba9dQMGpiR8W5EIMklP0Hj+Wt50ngwmemJrjNpALphGeET16Qg01iYQcPNh fR/oc9ZA5vpn7fFTnQZzlvcxRZCBJtuuqBcvM6oNjVVqLh6t6EN+viqh97XFZyc+ XFFYdCTRQ1JSgW7RIw/h8rFAvfPXIuXA7SwAQ/+PXlxOMi0fbZGbsVAiXPI1+pmX wXj3Vtgisb/i4cSJtG9wujGs/SNjmN/2Yyzj2ZjKh3Y4lxug2bko3BfrrbD7uAeL XOARp9ELjUk5m9tI9NuGpr9iIT392BaVvJDKyN8byK8skMOOsomG/zypVFLAbsBc w0dN5IxLvyk3lH7amSBj+aJKQV0cthss0L11WlMuftLiqsDzRMec2md35+T3eSt3 AQ132tTHcQ3SiMd4b/yxXe1CjJEo62dBQzppLpV27lcpurOJdhQYEAC0vfXGpkgJ 5UIn7t5wNpb5GC+CBSQ+qFhBTtGEY9MdhcM/mZJrBTRWmId7umm3UdUtihVz8qlJ uue+S8h3L7TUFkdIRcGgViJrcQsvDFhabkHvsKppl5CYRrT6Lu46XBTZV6ioZcsm maIuVY7agFVk4Z0Fyc+zYM7e/IDoVVBdBwUKDWNnEkFmRKE7RrWsBq59PBksLUtz G/8zxZ//8MRhlm5uyuid =Myva -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
852b0a8902
|
@ -330,10 +330,7 @@ static struct aa_profile *__attach_match(const char *name,
|
|||
continue;
|
||||
|
||||
if (profile->xmatch) {
|
||||
if (profile->xmatch_len == len) {
|
||||
conflict = true;
|
||||
continue;
|
||||
} else if (profile->xmatch_len > len) {
|
||||
if (profile->xmatch_len >= len) {
|
||||
unsigned int state;
|
||||
u32 perm;
|
||||
|
||||
|
@ -342,6 +339,10 @@ static struct aa_profile *__attach_match(const char *name,
|
|||
perm = dfa_user_allow(profile->xmatch, state);
|
||||
/* any accepting state means a valid match. */
|
||||
if (perm & MAY_EXEC) {
|
||||
if (profile->xmatch_len == len) {
|
||||
conflict = true;
|
||||
continue;
|
||||
}
|
||||
candidate = profile;
|
||||
len = profile->xmatch_len;
|
||||
conflict = false;
|
||||
|
|
|
@ -133,6 +133,9 @@ extern struct aa_perms allperms;
|
|||
#define xcheck_labels_profiles(L1, L2, 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_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)
|
|||
FLAGS_NONE, GFP_ATOMIC);
|
||||
}
|
||||
|
||||
/* assumes check for PROFILE_MEDIATES is already done */
|
||||
/* TODO: conditionals */
|
||||
static int profile_ptrace_perm(struct aa_profile *profile,
|
||||
struct aa_profile *peer, u32 request,
|
||||
struct common_audit_data *sa)
|
||||
struct aa_label *peer, u32 request,
|
||||
struct common_audit_data *sa)
|
||||
{
|
||||
struct aa_perms perms = { };
|
||||
|
||||
/* need because of peer in cross check */
|
||||
if (profile_unconfined(profile) ||
|
||||
!PROFILE_MEDIATES(profile, AA_CLASS_PTRACE))
|
||||
return 0;
|
||||
|
||||
aad(sa)->peer = &peer->label;
|
||||
aa_profile_match_label(profile, &peer->label, AA_CLASS_PTRACE, request,
|
||||
aad(sa)->peer = peer;
|
||||
aa_profile_match_label(profile, peer, AA_CLASS_PTRACE, request,
|
||||
&perms);
|
||||
aa_apply_modes_to_perms(profile, &perms);
|
||||
return aa_check_perms(profile, &perms, request, sa, audit_ptrace_cb);
|
||||
}
|
||||
|
||||
static int cross_ptrace_perm(struct aa_profile *tracer,
|
||||
struct aa_profile *tracee, u32 request,
|
||||
struct common_audit_data *sa)
|
||||
static int profile_tracee_perm(struct aa_profile *tracee,
|
||||
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)
|
||||
{
|
||||
if (profile_unconfined(tracer))
|
||||
return 0;
|
||||
|
||||
if (PROFILE_MEDIATES(tracer, AA_CLASS_PTRACE))
|
||||
return xcheck(profile_ptrace_perm(tracer, tracee, request, sa),
|
||||
profile_ptrace_perm(tracee, tracer,
|
||||
request << PTRACE_PERM_SHIFT,
|
||||
sa));
|
||||
/* policy uses the old style capability check for ptrace */
|
||||
if (profile_unconfined(tracer) || tracer == tracee)
|
||||
return profile_ptrace_perm(tracer, tracee, request, sa);
|
||||
|
||||
/* profile uses the old style capability check for ptrace */
|
||||
if (&tracer->label == tracee)
|
||||
return 0;
|
||||
|
||||
aad(sa)->label = &tracer->label;
|
||||
aad(sa)->peer = &tracee->label;
|
||||
aad(sa)->peer = tracee;
|
||||
aad(sa)->request = 0;
|
||||
aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1);
|
||||
|
||||
|
@ -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,
|
||||
u32 request)
|
||||
{
|
||||
struct aa_profile *profile;
|
||||
u32 xrequest = request << PTRACE_PERM_SHIFT;
|
||||
DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
|
||||
|
||||
return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm,
|
||||
request, &sa);
|
||||
return xcheck_labels(tracer, tracee, profile,
|
||||
profile_tracer_perm(profile, tracee, request, &sa),
|
||||
profile_tracee_perm(profile, tracer, xrequest, &sa));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue