Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5999752ybc; Wed, 27 Nov 2019 13:10:12 -0800 (PST) X-Google-Smtp-Source: APXvYqz1XMpMiqWW8sDrjtEnBmUDGoAIa1Y3t53yQlPQvx9j4l+JmhP9N164XrZMbChxEEpEjKph X-Received: by 2002:a17:906:1d59:: with SMTP id o25mr50716879ejh.17.1574889012420; Wed, 27 Nov 2019 13:10:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889012; cv=none; d=google.com; s=arc-20160816; b=Kd49W139KSCyJJJeu2YelqPEl/lskX848iXIG2YsyOnnSlDcdICMzxy8l83UkIQdJP Se0qvlHUyf/5d1TA1IjaRc/oGaZAquV+nRdk8lGWIZ9kQ/4F93cpVW1ktEQ/ED5wmdRy 3OJnd58hh50wY7cKlwpzArlb971WhM8JBKtkY/myNIkozv4efpA4djSWKW3j88R/QRee +tolJ0Tn2RmJrDCu2SC5tvssrVGnOSTWpaZlXdETwbmyBndvJ1bWAlPT1h+Rz8fmIzfX 24d+ROmDa0yG4e75pnzNhUrHKcVf8XK3VVXnZDpqiPC7c4yFn9wSCrbZfo7WvWD9gbFq mtnw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KiAZd0Wz3abIjgl7ui1F6dpdXXm0OKs7QWtfsJxg4/A=; b=nFpXsC0uC2G4x6gwzmZ0tsfcwQBcWr+hhHbhMhlvOTPIY8HeWTXVchA8NEkN13J4xN 2A1S1enry0PPtycHf49AqsayKDl1XNlfAifdDp4gLK3O94BUzY/wiLpJFZ12NuZFhJRC D19bWU+6hVRQNeVpD3JBKO0LArGShHPu+9Kgt2t1aGowyITgO7FMdTcAg2+3uRfP7f3y W8xeLtK7HCgxN8hnNHXeKLJkHRXnUbwGYRShxE3U8RP5CiiBemyovw5C/Eh7SKBQ8huS evtLMtyvouKnspJOkISVNvBdEfWEr/KSWdJ+XWOZcovSfADKdNYiPT4EJPwBM4aswgxD OzfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=COrgOezJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si12003085edc.353.2019.11.27.13.09.48; Wed, 27 Nov 2019 13:10:12 -0800 (PST) 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=COrgOezJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731898AbfK0VIL (ORCPT + 99 others); Wed, 27 Nov 2019 16:08:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730931AbfK0VII (ORCPT ); Wed, 27 Nov 2019 16:08:08 -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 EA4B12176D; Wed, 27 Nov 2019 21:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888887; bh=qV0WTWfRpMVnCr3u5uMAmCSY3+zE+d0NXXZ2q9BfVUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=COrgOezJMiwdKp/HeAu2/fmrHYaNhvCkWBv67m7+5ABAsa0xxaxeHKcwUdH2E8fNC DjmE9Bx8MH1B5Dp4BDpzD0bMqLXvaEeOkLovBtAtDR4dN6nzF2HoSvcV4Jn20Z0ypv XB9r/HBHX3Q7yqH0CPfW0RFsokiUlDwFlxZsHp+M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Miller , Lukas Bulwahn , Jouni Hogander Subject: [PATCH 4.19 282/306] net-sysfs: Fix reference count leak in rx|netdev_queue_add_kobject Date: Wed, 27 Nov 2019 21:32:12 +0100 Message-Id: <20191127203135.382666831@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 commit b8eb718348b8fb30b5a7d0a8fce26fb3f4ac741b upstream. kobject_init_and_add takes reference even when it fails. This has to be given up by the caller in error handling. Otherwise memory allocated by kobject_init_and_add is never freed. Originally found by Syzkaller: BUG: memory leak unreferenced object 0xffff8880679f8b08 (size 8): comm "netdev_register", pid 269, jiffies 4294693094 (age 12.132s) hex dump (first 8 bytes): 72 78 2d 30 00 36 20 d4 rx-0.6 . backtrace: [<000000008c93818e>] __kmalloc_track_caller+0x16e/0x290 [<000000001f2e4e49>] kvasprintf+0xb1/0x140 [<000000007f313394>] kvasprintf_const+0x56/0x160 [<00000000aeca11c8>] kobject_set_name_vargs+0x5b/0x140 [<0000000073a0367c>] kobject_init_and_add+0xd8/0x170 [<0000000088838e4b>] net_rx_queue_update_kobjects+0x152/0x560 [<000000006be5f104>] netdev_register_kobject+0x210/0x380 [<00000000e31dab9d>] register_netdevice+0xa1b/0xf00 [<00000000f68b2465>] __tun_chr_ioctl+0x20d5/0x3dd0 [<000000004c50599f>] tun_chr_ioctl+0x2f/0x40 [<00000000bbd4c317>] do_vfs_ioctl+0x1c7/0x1510 [<00000000d4c59e8f>] ksys_ioctl+0x99/0xb0 [<00000000946aea81>] __x64_sys_ioctl+0x78/0xb0 [<0000000038d946e5>] do_syscall_64+0x16f/0x580 [<00000000e0aa5d8f>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [<00000000285b3d1a>] 0xffffffffffffffff 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 | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -932,21 +932,23 @@ static int rx_queue_add_kobject(struct n error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, "rx-%u", index); if (error) - return 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) { - kobject_put(kobj); - return error; - } + if (error) + goto err; } kobject_uevent(kobj, KOBJ_ADD); return error; + +err: + kobject_put(kobj); + return error; } #endif /* CONFIG_SYSFS */ @@ -1471,21 +1473,21 @@ static int netdev_queue_add_kobject(stru error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, "tx-%u", index); if (error) - return error; + goto err; dev_hold(queue->dev); #ifdef CONFIG_BQL error = sysfs_create_group(kobj, &dql_group); - if (error) { - kobject_put(kobj); - return error; - } + if (error) + goto err; #endif kobject_uevent(kobj, KOBJ_ADD); - return 0; +err: + kobject_put(kobj); + return error; } #endif /* CONFIG_SYSFS */