]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
driver core: suppress sending MODALIAS in UNBIND uevents
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 13 Sep 2017 23:29:48 +0000 (16:29 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 18 Sep 2017 14:48:33 +0000 (16:48 +0200)
The current udev rules cause modules to be loaded on all device events save
for "remove". With the introduction of KOBJ_BIND/KOBJ_UNBIND this causes
issues, as driver modules that have devices bound to their drivers get
immediately reloaded, and it appears to the user that module unloading doe
snot work.

The standard udev matching rule is foillowing:

ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load $env{MODALIAS}"

Given that MODALIAS data is not terribly useful for UNBIND event, let's zap
it from the generated uevent environment until we get userspace updated
with the correct udev rule that only loads modules on "add" event.

Reported-by: Jakub Kicinski <kubakici@wp.pl>
Tested-by: Jakub Kicinski <kubakici@wp.pl>
Fixes: 1455cf8dbfd0 ("driver core: emit uevents when device is bound ...")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/kobject_uevent.c

index e590523ea4761425df5e112a2c2aab873dbaa90d..f237a09a58627bfd4df2628c173f57afd89a83de 100644 (file)
@@ -294,6 +294,26 @@ static void cleanup_uevent_env(struct subprocess_info *info)
 }
 #endif
 
+static void zap_modalias_env(struct kobj_uevent_env *env)
+{
+       static const char modalias_prefix[] = "MODALIAS=";
+       int i;
+
+       for (i = 0; i < env->envp_idx;) {
+               if (strncmp(env->envp[i], modalias_prefix,
+                           sizeof(modalias_prefix) - 1)) {
+                       i++;
+                       continue;
+               }
+
+               if (i != env->envp_idx - 1)
+                       memmove(&env->envp[i], &env->envp[i + 1],
+                               sizeof(env->envp[i]) * env->envp_idx - 1);
+
+               env->envp_idx--;
+       }
+}
+
 /**
  * kobject_uevent_env - send an uevent with environmental data
  *
@@ -409,16 +429,29 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
                }
        }
 
-       /*
-        * Mark "add" and "remove" events in the object to ensure proper
-        * events to userspace during automatic cleanup. If the object did
-        * send an "add" event, "remove" will automatically generated by
-        * the core, if not already done by the caller.
-        */
-       if (action == KOBJ_ADD)
+       switch (action) {
+       case KOBJ_ADD:
+               /*
+                * Mark "add" event so we can make sure we deliver "remove"
+                * event to userspace during automatic cleanup. If
+                * the object did send an "add" event, "remove" will
+                * automatically generated by the core, if not already done
+                * by the caller.
+                */
                kobj->state_add_uevent_sent = 1;
-       else if (action == KOBJ_REMOVE)
+               break;
+
+       case KOBJ_REMOVE:
                kobj->state_remove_uevent_sent = 1;
+               break;
+
+       case KOBJ_UNBIND:
+               zap_modalias_env(env);
+               break;
+
+       default:
+               break;
+       }
 
        mutex_lock(&uevent_sock_mutex);
        /* we will send an event, so request a new sequence number */