From patchwork Fri Jun 25 01:39:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12343459 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 2C18EC49EA5 for ; Fri, 25 Jun 2021 01:39:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DBA106044F for ; Fri, 25 Jun 2021 01:39:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBA106044F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EED578D000B; Thu, 24 Jun 2021 21:39:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9D2D8D0007; Thu, 24 Jun 2021 21:39:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC9B08D000B; Thu, 24 Jun 2021 21:39:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 99F638D0007 for ; Thu, 24 Jun 2021 21:39:34 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BCCD0250B7 for ; Fri, 25 Jun 2021 01:39:34 +0000 (UTC) X-FDA: 78290539068.15.BEFD717 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP id 81F99200106B for ; Fri, 25 Jun 2021 01:39:34 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 8AE7D6044F; Fri, 25 Jun 2021 01:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1624585173; bh=Rl3INkCWLXQUZ+pg4mwfU0Rz3o+ozGzkbWJMmLIpk1A=; h=Date:From:To:Subject:In-Reply-To:From; b=gJvkjtUf27BQxW50JGOvzv91hHLghsv1nOo6OQxlp5Q4aaNOufZuLa2RjFvrkwihy txV8l7ARgaDLsSMFeMzzGUUrWLqSXkrE+QOHdAXz4lu7zhnSKCeoUJjzoxfZbDyMhh hPcKUB0ctMqurm6OmHyMiwkrRcHr72hJNmhQo26M= Date: Thu, 24 Jun 2021 18:39:33 -0700 From: Andrew Morton To: akpm@linux-foundation.org, konishi.ryusuke@gmail.com, linux-mm@kvack.org, mlsemon35@gmail.com, mm-commits@vger.kernel.org, paskripkin@gmail.com, torvalds@linux-foundation.org Subject: [patch 11/24] nilfs2: fix memory leak in nilfs_sysfs_delete_device_group Message-ID: <20210625013933.6EAm6MayP%akpm@linux-foundation.org> In-Reply-To: <20210624183838.ac3161ca4a43989665ac8b2f@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=gJvkjtUf; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 81F99200106B X-Stat-Signature: xjab3ymqyfjmcrpnmk4tkb47fwmawrut X-HE-Tag: 1624585174-574906 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Pavel Skripkin Subject: nilfs2: fix memory leak in nilfs_sysfs_delete_device_group My local syzbot instance hit memory leak in nilfs2. The problem was in missing kobject_put() in nilfs_sysfs_delete_device_group(). kobject_del() does not call kobject_cleanup() for passed kobject and it leads to leaking duped kobject name if kobject_put() was not called. Fail log: BUG: memory leak unreferenced object 0xffff8880596171e0 (size 8): comm "syz-executor379", pid 8381, jiffies 4294980258 (age 21.100s) hex dump (first 8 bytes): 6c 6f 6f 70 30 00 00 00 loop0... backtrace: [] kstrdup+0x36/0x70 mm/util.c:60 [] kstrdup_const+0x53/0x80 mm/util.c:83 [] kvasprintf_const+0x108/0x190 lib/kasprintf.c:48 [] kobject_set_name_vargs+0x56/0x150 lib/kobject.c:289 [] kobject_add_varg lib/kobject.c:384 [inline] [] kobject_init_and_add+0xc9/0x160 lib/kobject.c:473 [] nilfs_sysfs_create_device_group+0x150/0x800 fs/nilfs2/sysfs.c:999 [] init_nilfs+0xe26/0x12b0 fs/nilfs2/the_nilfs.c:637 Link: https://lkml.kernel.org/r/20210612140559.20022-1-paskripkin@gmail.com Fixes: da7141fb78db ("nilfs2: add /sys/fs/nilfs2/ group") Signed-off-by: Pavel Skripkin Acked-by: Ryusuke Konishi Cc: Michael L. Semon Signed-off-by: Andrew Morton --- fs/nilfs2/sysfs.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_delete_device_group +++ a/fs/nilfs2/sysfs.c @@ -1053,6 +1053,7 @@ void nilfs_sysfs_delete_device_group(str nilfs_sysfs_delete_superblock_group(nilfs); nilfs_sysfs_delete_segctor_group(nilfs); kobject_del(&nilfs->ns_dev_kobj); + kobject_put(&nilfs->ns_dev_kobj); kfree(nilfs->ns_dev_subgroups); }