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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A13B9C4332F for ; Thu, 10 Nov 2022 18:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbiKJSBr (ORCPT ); Thu, 10 Nov 2022 13:01:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbiKJSBQ (ORCPT ); Thu, 10 Nov 2022 13:01:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A6CC4D5F2 for ; Thu, 10 Nov 2022 10:00:57 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 3BD73B822D7 for ; Thu, 10 Nov 2022 18:00:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64060C433C1; Thu, 10 Nov 2022 18:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1668103254; bh=RG15lCfsSF3VLWo5w4AxBk8Klg/z3h9CDfelzjeZIo0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0n4nGSo/Nl3aiG4bJ2DBvlNIPrsc78Qowviz/BXV7cnjhqq0AZVnzaPMHg0qvQbRm NNFCLfnBrgbMDqglu1wsZ/5jtW5QKo+k0Wvr9kgYcAxqrpa6X27M3nBtxkkLMrds6b PaCef3JWPateWsHXz1CMzzXlDQKhKsPxjVQUsdcc= Date: Thu, 10 Nov 2022 19:00:52 +0100 From: Greg KH To: Chengming Zhou Cc: tj@kernel.org, linux-kernel@vger.kernel.org, syzbot+2fdf66e68f5f882c1074@syzkaller.appspotmail.com Subject: Re: [PATCH] fs/kernfs: Fix lockdep warning in kernfs_active() Message-ID: References: <0000000000002473fd05eca7540a@google.com> <20221109120415.55759-1-zhouchengming@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221109120415.55759-1-zhouchengming@bytedance.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 09, 2022 at 08:04:15PM +0800, Chengming Zhou wrote: > syzbot found a lockdep warning in kernfs_find_and_get_node_by_id(), > bisected to the commit c25491747b21 ("kernfs: Add KERNFS_REMOVING flags"), > which didn't hold kernfs_rwsem before call kernfs_active(kn). > > Since kernfs_find_and_get_node_by_id() doesn't have to get active count > of kn, only need to get a stable refcount of kn, so it should be enough > to just check kn has been KERNFS_ACTIVATED. > > Reported-by: syzbot+2fdf66e68f5f882c1074@syzkaller.appspotmail.com > Fixes: c25491747b21 ("kernfs: Add KERNFS_REMOVING flags") > Signed-off-by: Chengming Zhou > --- > fs/kernfs/dir.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c > index 6acd9c3d4cff..08f0f1570cd7 100644 > --- a/fs/kernfs/dir.c > +++ b/fs/kernfs/dir.c > @@ -705,7 +705,13 @@ struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root, > goto err_unlock; > } > > - if (unlikely(!kernfs_active(kn) || !atomic_inc_not_zero(&kn->count))) > + /* > + * ACTIVATED is protected with kernfs_mutex but it was clear when > + * @kn was added to idr and we just wanna see it set. No need to > + * grab kernfs_mutex. > + */ > + if (unlikely(!(kn->flags & KERNFS_ACTIVATED) || > + !atomic_inc_not_zero(&kn->count))) > goto err_unlock; > > spin_unlock(&kernfs_idr_lock); > -- > 2.37.2 > Shouldn't: https://lore.kernel.org/r/Y0SwqBsZ9BMmZv6x@slm.duckdns.org fix this instead?