Message ID | 20221109120415.55759-1-zhouchengming@bytedance.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp299554wru; Wed, 9 Nov 2022 04:17:31 -0800 (PST) X-Google-Smtp-Source: AMsMyM5cSaSUU/MM/EeuTrov+1bjIJRP2Q50QIoRmDqpbKFRfSa4joP+cF9cKlNqrBfYs037B43l X-Received: by 2002:a17:90a:2f03:b0:213:c57c:f062 with SMTP id s3-20020a17090a2f0300b00213c57cf062mr56463691pjd.35.1667996251479; Wed, 09 Nov 2022 04:17:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667996251; cv=none; d=google.com; s=arc-20160816; b=dOG+zBzi+bXny8Yf+AAfhVxC4JRQflPDxlQp3vztPwLrfNu3pFmUCsSx6+47F5Z6VD o7sFp08Dhk1hksoq+I+tdLqLfQ4lcLtpdQ610dlLnJ/r0A/M48OeINvzNCf0ZPsvkGYo k62vjplMVCZFEP57G/lCvOf7h9yk759VQXLKtabdqGBMcCVjghiBpUIuWpXe8cE8dRE0 iMI7C4VQ0PNzObBfMdBtsTiUbhTDxkZm5tYMEgOQk6imJHcR286n9roFwlTHXEb/TN8d qrJea086deacOOy1fyEJlQezBC3xtBghNMAlnCIG+9U/xWrDkrB5loWoCaRfAsVZ1F0I B1eg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P0s3cxJ3sHKa2IH5jImaelb3lptAzKadDfKWm7RrmSM=; b=HJKHVBZcy/e3+drwOtvTADTN6UrxtgGbEcMGto9sfWf8F43hrkBdF/ivA1t0JTUTZO iYxni61aZBRoaFKtHgB1ue/HFOWboXLGbqH0qMBIxVgpmJJ609JXpSl1nIPp78jVQc8b fsGumzO+SVnvQVjcAeUy3n27+zkGxNAilMYWP1Q+OOggk7584Sj1zTEcz6jTNsbB6iH8 QsZ1NKZL8v1RZM0952eRrqrjBquelpnYiaW+HtoGhF9Whtd1eqkxsn8Pe5AGUGlwq6zl EozSva4eEeZnGcVlAt9J5PLx17KU2OTAyTM2DeKHUL4cxwK4NUdMb+gXwI/ANRlP/evp PwcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=0u+Y1bvr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw5-20020a170903044500b001865c1ecf30si16193678plb.176.2022.11.09.04.17.16; Wed, 09 Nov 2022 04:17:31 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=0u+Y1bvr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbiKIMEu (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Wed, 9 Nov 2022 07:04:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiKIMEt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 9 Nov 2022 07:04:49 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB1B82A726 for <linux-kernel@vger.kernel.org>; Wed, 9 Nov 2022 04:04:47 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id k5so16508924pjo.5 for <linux-kernel@vger.kernel.org>; Wed, 09 Nov 2022 04:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P0s3cxJ3sHKa2IH5jImaelb3lptAzKadDfKWm7RrmSM=; b=0u+Y1bvrB+uIJ9r45t2leywA/j6CnxdI1J/xGQRyBrlkq3/VCcnwFR/8f2ibOZadFm 5uM539JlnXwUbiluDGLqvTSpy/ST1xSTyMbQ7so++YUpSb4TUsnrd9eWceowvzcgxx1Z htGJesNlZHDHg9hTP0Hf4HnvT3z/vyJpnTMMkn9NcwUIYqzIfTZMqjFtt2Zd9Mdvr4Y3 wmB3mRqs36bIrzRAt3Wwbym8nXv0ceyK5M9Wp/qqWU1bJZGRoj254ueThRqnkHSxikUL Io0sDALIzRZEW8gjrD4L+cO88bu8kf5P0M3QGnGxvRnCcDd33aA1jqW80vrPBDwKdo7o SjFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P0s3cxJ3sHKa2IH5jImaelb3lptAzKadDfKWm7RrmSM=; b=Bj3cG8iNxM9lVkrinD8NeXBj3Csvt+GcFNSW7o8OSI2V6k+Mh1crtFX7/yUnY7Jbrc +/2hAGP/vqwrQOnTgnoO63GZchfluVXB/G99BpFIzW5E+6wAzTi4Wjx/v/lTE1qvuO8D f0dPwKr+NiEQFY73a1ScZr29swXvdlCDi7Fqc3YFVYKdzFlsEVxxt7SP//KRrADD0ki/ vBsiOJOxWablKyO/1xfnLFG0V+ANV6TGBDQdtQjWklrJFZY87vx+fm6KV/JJIuXUrwVL x8MqXAsgdp9LxrKNMyky/GWnN6/J2L7DJM8/1maeDQYbYO75l6cQLGLQkZWvOXiF5ovf p0Nw== X-Gm-Message-State: ACrzQf36NicqweB/lfgWuOKT4EmNNOs0i7gA8VFr/oseDpGlfILrQB1P mIejrJPae9/glxxx7X+QF+53QQ== X-Received: by 2002:a17:903:264b:b0:186:af7a:391d with SMTP id je11-20020a170903264b00b00186af7a391dmr60835852plb.19.1667995487443; Wed, 09 Nov 2022 04:04:47 -0800 (PST) Received: from C02CV1DAMD6P.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id c195-20020a621ccc000000b00550724f8ea0sm8064581pfc.128.2022.11.09.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 04:04:46 -0800 (PST) From: Chengming Zhou <zhouchengming@bytedance.com> To: gregkh@linuxfoundation.org, tj@kernel.org Cc: linux-kernel@vger.kernel.org, Chengming Zhou <zhouchengming@bytedance.com>, syzbot+2fdf66e68f5f882c1074@syzkaller.appspotmail.com Subject: [PATCH] fs/kernfs: Fix lockdep warning in kernfs_active() Date: Wed, 9 Nov 2022 20:04:15 +0800 Message-Id: <20221109120415.55759-1-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <0000000000002473fd05eca7540a@google.com> References: <0000000000002473fd05eca7540a@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749020837451731455?= X-GMAIL-MSGID: =?utf-8?q?1749020837451731455?= |
Series |
fs/kernfs: Fix lockdep warning in kernfs_active()
|
|
Commit Message
Chengming Zhou
Nov. 9, 2022, 12:04 p.m. UTC
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 <zhouchengming@bytedance.com>
---
fs/kernfs/dir.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
Comments
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 <zhouchengming@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> Thanks.
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 <zhouchengming@bytedance.com> > --- > 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?
On Thu, Nov 10, 2022 at 07:00:52PM +0100, Greg KH wrote: > Shouldn't: > https://lore.kernel.org/r/Y0SwqBsZ9BMmZv6x@slm.duckdns.org fix this > instead? The difference is around whether the id based lookup can see hidden files or not. But yeah, it makes more sense to hide it. Thanks.
On Thu, Nov 10, 2022 at 08:11:34AM -1000, Tejun Heo wrote: > On Thu, Nov 10, 2022 at 07:00:52PM +0100, Greg KH wrote: > > Shouldn't: > > https://lore.kernel.org/r/Y0SwqBsZ9BMmZv6x@slm.duckdns.org fix this > > instead? > > The difference is around whether the id based lookup can see hidden files or > not. But yeah, it makes more sense to hide it. So your patch should not have been applied to my tree? And I should take this one instead? confused, greg k-h
On Thu, Nov 10, 2022 at 07:20:55PM +0100, Greg KH wrote: > On Thu, Nov 10, 2022 at 08:11:34AM -1000, Tejun Heo wrote: > > On Thu, Nov 10, 2022 at 07:00:52PM +0100, Greg KH wrote: > > > Shouldn't: > > > https://lore.kernel.org/r/Y0SwqBsZ9BMmZv6x@slm.duckdns.org fix this > > > instead? > > > > The difference is around whether the id based lookup can see hidden files or > > not. But yeah, it makes more sense to hide it. > > So your patch should not have been applied to my tree? And I should > take this one instead? Oh, sorry. The patch you took is the better one and I was confused when I was looking at this patch. No action necessary. It was just me being confused. Thanks.
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 <zhouchengming@bytedance.com> > --- > 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 > Is this still needed in 6.1-rc6? thanks, greg k-h
On Wed, Nov 23, 2022 at 07:30:01PM +0100, Greg KH wrote:
> Is this still needed in 6.1-rc6?
1edfe4ea16ca ("kernfs: Fix spurious lockdep warning in
kernfs_find_and_get_node_by_id()") already fixed the issue. So, not needed.
Thanks.
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);