Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp392054pxp; Wed, 16 Mar 2022 07:56:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy10OwWJp5luv4Vrv1CvgcUB4iri0WJVgtb0eg74iru505JYGCAs9Xv18dJxpcCljLrPLQ1 X-Received: by 2002:a63:db53:0:b0:380:cf1d:4401 with SMTP id x19-20020a63db53000000b00380cf1d4401mr11791pgi.504.1647442596399; Wed, 16 Mar 2022 07:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647442596; cv=none; d=google.com; s=arc-20160816; b=0nnOH7RSGejY+KRJjZZHfle+hd+AkwsK8UG8wLh/Fwd8W/dxguq68KRHZpY0hWCVV9 4GwRREvHxDUeMZt0YQ45obR4Sw5XnEOIghoBTtQJTiXwgzFhNKJEk1JLUbrySlAwumLN lLIiRYqVWnPpWfD6IDygFPUif3rqrM5MEKQ1Lk0ah4/MrbscFcthweX3pLuTpdjMXzeV xfYb90nHoiqSN0StJ+zJ4L6H9zSbWFzQZhN4E31aioc1k5JVfsT3md14ya6RykCWdI3I FNQMzVoTWBu3o1FOq8RfH+A3Cdy6UzWJgsJh3X87J6Ri7aA6uGDwhWK9NHctd9tytN+t ATaw== 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 :message-id:date:subject:cc:to:from; bh=B7tNBfiNin2hSbCQlBFfa/fnQIZYaZzn96yFXNt2SDY=; b=jfIATYmqKVvnyZN2xXSQNs+UnxHwJBpyC2B/P1eRtTpYSh4sMf1oCf5qgMxgr8Z5R6 S6kO6HX7+AycHm6MG7WPy6jsKbBNwJoaMxk9gfimuqH0vVtqd5q4CloOiS0Vcm8ooqNP Fwq+1WBNWSMwHTQIZfxbdVR5w51YhsW02BGyB+8fSwCuUx0vt+Pf+/VTx23vx4V1G4xF 8vjsjC/0g2D5IikP14XuUHp6jLRI2Xp8MME9MbwC4txHE09FVq4deO7V+/PSkl5YFFkl jR3m4Ub1fB05J9ANy5FiNLMTUXesUvUdhif1Uu39DAcsbT/4PSAMSoI7NKjfDg609Dv0 9sSg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a170902db0300b001530856ac38si2157557plx.26.2022.03.16.07.56.21; Wed, 16 Mar 2022 07:56:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345679AbiCOHxo (ORCPT + 99 others); Tue, 15 Mar 2022 03:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345661AbiCOHxn (ORCPT ); Tue, 15 Mar 2022 03:53:43 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDAA84BB9A for ; Tue, 15 Mar 2022 00:52:29 -0700 (PDT) Received: from localhost.localdomain ([172.16.0.254]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 22F7pr4U009621-22F7pr4X009621 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 15 Mar 2022 15:51:58 +0800 From: Dongliang Mu To: Gao Xiang , Chao Yu Cc: Dongliang Mu , syzkaller , linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs: erofs: remember if kobject_init_and_add was done Date: Tue, 15 Mar 2022 15:51:52 +0800 Message-Id: <20220315075152.63789-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: dzm91@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Dongliang Mu Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug is triggered by injecting fault in kobject_init_and_add of erofs_unregister_sysfs. Fix this by remembering if kobject_init_and_add is successful. Note that I've tested the patch and the crash does not occur any more. Reported-by: syzkaller Signed-off-by: Dongliang Mu --- fs/erofs/internal.h | 1 + fs/erofs/sysfs.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 5aa2cf2c2f80..9e20665e3f68 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -144,6 +144,7 @@ struct erofs_sb_info { u32 feature_incompat; /* sysfs support */ + bool s_sysfs_inited; struct kobject s_kobj; /* /sys/fs/erofs/ */ struct completion s_kobj_unregister; }; diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index dac252bc9228..2b48a4df19b4 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -209,6 +209,7 @@ int erofs_register_sysfs(struct super_block *sb) "%s", sb->s_id); if (err) goto put_sb_kobj; + sbi->s_sysfs_inited = true; return 0; put_sb_kobj: @@ -221,9 +222,11 @@ void erofs_unregister_sysfs(struct super_block *sb) { struct erofs_sb_info *sbi = EROFS_SB(sb); - kobject_del(&sbi->s_kobj); - kobject_put(&sbi->s_kobj); - wait_for_completion(&sbi->s_kobj_unregister); + if (sbi->s_sysfs_inited) { + kobject_del(&sbi->s_kobj); + kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); + } } int __init erofs_init_sysfs(void) -- 2.25.1