Modify

Opened 4 years ago

Last modified 4 years ago

#15013 new defect

Race condition with kernel module loading

Reported by: Whitelighter Owned by: developers
Priority: normal Milestone:
Component: base system Version: Trunk
Keywords: procd, kmodloader Cc:

Description

On a fast dual-core system, kmodloader called from /etc/init.d/boot can start before kmodloader called from procd (init.c) has finished.

With the right circumstances this can cause modules not to load.

Example:
/etc/modules-boot.d has pps_core and ptp
/etc/modules.d has e1000e

ptp depends on pps_core
e1000e depends on ptp

When the second kmodloader (kmodloader2) is called it retrieves the list of currently loaded modules. If the first kmodloader (kmodloader1) hasn't completed this list will be incomplete.

kmodloader2 tries to load e1000e and determines the dependencies are ptp and pps_core. They should be already loaded, but due to the race condition they can still be in progress. As such kmodloader2's loaded module list doesn't contain them. kmodloader1 will complete the loading of pps_core and ptp whilst kmodloader2 is running. So when kmodloader2 tries to load the dependencies (pps_core and ptp) for e1000e it fails because they are already loaded and results in e1000e not loading.

Sadly it doesn't seem the syscall to load the module returns a unique error code to indicate the module is already loaded. Otherwise kmodloader could have continued as if the load was successful.

Possible option is to do a sleep wait loop in /etc/init.d/boot until the first kmodloader doesn't show in the process list before executing the second kmodloader?

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by Whitelighter

Potential fix to /etc/init.d/boot

--- boot.old    2014-02-16 23:09:12.000000000 +0000
+++ boot.new    2014-02-16 23:08:55.000000000 +0000
@@ -53,6 +53,16 @@
        grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
        [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
 
+        # Wait for first kmodloader to finish
+        while true
+        do
+          if [ -z "$(ps | grep '[k]modloader')" ]; then
+            break
+          else
+            sleep 1
+          fi
+        done
+        
        /sbin/kmodloader
 
        # allow wifi modules time to settle

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.