aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-12-13 18:21:22 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-12-21 05:10:33 -0500
commit9b3fa47d4a76b1d606a396455f9bbeee083ef008 (patch)
tree8fe11ace9a6ce42159bc38aa287082706d1cfc85
parentf57ab9a01a36ef3454333251cc57e3a9948b17bf (diff)
kobject: fix suppressing modalias in uevents delivered over netlink
The commit 4a336a23d619 ("kobject: copy env blob in one go") optimized constructing uevent data for delivery over netlink by using the raw environment buffer, instead of reconstructing it from individual environment pointers. Unfortunately in doing so it broke suppressing MODALIAS attribute for KOBJ_UNBIND events, as the code that suppressed this attribute only adjusted the environment pointers, but left the buffer itself alone. Let's fix it by making sure the offending attribute is obliterated form the buffer as well. Reported-by: Tariq Toukan <tariqt@mellanox.com> Reported-by: Casey Leedom <leedom@chelsio.com> Fixes: 4a336a23d619 ("kobject: copy env blob in one go") Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--lib/kobject_uevent.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index c3e84edc47c9..2615074d3de5 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -346,7 +346,8 @@ static int kobject_uevent_net_broadcast(struct kobject *kobj,
346static void zap_modalias_env(struct kobj_uevent_env *env) 346static void zap_modalias_env(struct kobj_uevent_env *env)
347{ 347{
348 static const char modalias_prefix[] = "MODALIAS="; 348 static const char modalias_prefix[] = "MODALIAS=";
349 int i; 349 size_t len;
350 int i, j;
350 351
351 for (i = 0; i < env->envp_idx;) { 352 for (i = 0; i < env->envp_idx;) {
352 if (strncmp(env->envp[i], modalias_prefix, 353 if (strncmp(env->envp[i], modalias_prefix,
@@ -355,11 +356,18 @@ static void zap_modalias_env(struct kobj_uevent_env *env)
355 continue; 356 continue;
356 } 357 }
357 358
358 if (i != env->envp_idx - 1) 359 len = strlen(env->envp[i]) + 1;
359 memmove(&env->envp[i], &env->envp[i + 1], 360
360 sizeof(env->envp[i]) * env->envp_idx - 1); 361 if (i != env->envp_idx - 1) {
362 memmove(env->envp[i], env->envp[i + 1],
363 env->buflen - len);
364
365 for (j = i; j < env->envp_idx - 1; j++)
366 env->envp[j] = env->envp[j + 1] - len;
367 }
361 368
362 env->envp_idx--; 369 env->envp_idx--;
370 env->buflen -= len;
363 } 371 }
364} 372}
365 373