From patchwork Mon Oct 24 11:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp417200wru; Mon, 24 Oct 2022 05:12:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nr8Ylo+Nnzr1Bt9gfKwJ0datUB6y3FtlFFUq7l1Q04mNIODmZkQVgB733cU3O5VArllDZ X-Received: by 2002:a17:906:6086:b0:731:3970:48d0 with SMTP id t6-20020a170906608600b00731397048d0mr27975752ejj.16.1666613565735; Mon, 24 Oct 2022 05:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613565; cv=none; d=google.com; s=arc-20160816; b=1JXLtgRUo1dyUsvyXb6L/lYEHxW/NkqaMt3otUv0pPopaz6H7ud5XaojPUNHE8e8HE nNnljm+ShpMGkCuPi0G1ECSRlhxgMC4F4L0V8/c/nBcsrnwMZuyEuQHADlC+Hvkctogf egFuuy0ZLzybLI2ynlpkCvaLUDjClinbfx50NHWZLsfwSwxIv920ttvhx829wI9BrDg1 W0McNG2RdpbuMfB3prSIG3+uyeiFCrOoK8S3ogaKLnBEwtepfYQnqZfL9aHlD84qzdeL 7lGCdQI6Nr+4AQ5VqrCu4hFP97he8bN57VP2i7yQvCphlYZwH9ou9r/cqAC/pm2PHBRb 5AMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wBBHVQ/SnCsgwj7CeL+2mN9nfbtgASLm5a5qWciU3lA=; b=OrEWq3215otTYOIx3ZrdUUzOQfb7+Hpp5mxp8sPaO3IKk/ipT3z/F5PLxx725VvBDN 6J96+1BoxFk9hrxlk0oPRoHf/KjuQcAbq1r8oMaoO6hzjE5hZ0cpFN/Z4M6OPv77rLXS rybvh1AXbRsZi3bM9JP3Gg9vxobZpb0w1EHg6PaAO/h+B6onEDjVVtkIz9qfK2NvwgvG yKWzdsF0MjopB0itkyKLK6XaxH+NwiyBT1O1Oy6rRTxF4I4z+gag3ONjoOIoACIlGCef C4LXiRnwbdmFnx1gpV/r1Ab7MDH++Dt3fofUeZ+nUeMKPNqB0jdCTfYZKXH+sL2YOheq NC2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hXOLf5NO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a056402084b00b0045b265a1712si33942077edz.595.2022.10.24.05.12.21; Mon, 24 Oct 2022 05:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hXOLf5NO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbiJXMBq (ORCPT + 99 others); Mon, 24 Oct 2022 08:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbiJXL7S (ORCPT ); Mon, 24 Oct 2022 07:59:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C98512A70C; Mon, 24 Oct 2022 04:47:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 59DC461286; Mon, 24 Oct 2022 11:39:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72873C433D6; Mon, 24 Oct 2022 11:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611566; bh=fzdObW4Tz01b4F6wuAJJY5sICvfv8+U/Svx9awbkDJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hXOLf5NOyXk1YzivyOZxgSost0vHaePp6Aek/HhBP9Ca/PmcmGuJRtdUE1vEt9IK6 uSboZJ61+Hj4RpOJtERSj+5Tpof8npVsYJNKhh3UrZcMG0dUk99C4avCLieNj4hQZt 6rprdXWo5Eq6b8Iv0g99xRTuxi/lIIBbqyA0NQdY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ryusuke Konishi , syzbot+7381dc4ad60658ca4c05@syzkaller.appspotmail.com, Andrew Morton Subject: [PATCH 4.9 028/159] nilfs2: fix leak of nilfs_root in case of writer thread creation failure Date: Mon, 24 Oct 2022 13:29:42 +0200 Message-Id: <20221024112950.436896065@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747570986207274104?= X-GMAIL-MSGID: =?utf-8?q?1747570986207274104?= From: Ryusuke Konishi commit d0d51a97063db4704a5ef6bc978dddab1636a306 upstream. If nilfs_attach_log_writer() failed to create a log writer thread, it frees a data structure of the log writer without any cleanup. After commit e912a5b66837 ("nilfs2: use root object to get ifile"), this causes a leak of struct nilfs_root, which started to leak an ifile metadata inode and a kobject on that struct. In addition, if the kernel is booted with panic_on_warn, the above ifile metadata inode leak will cause the following panic when the nilfs2 kernel module is removed: kmem_cache_destroy nilfs2_inode_cache: Slab cache still has objects when called from nilfs_destroy_cachep+0x16/0x3a [nilfs2] WARNING: CPU: 8 PID: 1464 at mm/slab_common.c:494 kmem_cache_destroy+0x138/0x140 ... RIP: 0010:kmem_cache_destroy+0x138/0x140 Code: 00 20 00 00 e8 a9 55 d8 ff e9 76 ff ff ff 48 8b 53 60 48 c7 c6 20 70 65 86 48 c7 c7 d8 69 9c 86 48 8b 4c 24 28 e8 ef 71 c7 00 <0f> 0b e9 53 ff ff ff c3 48 81 ff ff 0f 00 00 77 03 31 c0 c3 53 48 ... Call Trace: ? nilfs_palloc_freev.cold.24+0x58/0x58 [nilfs2] nilfs_destroy_cachep+0x16/0x3a [nilfs2] exit_nilfs_fs+0xa/0x1b [nilfs2] __x64_sys_delete_module+0x1d9/0x3a0 ? __sanitizer_cov_trace_pc+0x1a/0x50 ? syscall_trace_enter.isra.19+0x119/0x190 do_syscall_64+0x34/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd ... Kernel panic - not syncing: panic_on_warn set ... This patch fixes these issues by calling nilfs_detach_log_writer() cleanup function if spawning the log writer thread fails. Link: https://lkml.kernel.org/r/20221007085226.57667-1-konishi.ryusuke@gmail.com Fixes: e912a5b66837 ("nilfs2: use root object to get ifile") Signed-off-by: Ryusuke Konishi Reported-by: syzbot+7381dc4ad60658ca4c05@syzkaller.appspotmail.com Tested-by: Ryusuke Konishi Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/segment.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2796,10 +2796,9 @@ int nilfs_attach_log_writer(struct super inode_attach_wb(nilfs->ns_bdev->bd_inode, NULL); err = nilfs_segctor_start_thread(nilfs->ns_writer); - if (err) { - kfree(nilfs->ns_writer); - nilfs->ns_writer = NULL; - } + if (unlikely(err)) + nilfs_detach_log_writer(sb); + return err; }