Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752102AbbKPMjP (ORCPT ); Mon, 16 Nov 2015 07:39:15 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:36007 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751583AbbKPMjL (ORCPT ); Mon, 16 Nov 2015 07:39:11 -0500 X-AuditID: cbfee61b-f79d56d0000048c5-0d-5649ce6d276f From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: fix memory leak of kobject in error path of fill_super Date: Mon, 16 Nov 2015 20:38:25 +0800 Message-id: <008c01d1206b$c9cf4a90$5d6ddfb0$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdEga1MB3Hth5tgzTRi967EtpAsPvg== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJLMWRmVeSWpSXmKPExsVy+t9jAd3cc55hBrsncFk8WT+L2eLSIneL y7vmsDkwe2xa1cnmsXvBZyaPz5vkApijuGxSUnMyy1KL9O0SuDJO7J/OWLCSr+LADb4Gxvfc XYwcHBICJhKfZhl2MXICmWISF+6tZ+ti5OIQEljKKPG19worhPOKUeLfsR1MIFVsAioSyzv+ g9kiQPahRZfZQWxmAQ+Jxo7vrCC2sICvxLdbR1hAFrAIqEqsXCQHEuYVsJS4M/s4G4QtKPFj 8j0WiFYtifU7jzNB2PISm9e8ZYY4SEFix9nXjBCr9CQerVrGClEjLrHxyC2WCYwCs5CMmoVk 1Cwko2YhaVnAyLKKUSK1ILmgOCk91ygvtVyvODG3uDQvXS85P3cTIziAn0nvYDy8y/0QowAH oxIPr8Jz9zAh1sSy4srcQ4wSHMxKIrxdpz3DhHhTEiurUovy44tKc1KLDzFKc7AoifPqexqF CQmkJ5akZqemFqQWwWSZODilGhi12mu1tge4ZEzbaOFzR4UlY9XmmaktJjMdtRnZrlltTNPY rO+zRfSy8BUX37yWepvXRte/TCx6rtAibutnulXLbWuN2vwPvY5c/+t+RmutXnD7k/q3GZP2 qHwrknz4yVmu7O+JilMp93U8Tq+8kCIxeVnKz5txvtWz/54sEGL4xPrl0JVW/s9KLMUZiYZa zEXFiQCN3Gt8XAIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2024 Lines: 59 f2fs_sb_info::s_kobj should be released in error path of fill_super, otherwise it will lead to memory leak. This bug was found by kmemleak: dmesg: kmemleak: 2 new suspected memory leaks (see /sys/kernel/debug/kmemleak) cat /sys/kernel/debug/kmemleak unreferenced object 0xffff8800838dc358 (size 8): comm "mount", pid 4154, jiffies 4297482839 (age 1911.412s) hex dump (first 8 bytes): 7a 72 61 6d 31 00 ff ff zram1... backtrace: [] kmemleak_alloc+0x28/0x50 [] __kmalloc_track_caller+0xef/0x1c0 [] kstrdup+0x45/0x80 [] kstrdup_const+0x28/0x30 [] kvasprintf_const+0x63/0xa0 [] kobject_set_name_vargs+0x3c/0xa0 [] kobject_add_varg+0x25/0x60 [] kobject_init_and_add+0x53/0x70 [] f2fs_fill_super+0x9d9/0xc40 [f2fs] [] mount_bdev+0x192/0x1d0 [] f2fs_mount+0x15/0x20 [f2fs] [] mount_fs+0x43/0x170 [] vfs_kern_mount+0x76/0x160 [] do_mount+0x258/0xdc0 [] SyS_mount+0x7b/0xc0 [] entry_SYSCALL_64_fastpath+0x12/0x6f ... Signed-off-by: Chao Yu --- fs/f2fs/super.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 9d0ea11..f394d20 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1362,6 +1362,8 @@ try_onemore: free_kobj: kobject_del(&sbi->s_kobj); + kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); free_proc: if (sbi->s_proc) { remove_proc_entry("segment_info", sbi->s_proc); -- 2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/