Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbdLMXVc (ORCPT ); Wed, 13 Dec 2017 18:21:32 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:34933 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751646AbdLMXV0 (ORCPT ); Wed, 13 Dec 2017 18:21:26 -0500 X-Google-Smtp-Source: ACJfBov3uO75Qu+IRRNOcX5004k2EtHMvXUredDcc2x719lplEThz0soQhKt4unUZHSFatS00jemOA== Date: Wed, 13 Dec 2017 15:21:22 -0800 From: Dmitry Torokhov To: Greg Kroah-Hartman Cc: Eric Dumazet , Eric Dumazet , Tariq Toukan , "David S . Miller" , Komali Katari , "Luis R. Rodriguez" , Casey Leedom , linux-kernel@vger.kernel.org Subject: [PATCH] kobject: fix suppressing modalias in uevents delivered over netlink Message-ID: <20171213232122.5ztmwume5kylh4mz@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1861 Lines: 59 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 Reported-by: Casey Leedom Fixes: 4a336a23d619 ("kobject: copy env blob in one go") Signed-off-by: Dmitry Torokhov --- lib/kobject_uevent.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index f237a09a5862..ae47cc732ba6 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -297,7 +297,8 @@ static void cleanup_uevent_env(struct subprocess_info *info) static void zap_modalias_env(struct kobj_uevent_env *env) { static const char modalias_prefix[] = "MODALIAS="; - int i; + size_t len; + int i, j; for (i = 0; i < env->envp_idx;) { if (strncmp(env->envp[i], modalias_prefix, @@ -306,11 +307,18 @@ static void zap_modalias_env(struct kobj_uevent_env *env) continue; } - if (i != env->envp_idx - 1) - memmove(&env->envp[i], &env->envp[i + 1], - sizeof(env->envp[i]) * env->envp_idx - 1); + len = strlen(env->envp[i]) + 1; + + if (i != env->envp_idx - 1) { + memmove(env->envp[i], env->envp[i + 1], + env->buflen - len); + + for (j = i; j < env->envp_idx - 1; j++) + env->envp[j] = env->envp[j + 1] - len; + } env->envp_idx--; + env->buflen -= len; } } -- 2.15.1.504.g5279b80103-goog -- Dmitry