Skip to contentSkip to conversation

what's going on with aa_destroy_aafs() call in apparmor_init()?

DISCUSSION Al Viro 2 participants 2 messages Sep 21, 2025 – Sep 22, 2025

Subsystems (2)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

Correct me if I'm wrong, but as far as I can tell apparmor_init()
ends up being called from security_init(), which is called before the call of vfs_caches_init(), not to mention fs_initcall stuff.

If that's the case, what is this doing there?
error:

        aa_destroy_aafs();
	AA_ERROR("Error creating AppArmor securityfs\n");
	return error;

aa_create_aafs() is called via fs_initcall; moreover, it will bail out if called before apparmor_initialized has become true, so...

While we are at it, what will happen if apparmor_init() succeeds, but aa_create_fs() fails afterwards?

If nothing else, aa_null_path will be left {NULL, NULL}, which will immediately oops dentry_open() in aa_inherit_files()...

#1 lore raw
Quoted 3 lines · Al Viro

Correct me if I'm wrong, but as far as I can tell apparmor_init()
ends up being called from security_init(), which is called before the call of vfs_caches_init(), not to mention fs_initcall stuff.

sigh, yes that is what is happening.

Quoted 5 lines

If that's the case, what is this doing there?
error:

         aa_destroy_aafs();
	AA_ERROR("Error creating AppArmor securityfs\n");
	return error;

it shouldn't be it should have been dropped ages ago. Its a mess up on a patch and then it just got carried forward

Quoted 5 lines

aa_create_aafs() is called via fs_initcall; moreover, it will bail out if called before apparmor_initialized has become true, so...

While we are at it, what will happen if apparmor_init() succeeds, but aa_create_fs() fails afterwards?

Yeah that one is ugly. I will have to poke at the best solution atm. For current kernels, no policy will load. Backing out the LSM hooks isn't going to happen but we will need to just run in an unconfined state and make sure any references to the fs handle the null condition.

Quoted 2 lines

If nothing else, aa_null_path will be left {NULL, NULL}, which will immediately oops dentry_open() in aa_inherit_files()...

indeed, I have to wonder if it was always that way or I just messed up. I borrowed the pattern from selinux but should have also dug into what it was doing.

regardless it needs to be fixed.
We can check that its null and set the file to null for replace fds.

Give me a bit to see about some patches.