7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: John Johansen [ Upstream commit 97ba44a2aa4c7ab011a93ce94cb595200fe4ea4f ] The load interface does not guarantee the order profiles are loaded. When a parent is loaded after its child, and the load fails, the current code will issue a warning, and leak a dentry. For the loaded set of profiles, ensure that on failure list is ordered is traversed in reverse so any children processed after their parent is freed first. We do not need to deal with the cases where the children are processed before their parent, because either a parent outside the list already exists or a dummy parent outside of the list is created, and the list walk will not put those parents before their children. Fixes: 6ec46f8f1977d ("apparmor: remove fs entries created by a failed policy load") Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 8f23f99d2a58f..63f7821b4dfff 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c @@ -1432,8 +1432,10 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label, * them yet, and leaving them behind would leak the new profiles * (their dents pin the proxy) and make the next load at the same, * unbumped ns revision fail with -EEXIST on its raw_data dir. + * ensure children (which are at the end of the list are removed + * before their parent */ - list_for_each_entry(tmp, &lh, list) { + list_for_each_entry_reverse(tmp, &lh, list) { if (!tmp->old) __aafs_profile_rmdir(tmp->new); } -- 2.53.0