If apparmor_parser -N (in profiles_names_list()) fails, aa-remove-unknown possibly gets an incomplete list of profiles in /etc/apparmor.d/ and therefore might remove more profiles than it should.
Replace the profiles_names_list() call with a direct apparmor_parser call, and abort aa-remove-unknown if it exits with $? != 0
aa-remove-unknown -n AppArmor parser error for /etc/apparmor.d/broken in profile /etc/apparmor.d/broken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN Would remove 'delete_me'
./aa-remove-unknown -n AppArmor parser error for /etc/apparmor.d in profile /etc/apparmor.d/zbroken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN apparmor_parser exited with failure, aborting.
And of course, after fixing the broken profile:
./aa-remove-unknown -n Would remove 'delete_me'
(cherry picked from commit 5053a01d)
This backports the fix in
aa-remove-unknown from !836 (merged), but doesn't backport the cleanup in
I propose this patch for 3.0 and all 2.x branches.