From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12345C2D0BF for ; Tue, 17 Dec 2019 20:11:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF7152176D for ; Tue, 17 Dec 2019 20:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576613496; bh=Jk2WK0gpxpGOm7b/DRmsYrr/d03CP+EHVZIj9KNKkcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xcxD8N2E07qUAWUp97LyabgHhKUUfaFVzBU2n+dJl+HUkof2p+aJjzlKMb0jaWCMg IX70QQT/J2zCIEnxyeSw0hyf2XCMh6q6H6jHu+WbALUcC9EjMvPRUFRXw3kzkqLUVM jaTKrwYpY4SuA9HDqthFApQIEM5tK12AVyQos580= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbfLQULg (ORCPT ); Tue, 17 Dec 2019 15:11:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:38224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728757AbfLQULc (ORCPT ); Tue, 17 Dec 2019 15:11:32 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15FFA2176D; Tue, 17 Dec 2019 20:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576613491; bh=Jk2WK0gpxpGOm7b/DRmsYrr/d03CP+EHVZIj9KNKkcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A9iKaADvJdeL/amHIs/qM0WZTYi8TMV3NaklL6Z12rOBGApg+RMfl2FR/puLETc6e bEvNRYbBrPl9NXVUJE8LCcbWxxICUf4KczOEma7Gb6v85MGcKo1tfqBRUWNXBLhDdF 6L0I1VPaZIiZfdrzX959PzGfsRdctP9CcEgMTPyo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Tetsuo Handa , David Miller , Lukas Bulwahn Subject: [PATCH 5.4 08/37] net-sysfs: Call dev_hold always in netdev_queue_add_kobject Date: Tue, 17 Dec 2019 21:09:29 +0100 Message-Id: <20191217200724.234482593@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191217200721.741054904@linuxfoundation.org> References: <20191217200721.741054904@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jouni Hogander [ Upstream commit e0b60903b434a7ee21ba8d8659f207ed84101e89 ] Dev_hold has to be called always in netdev_queue_add_kobject. Otherwise usage count drops below 0 in case of failure in kobject_init_and_add. Fixes: b8eb718348b8 ("net-sysfs: Fix reference count leak in rx|netdev_queue_add_kobject") Reported-by: Hulk Robot Cc: Tetsuo Handa Cc: David Miller Cc: Lukas Bulwahn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/net-sysfs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1459,14 +1459,17 @@ static int netdev_queue_add_kobject(stru struct kobject *kobj = &queue->kobj; int error = 0; + /* Kobject_put later will trigger netdev_queue_release call + * which decreases dev refcount: Take that reference here + */ + dev_hold(queue->dev); + kobj->kset = dev->queues_kset; error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, "tx-%u", index); if (error) goto err; - dev_hold(queue->dev); - #ifdef CONFIG_BQL error = sysfs_create_group(kobj, &dql_group); if (error)