From: John Johansen Date: Sat, 26 Mar 2022 08:58:15 +0000 (-0700) Subject: apparmor: fix overlapping attachment computation X-Git-Tag: v5.19.4~317 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a1fffe963555096d401719342c9a1a8c752e30a;p=thirdparty%2Fkernel%2Fstable.git apparmor: fix overlapping attachment computation commit 2504db207146543736e877241f3b3de005cbe056 upstream. When finding the profile via patterned attachments, the longest left match is being set to the static compile time value and not using the runtime computed value. Fix this by setting the candidate value to the greater of the precomputed value or runtime computed value. Fixes: 21f606610502 ("apparmor: improve overlapping domain attachment resolution") Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c index a29e69d2c3005..97721115340fc 100644 --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c @@ -466,7 +466,7 @@ restart: * xattrs, or a longer match */ candidate = profile; - candidate_len = profile->xmatch_len; + candidate_len = max(count, profile->xmatch_len); candidate_xattrs = ret; conflict = false; } diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h index cb5ef21991b72..232d3d9566eb7 100644 --- a/security/apparmor/include/policy.h +++ b/security/apparmor/include/policy.h @@ -135,7 +135,7 @@ struct aa_profile { const char *attach; struct aa_dfa *xmatch; - int xmatch_len; + unsigned int xmatch_len; enum audit_mode audit; long mode; u32 path_flags;