From patchwork Tue Jan 28 13:57:46 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: 232760 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=ham 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 C38AEC33CB3 for ; Tue, 28 Jan 2020 13:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 919042468A for ; Tue, 28 Jan 2020 13:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580219960; bh=dCPWa8MIs/gY7UhmdP6wQjc+AxHDwauBWDjka8VCMsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UV1VKGO6drNwRNV5SORFm1WH+pg/v1UdUb9LRbQHLOQtFaS4lKXH0ZjAqUH7MhQCn Krty4efKMc92Vfp+q0DGrmMTBMVHufElap3G2qysFBdDuFq1bY3ceKqbpgR+FWR0m1 lpPRWyhHGBllvV5TpryQHjUDYh1FamvjepQuo5So= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726794AbgA1N7T (ORCPT ); Tue, 28 Jan 2020 08:59:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:44644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726823AbgA1N7S (ORCPT ); Tue, 28 Jan 2020 08:59:18 -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 8DCB32468A; Tue, 28 Jan 2020 13:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580219958; bh=dCPWa8MIs/gY7UhmdP6wQjc+AxHDwauBWDjka8VCMsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jzMnriDZdea88RZmeOg6Yqo0R/ZkcAg9Fg2vXE2iKUy0NVJutT+6wEcakrpMDhnD9 iodjBgp4UaBQpwyQ0OgF81kqqy+2H/vbeNTYDZa7qXb7dFds/0hw8djJScL/BG1EI/ N4V0A1wDV8W/1BSpY8ExbQ0bOiok1rKvhc+PL1e8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , David Miller , Lukas Bulwahn , Jouni Hogander Subject: [PATCH 4.14 12/46] net-sysfs: Call dev_hold always in rx_queue_add_kobject Date: Tue, 28 Jan 2020 14:57:46 +0100 Message-Id: <20200128135751.652489138@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135749.822297911@linuxfoundation.org> References: <20200128135749.822297911@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 ddd9b5e3e765d8ed5a35786a6cb00111713fe161 upstream. Dev_hold has to be called always in rx_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: syzbot Cc: Tetsuo Handa Cc: David Miller Cc: Lukas Bulwahn Signed-off-by: Jouni Hogander 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 @@ -911,14 +911,17 @@ static int rx_queue_add_kobject(struct n struct kobject *kobj = &queue->kobj; int error = 0; + /* Kobject_put later will trigger rx_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, &rx_queue_ktype, NULL, "rx-%u", index); if (error) goto err; - dev_hold(queue->dev); - if (dev->sysfs_rx_queue_group) { error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group); if (error)