Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3080169yba; Mon, 22 Apr 2019 19:27:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyliyi6ggmlNm6h0OwrJeAmqdYzk5QrHG24wiX7IMyRB/hHfAqqsPDQfNVy60hHPVJD6yDE X-Received: by 2002:a63:84c7:: with SMTP id k190mr22129051pgd.255.1555986444197; Mon, 22 Apr 2019 19:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555986444; cv=none; d=google.com; s=arc-20160816; b=FXBbxobkv90NsPK8x3CQIMtfQKOBDxK8mjw0kY/1Qzjd+N37EEajldsB8Tb/TuRFB+ 9dmPyB6OozcC+bLwXQt1GnIV8IyfwLrJHEaNRf2geqIzq8KKkVtYzgP8sIva1St1z61F v/yROvcBtMgD/A71QiIXf3YHb5I9FkppR3NjJtZwtzPPd1XAxNVVlkN8Vqb3M/8iyQnf GcYdlMkGnGBvd/nVQqPtn4yKxGf2LW4EgySNLrSY2lK+1i+MWqNLwhllvR++Px54Noon obEtwhQB4QaK13EL/YQJYY0gnorIjJtxmSMxfLj+9TFCBGFV4m4Q8z3D0nYp+ngkPsui irJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NepLVgFy51bK8NgeMu+CudVLAE9h+SNbzXRXmA1jImo=; b=nvT38ecIuzxbdg/9V3rARkQpHe+IMoUaVI2JeMBXWddXqt3h9kwU5wF6vFP+F9zJsl T0lIGsceNb0cAzxnlAECEvMCwWAUXnM9gocID0Z/yHUtkatvPZPiuFIxO7XBB/5TwX72 USNzy7TeUfIBa/xfxyVgs/l//y6EJ3TzrbS6B/h6n0dPIvKhg+n1GiCM6rJDBElQXHBt eUU92BrJ2NnWtRX1AZC1TL+qsM9/2gGw43bHWonCmSMTWnfxXzga2XzZlxzxsYi8V8B7 GBAOU+/o31qAdKaBJKMv/saBGdVLEyp3gnC6JNhOMNaTaO54qg1vXoS/IwvkIseN73Nr qqNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aFrcl+VT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k66si13620958pgc.247.2019.04.22.19.27.08; Mon, 22 Apr 2019 19:27:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aFrcl+VT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731955AbfDVUBN (ORCPT + 99 others); Mon, 22 Apr 2019 16:01:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:49600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730145AbfDVTrB (ORCPT ); Mon, 22 Apr 2019 15:47:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3166C21906; Mon, 22 Apr 2019 19:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962420; bh=mcmamO7Oh+IA5VVXze+//Ym8Kz+7TgLgMJ+OLyC967U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aFrcl+VThllPklk4LLg9lWdl5L65Ugu5aBeXtZWAQvd53htJTEdx9yinoI6gpwULS s+72UL4cnreRyuf89VAZGjDW+pjZww6BvtIyqfrjOKV/2BMzAF4fj1O/JoTx+L1AKr D2N91lm6YnzhUCYtwC6gviS7hK5ZRI/wiWvJYx1I= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Jacek Anaszewski , Sasha Levin , linux-leds@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 53/68] leds: trigger: netdev: fix refcnt leak on interface rename Date: Mon, 22 Apr 2019 15:45:01 -0400 Message-Id: <20190422194516.11634-53-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafał Miłecki [ Upstream commit 4cb6560514fa19d556954b88128f3846fee66a03 ] Renaming a netdev-trigger-tracked interface was resulting in an unbalanced dev_hold(). Example: > iw phy phy0 interface add foo type __ap > echo netdev > trigger > echo foo > device_name > ip link set foo name bar > iw dev bar del [ 237.355366] unregister_netdevice: waiting for bar to become free. Usage count = 1 [ 247.435362] unregister_netdevice: waiting for bar to become free. Usage count = 1 [ 257.545366] unregister_netdevice: waiting for bar to become free. Usage count = 1 Above problem was caused by trigger checking a dev->name which obviously changes after renaming an interface. It meant missing all further events including the NETDEV_UNREGISTER which is required for calling dev_put(). This change fixes that by: 1) Comparing device struct *address* for notification-filtering purposes 2) Dropping unneeded NETDEV_CHANGENAME code (no behavior change) Fixes: 06f502f57d0d ("leds: trigger: Introduce a NETDEV trigger") Signed-off-by: Rafał Miłecki Acked-by: Pavel Machek Signed-off-by: Jacek Anaszewski Signed-off-by: Sasha Levin (Microsoft) --- drivers/leds/trigger/ledtrig-netdev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 3dd3ed46d473..167a94c02d05 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -301,11 +301,11 @@ static int netdev_trig_notify(struct notifier_block *nb, container_of(nb, struct led_netdev_data, notifier); if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE - && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER - && evt != NETDEV_CHANGENAME) + && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER) return NOTIFY_DONE; - if (strcmp(dev->name, trigger_data->device_name)) + if (!(dev == trigger_data->net_dev || + (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name)))) return NOTIFY_DONE; cancel_delayed_work_sync(&trigger_data->work); @@ -320,12 +320,9 @@ static int netdev_trig_notify(struct notifier_block *nb, dev_hold(dev); trigger_data->net_dev = dev; break; - case NETDEV_CHANGENAME: case NETDEV_UNREGISTER: - if (trigger_data->net_dev) { - dev_put(trigger_data->net_dev); - trigger_data->net_dev = NULL; - } + dev_put(trigger_data->net_dev); + trigger_data->net_dev = NULL; break; case NETDEV_UP: case NETDEV_CHANGE: -- 2.19.1