Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1092133rwb; Thu, 10 Nov 2022 11:04:12 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Vd1TtwT95ygE+SmLk3dUce3adRRIGU50VyKM8fsPxUgFhfV2AD3yCGHK4XakNal/Ac6p3 X-Received: by 2002:a17:906:c55:b0:7a5:f8a5:6f81 with SMTP id t21-20020a1709060c5500b007a5f8a56f81mr3363560ejf.570.1668107051761; Thu, 10 Nov 2022 11:04:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668107051; cv=none; d=google.com; s=arc-20160816; b=zDkuHeVZn7mEYNzQQ/pQm0AYiopdgzVeuRPTaF1F+k2sSj0l/S9xUT9AU6Kerlei5h BXGgYzyODwhAzN09sID6Lt4LDpvvZqapyPZPIUtPUSaJwRXkikmVslpeOJQ+hF7n/X7J 1YIRYSKNZQsT6m3Viq+hkeDVi6DE/tS3MuZwrZU6ZBgZ1OoJ7Nd6+EUIu50k7IKwsu+k vA3UDRAY2mAn+eAXM0+aqo67YRi8bnIFt9mEOQoKsv0lZmd4MCy/VAUlnH8xulO2X+Zd aAxPpVk7FdlFExG/slw6W/NdCD/6/89qZgm6pdmtBi8gxf6nUbSllAOv/IVKPZnRMG6C pZlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BVzGoMA6MhabVS+dE2u6WFSJEVxwBzidXLwuAfEsj4Q=; b=FwXuc/gUMzN5ZesPIbIpgIYBWACOOUx254a0pPGffldgPVg1JoiH/cwXt1gLshjFPN sC4QPgCvJlWIzBPbwSEAnXgbrEdmu9o6SaSSL5hZhz0f3sw46bLSSRMkhlS+2QiB68E4 8yKb1MhSyJOf/2/DHZM2eo8xWn7NqdhZA5/CsXUoLouRJ7r7fh7ps/CqKbI3woEvJyfB G2CPNJ3SYsEGqL7AbHrf3oqShuWhTKMuzeOyBS+AKN7tn0ptLdQJnfkhs70jYSvS/upo 9GSAFtD/EOcCluUv+XHdBkaOsSRHYWbDBlgUyk+gWBYVdQCJN2m5Ykjwvf9sXeaot98U YEgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0n4nGSo/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020a50aace000000b0045ce40540ebsi296381edc.269.2022.11.10.11.03.46; Thu, 10 Nov 2022 11:04:11 -0800 (PST) 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="0n4nGSo/"; 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 S231735AbiKJSBq (ORCPT + 92 others); Thu, 10 Nov 2022 13:01:46 -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> X-Spam-Status: No, score=-7.1 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 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?