Skip to content

Commit 38dc717

Browse files
author
Jessica Yu
committed
module: delay kobject uevent until after module init call
Apparently there has been a longstanding race between udev/systemd and the module loader. Currently, the module loader sends a uevent right after sysfs initialization, but before the module calls its init function. However, some udev rules expect that the module has initialized already upon receiving the uevent. This race has been triggered recently (see link in references) in some systemd mount unit files. For instance, the configfs module creates the /sys/kernel/config mount point in its init function, however the module loader issues the uevent before this happens. sys-kernel-config.mount expects to be able to mount /sys/kernel/config upon receipt of the module loading uevent, but if the configfs module has not called its init function yet, then this directory will not exist and the mount unit fails. A similar situation exists for sys-fs-fuse-connections.mount, as the fuse sysfs mount point is created during the fuse module's init function. If udev is faster than module initialization then the mount unit would fail in a similar fashion. To fix this race, delay the module KOBJ_ADD uevent until after the module has finished calling its init routine. References: systemd/systemd#17586 Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Tested-By: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com> Signed-off-by: Jessica Yu <jeyu@kernel.org>
1 parent 2d26c71 commit 38dc717

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎kernel/module.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,6 @@ static int mod_sysfs_init(struct module *mod)
18971897
if (err)
18981898
mod_kobject_put(mod);
18991899

1900-
/* delay uevent until full sysfs population */
19011900
out:
19021901
return err;
19031902
}
@@ -1934,7 +1933,6 @@ static int mod_sysfs_setup(struct module *mod,
19341933
add_sect_attrs(mod, info);
19351934
add_notes_attrs(mod, info);
19361935

1937-
kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
19381936
return 0;
19391937

19401938
out_unreg_modinfo_attrs:
@@ -3656,6 +3654,9 @@ static noinline int do_init_module(struct module *mod)
36563654
blocking_notifier_call_chain(&module_notify_list,
36573655
MODULE_STATE_LIVE, mod);
36583656

3657+
/* Delay uevent until module has finished its init routine */
3658+
kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
3659+
36593660
/*
36603661
* We need to finish all async code before the module init sequence
36613662
* is done. This has potential to deadlock. For example, a newly

0 commit comments

Comments
 (0)