From patchwork Tue Jan 28 14:07:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 232595 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 0861FC33CB2 for ; Tue, 28 Jan 2020 14:32:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C988324686 for ; Tue, 28 Jan 2020 14:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221946; bh=ry1w5+wOxDp6nob0N2laByzLXUOzRwsg+mF825EiCfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ydPQ1ESv80vuvVH05cXGamS1nzCgEJJPVbwMiMu9Ti5tZ4uSX0pUiyHcyopm7ZVGU rE+cXV2iDPcPFEkJp41ui1UBo+CS8/SvBnkrIV9FrtTqO/L0jxI4SwBxBIWsp83Exh bDUOMhdZ1WParuxpUx2Nn40HFbipyB1qPn3LzJYM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732698AbgA1O0j (ORCPT ); Tue, 28 Jan 2020 09:26:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:54128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733200AbgA1O0i (ORCPT ); Tue, 28 Jan 2020 09:26:38 -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 6FC9224686; Tue, 28 Jan 2020 14:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221597; bh=ry1w5+wOxDp6nob0N2laByzLXUOzRwsg+mF825EiCfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wcAgr5/CKIOBpx7IdqCW8IxQLpQji8BlL4X/dBYys79qDymIBg9loNR9lXGYium8I U1dwLZWul6G88juZBOd3XdYN+VYtRuEAdMHHGAILSePzopRDTBlCmkyp8ibJQK8CI2 C7NNjO1kRSyrhkjsoLnTjESPPr9SOdrmFgmYmK1w= 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 4.19 14/92] net-sysfs: Call dev_hold always in netdev_queue_add_kobject Date: Tue, 28 Jan 2020 15:07:42 +0100 Message-Id: <20200128135811.014435471@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135809.344954797@linuxfoundation.org> References: <20200128135809.344954797@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jouni Hogander commit e0b60903b434a7ee21ba8d8659f207ed84101e89 upstream. 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 @@ -1469,14 +1469,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)