Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp982819pxp; Wed, 16 Mar 2022 23:25:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybyJ4pD+SjQ5KgaMO8YQdW5yNIteFPyNxRLhqolW8GJfcDAbIsFobebkenmSq46KDzZBbe X-Received: by 2002:a17:902:c189:b0:153:9f00:bafd with SMTP id d9-20020a170902c18900b001539f00bafdmr3477060pld.171.1647498344431; Wed, 16 Mar 2022 23:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647498344; cv=none; d=google.com; s=arc-20160816; b=xYFEdgXOxjFkWeZt2f4BX4fKKg/rmil7eEUAniVl2IMA8OhwIX7YKVtbVeExkeE2iM 1xY0hZnZuL3IvoG733F6DQn8Y8xe9BRhHLAk1pxzWRcZFbH67Ny0B4IC/w9J/yDtoFh9 oesnNdg4jPpq1Mgfn2tYdSx3UXqcMLTzRfjDyKHm4ahLE5QbCGG1STtCbK0kizNLHvrv tLA9WweqpQC287t7eUUhXuDE6B1yGQpciWeDCEZQ4sNUfbaQSW/8mG/ut6dLZJygTQU3 3JpIBc+aPdxE4rC2hFSi8G+Qkx+/We5+Lf7SOa2pieXPHcFEF0NMe8bjrabFLuFasR2M DUBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EnTTr6mj6yg+cZdFX1bIbLC2oMGNkwyebsyh6QMugTk=; b=qSdwhvJI/UZTwp7jX7cpmHOXxOEEWjOTAFu/QXRVAQAdriREXsvfbepLTWIfS8ZR6K vDyEIzLl0EZlwOLh0jsn8RfnYNzDhrmd74okFtsxUZPhAc5AWMJmDwEMQas+NSXp61n2 vDkFkFs3NtybKBM7d/YzW7644n9EgcBKPvnelrsbbLwCxKEnKZRNLQKYmEu2rU1O5hHp 7emDSKJWxTbjVIQqRc871dJ2Hq4Y8sxNPnxL06S0HlhJ/TV9uET9XzbARoU/vMWj6jlK iz5YVaO3AR4EChIuFBWGlt6Ak0XcXDalvGoorucWKMeCMskKrZKZvNQQDSJlz0GcZmpG H5XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RpZxAGtA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m11-20020a170902f64b00b00153215fec34si4062463plg.27.2022.03.16.23.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:25:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RpZxAGtA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 133F51CD7D8; Wed, 16 Mar 2022 22:11:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346512AbiCOJTq (ORCPT + 99 others); Tue, 15 Mar 2022 05:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346519AbiCOJTn (ORCPT ); Tue, 15 Mar 2022 05:19:43 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0C41C911; Tue, 15 Mar 2022 02:18:30 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id p15so39761577ejc.7; Tue, 15 Mar 2022 02:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EnTTr6mj6yg+cZdFX1bIbLC2oMGNkwyebsyh6QMugTk=; b=RpZxAGtAsiaQq2EjtUjq0pVkzgDfzqFxUHBlQWSdv6Ha2d7hyFYGAEU/mATuq/cACP IMd2WkLvGI5nZeuQpWPs7xnK4y/8MspWBiTCLMfeWz1mDtrcobxH1/ht+JqNdt5WX/kM rJdItBirLkGgBX0hTboHGoXKsZhgfvFjpn/0ZYG8utbSnF/N74GO42t75N0VLWrzEf9F /hGsTly9TKWjMg2x0yQwWISscGw2Pc9Mv81TBGqoKjDR4SJ47PKOlacUOj21WNXWyEt2 rjN9mAy16V3Td7bHslf1VcIgVqUrg2EafO9nW83HNZ7mMujrOkP11S+43sFhL3/vNm8C w86Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EnTTr6mj6yg+cZdFX1bIbLC2oMGNkwyebsyh6QMugTk=; b=qiYpC/w6whmhmR5zHVcpWVCSjJr/D3CzvnN6xouaOZXx6wqyOMmXR9e975/RwvzSY1 5geOaypDC7w2vaWTYjWrhDPfpubwsC+nE6NK7dFkiNPHxsmFnRg3MBGvkItaeEqvnbDD 9eceTZOePuMb+YVrk7DINt/LykCJl6DxTt+Ih5VTa9Goayaaz5VFXfaiPPkACcNuAF5R S3J61JMkQzBFU4CIqjUMqcmQoCE3CZqQvMXgnOY59PV42QKJ4jTr1hvlNikSCyolYh+e 5Je3L56d9LcfnmKIUwZvIay8msjlgNSL3f3BMPtUL1fhJNWLOJnGkU2fsxokxMaaSBNT Qa2w== X-Gm-Message-State: AOAM53015C0GGnYNG7cFDL1tA3qORwCcdadDKQhAwlgoUwEZJvESQ/+a f2Q7ycaqSTjHk8JCWAxN9D/AVTD/6IuRqR73R88= X-Received: by 2002:a17:907:9956:b0:6cf:cd25:c5a7 with SMTP id kl22-20020a170907995600b006cfcd25c5a7mr21472111ejc.635.1647335908443; Tue, 15 Mar 2022 02:18:28 -0700 (PDT) MIME-Version: 1.0 References: <3192BC90-D082-472B-B310-6E09A14A77C6@hust.edu.cn> <7da316f4-aa65-896e-9020-2dfff2bbfc09@gmail.com> In-Reply-To: From: Dongliang Mu Date: Tue, 15 Mar 2022 17:18:02 +0800 Message-ID: Subject: Re: Fw:Re: [PATCH] fs: nilfs2: fix memory leak in nilfs sysfs create device group To: Ryusuke Konishi Cc: Pavel Skripkin , Andrew Morton , linux-nilfs , LKML , Nanyong Sun , =?UTF-8?B?5oWV5Yas5Lqu?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, Mar 15, 2022 at 5:11 PM Ryusuke Konishi wrote: > > Hi Dongliang, > > On Tue, Mar 15, 2022 at 2:50 PM Dongliang Mu wrote: > > > > On Tue, Mar 15, 2022 at 12:46 PM Ryusuke Konishi > > wrote: > > > > > > On Tue, Mar 15, 2022 at 10:59 AM Dongliang Mu wrote: > > > > > > > > On Sun, Mar 13, 2022 at 9:35 PM Dongliang Mu wrote: > > > > > > > > > > On Sun, Mar 13, 2022 at 12:01 AM Ryusuke Konishi > > > > > wrote: > > > > > > > > > > > > Hi Pavel and Dongliang, > > > > > > > > > > > > On Sun, Mar 13, 2022 at 12:16 AM Pavel Skripkin wrote: > > > > > > > > > > > > > > Hi Ryusuke, > > > > > > > > > > > > > > On 3/12/22 18:11, Ryusuke Konishi wrote: > > > > > > > >> In case of nilfs_attach_log_writer() error code jumps to > > > > > > > >> failed_checkpoint label and calls destroy_nilfs() which should call > > > > > > > >> nilfs_sysfs_delete_device_group(). > > > > > > > > > > > > > > > > nilfs_sysfs_delete_device_group() is called in destroy_nilfs() > > > > > > > > if nilfs->ns_flags has THE_NILFS_INIT flag -- nilfs_init() inline > > > > > > > > function tests this flag. > > > > > > > > > > > > > > > > The flag is set after init_nilfs() succeeded at the beginning of > > > > > > > > nilfs_fill_super() because the set_nilfs_init() inline in init_nilfs() sets it. > > > > > > > > > > > > > > > > So, nilfs_sysfs_delete_group() seems to be called in case of > > > > > > > > the above failure. Am I missing something? > > > > > > > > > > > > > > > > > > > > > > Yeah, that's what I mean :) I can't see how reported issue is possible > > > > > > > with current code. > > > > > > > > > > > > > > > > > > > > > Sorry for not being clear > > > > > > > > > > > > Understood, thanks for the reply. > > > > > > > > > > > > If so, the case where nilfs_sysfs_create_device_group() itself failed, > > > > > > is suspicious as mentioned in the previous mail. A possible scenario > > > > > > I guess is : > > > > > > > > > > > > - nilfs_sysfs_create_device_group() on the first mount try fails and leaks > > > > > > due to lack of kobject_del() in the error path. > > > > > > - Then, nilfs_sysfs_create_device_group() on the next mount try hits > > > > > > the leak detector at kobject_init_and_add(). > > > > > > > > > > > > So, if the leak bug is reproducible, I'd like to ask Dongliang to > > > > > > test the effect of the first patch. > > > > > > > > > > If my local syzkaller instance gets a reproducer, I will try to do this. > > > > > > > > > > > > > > > > > Regards, > > > > > > Ryusuke Konishi > > > > > > > > Hi Ryusuke, > > > > > > > > The crash still occurred in my newly set up syzkaller instance. It > > > > appears after two days' fuzzing. > > > > > > > > I remember you suggested me to add kobject_del just for testing, > > > > right? And let's see if this crash still occurs any more. > > > > > > You need a few days to reproduce it ? > > > If so, I think this confirmation method is uncertain. > > > In that case, I will try inserting an artificial error by changing > > > nilfs_sysfs_create_device_group() a bit to confirm if the same crash occurs. > > I tried to change the code of nilfs_sysfs_create_device_group() so that > an error occurs once every two times. > As a result, the leak bug was not reproduced. > > In addition, by kobject debug messages, I saw that the device name > ("loop2" in your case) was properly freed through kobject_put() even in > the erroneous case. > > So, my previous guess was wrong. > Looks like there is another cause for the leak of the device name. > It may not be a nilfs2 issue, I don't know. > > > I am reproducing another bug [1] recently. If you can spare some time > > figuring out the underlying issue, that's really great. Or we can wait > > some time for the bug to disclose more, after all, it is only a rare > > memory leak. > > > > [1] https://syzkaller.appspot.com/bug?extid=045796dbe294d53147e6 > > According to the log, it looks like "erofs_put_super() -> > erofs_unregister_sysfs()" hits: > > kobject: '(null)' (ffff88807b550190): is not initialized, yet > kobject_put() is being called. > > This warning is output in kobject_put() if kobj argument is not in > 'state_initialized': > > void kobject_put(struct kobject *kobj) > { > if (kobj) { > if (!kobj->state_initialized) > WARN(1, KERN_WARNING > "kobject: '%s' (%p): is not > initialized, yet kobject_put() is being called.\n", > kobject_name(kobj), kobj); > kref_put(&kobj->kref, kobject_release); > } > } > > How about chasing this abnormal condition ? > Anyway, please ask erofs maintainers and linux-erofs mailing list for this. Thanks for your information. I have got the reproducer and sent the patch to the kernel mailing list this afternoon. I will start reproducing this case and try to fix it if reproducible. Thanks very much. > > Regards, > Ryusuke Konishi