From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18C3FC433F5 for ; Tue, 15 Mar 2022 11:05:47 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KHrDT4VyWz30GN for ; Tue, 15 Mar 2022 22:05:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qrx7ZR9n; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1030; helo=mail-pj1-x1030.google.com; envelope-from=jnhuang95@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qrx7ZR9n; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KHrDM1LbTz2y7M for ; Tue, 15 Mar 2022 22:05:38 +1100 (AEDT) Received: by mail-pj1-x1030.google.com with SMTP id mj15-20020a17090b368f00b001c637aa358eso1657374pjb.0 for ; Tue, 15 Mar 2022 04:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:to:cc:references :from:in-reply-to:content-transfer-encoding; bh=kuK4I2tojx5UmkgwIWGWy7dBaK7RpGnhCg0EIQSmGxw=; b=qrx7ZR9ndfJG3lJpJBz/HJZ9Ap9HB1jiHmW+Yf9ayVXtZ+5iVwMyYWMNpvOp6TXiGR L7zUbiJ/prSfJZfnwV5vkWPFV9Hpx4ISpf8pRXKFrGBHz3j/OJTHsGRWOHj6MZaC+acY scMv8RNLAw9oEzrojECbS7FpI0+JYvXd6X2PWp0CPTk6MA8PVGuoWqnqkuOy2mU8PhRU ocqww9WBDEbxrWrRmEUfm2dKL9Dp4MbeqxN75bPu4ex2uCZYBh4nBh8WtxY7yRkDleb7 HI4rkOj37DL6db7N6oMcVOMhEvvmU5m4WdhpN3p+1WWymVThvUCzN5R+4e+omsVcRAAI uMUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :to:cc:references:from:in-reply-to:content-transfer-encoding; bh=kuK4I2tojx5UmkgwIWGWy7dBaK7RpGnhCg0EIQSmGxw=; b=cBqLkn5QLgmkimbzyEeu0A7pUFO3ztB7/wsvwFsNJzmoBT5V3KXPbB8eYnwgfOAr6p 2EoCxxRj0CA1gJOeQcxLBwHRlkUZRMSUUr5Pn2xVpWHY4EX1ky8ZSoR4ZybfUmDE3W8r 0hHJk7ZQOF0JU0tOmA5e3kQNPaVVdgsdthP30wAYHlRpioKFjB54VG+P0JeBqHsWLkKW nHWzbKg/E3lMnkwKLFWxjWO4hm+APX7NiTdAj0jJNP/6Z2yg46mZ79UYsMi8VdcrLQVm lpbRSwn3ApSlkAPcm/t3pyy9dgsQYP6E4e6TDMLo3Tgx8CC53/kMUf6i9kKsv4iogKlr QcyA== X-Gm-Message-State: AOAM533tlvvGJhrV6kANzNRnWpdYQYDRmuNfu+M8vjODuGSeOTUn8jWZ cSXkqQEmyfZRr8DMIpOigu0= X-Google-Smtp-Source: ABdhPJypZlFCeCodjEQKPkdy0A15ZfdulIZDg/AcsnNrzl7o3ou5sEUVcNOUj3lYdGf68D4r8WAGjw== X-Received: by 2002:a17:902:e848:b0:151:e3a5:b609 with SMTP id t8-20020a170902e84800b00151e3a5b609mr27320794plg.137.1647342335590; Tue, 15 Mar 2022 04:05:35 -0700 (PDT) Received: from [127.0.0.1] ([103.97.175.139]) by smtp.gmail.com with ESMTPSA id lr9-20020a17090b4b8900b001c645bf9a0bsm1798544pjb.1.2022.03.15.04.05.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Mar 2022 04:05:35 -0700 (PDT) Message-ID: <8d832e7a-c8da-d2fa-571a-ea150b8deb1b@gmail.com> Date: Tue, 15 Mar 2022 19:05:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] fs: erofs: remember if kobject_init_and_add was done To: Gao Xiang References: <20220315075152.63789-1-dzm91@hust.edu.cn> From: Huang Jianan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dongliang Mu , Dongliang Mu , linux-kernel@vger.kernel.org, syzkaller , linux-erofs@lists.ozlabs.org Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 在 2022/3/15 18:55, Gao Xiang 写道: > On Tue, Mar 15, 2022 at 06:43:01PM +0800, Huang Jianan wrote: >> 在 2022/3/15 15:51, Dongliang Mu 写道: >>> 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; >> Hi Dongliang, >> >> How about using sbi->s_kobj.state_in_sysfs to avoid adding a extra member in >> sbi ? > Ok, I have no tendency of these (I'm fine with either ways). > I've seen some usage like: > > static inline int device_is_registered(struct device *dev) > { > return dev->kobj.state_in_sysfs; > } > > But I'm still not sure if we need to rely on such internal > interface.. More thoughts? Yeah... It seems that it is better to use some of the interfaces provided by kobject, otherwise we should still maintain this state in sbi. Thanks, Jianan > Thanks, > Gao Xiang >> Thanks, >> Jianan >> >>> 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)