Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp176974rdb; Thu, 21 Dec 2023 06:17:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVK3crFXnYrm/6gaRXhgixAbyOJQCdGtaoSE/Xq7JG23vhVIrqsa1R83+LrKLqDKcBRaZa X-Received: by 2002:a17:906:4a88:b0:a26:989b:7cdd with SMTP id x8-20020a1709064a8800b00a26989b7cddmr1358088eju.83.1703168229575; Thu, 21 Dec 2023 06:17:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703168229; cv=none; d=google.com; s=arc-20160816; b=cJeYZum6XvPEKX+kAxnFswxVRENIROj1fqaaUn//f76gJr84J0AK0qTvsDV9Q4i2w4 32mpCuS4RPcprKlBzExsAq+b4Ht6KwxbgXhx5JX9PxvoL3WTlR6ppbDxiCQj4pNXqQk2 RkAULAYTq3toblYKAhgbJLiKpdB57z+I3QvAALPvn3TBbLEzqf9Pff529qEEqmlULPuU 0tc5VSDAhtMpOSbS6XFVVzUPPvfAuW7crn5dqR8lwZnZJMiw+5ZuEb69j2nrao2hO0zE RHlfQWOhvlNnmbNEYYqFh+dmLSW/P/84pwsl8RWlaOPGnQxJOjtgje/Jr4e4I5K0TUbQ Bg+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=eIaYI0ct3kzN+uIpwX8VkuvulkFIVBzGuvKucGJ7sP4=; fh=kv6lwvgFPQvTyO5DLJ36U+RDFfFxbw4DsctUkaN8k8A=; b=UQg09UqE5CnDq1edKtuZ23i5Q4Am3zKXYJnLwLogfO/Uhg7lGu/CJcSTXV8TYC9nLv cEwHySEi0ogD8blKD0vAla1fQAGw2mVYIcu5ZMNgEekuN+utgNVUkJe5ZizIzRjzZuJT 8unZqpv0s5K4XvT+H3v0wjq5rqe1HjH4jbIu8x8n0G2arD/yzdVvE1zfJAw2B3hcj+3u OxkBxrOCaETCRMfoAxK68eh5UaEAzIByBfNlrBKlhqLyuAIUbbA98MQCxBAiODt5VdOn VkjxMFq7fyPTNXdKtZEf3X0bEINzvnyacethvz+F2dSh2y800DydCSrLTViARFe9UoqX rl1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b="uC6jk/c5"; spf=pass (google.com: domain of linux-kernel+bounces-8549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s10-20020a170906a18a00b00a2684c29489si890291ejy.526.2023.12.21.06.17.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 06:17:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b="uC6jk/c5"; spf=pass (google.com: domain of linux-kernel+bounces-8549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3E8BE1F28459 for ; Thu, 21 Dec 2023 14:07:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01019360B9; Thu, 21 Dec 2023 14:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="uC6jk/c5" X-Original-To: linux-kernel@vger.kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B332360A1 for ; Thu, 21 Dec 2023 14:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=eIaYI0ct3kzN+uIpwX8VkuvulkFIVBzGuvKucGJ7sP4=; t=1703167522; x=1704377122; b=uC6jk/c5VTe/lfpbjdwn22RBn3Gm5TRTVHsQLt05glL6bWWIcFClVPkLM/CoxhJ3tXFee0olggL mIuVKxLoFRHtO6Poxwf0nG4tJ2W73a0kl+zsAWlHnpejdZAcL7V4JA0AiS66o+ovjlMJ74PqUAk9w nGiST2/FXLC7qGLyyz0vcNWfF6I0nilGz2B4mI7GtPUMDe5zZfnyaS6brCS+LQgQF88r8WmrM8X5j NU/EV1QkApn7Y7IiGWNhsYMZaqB9GZgNsBTDpx3dq4hV1uaypZd6rjIkAGjVfa4ac4+vnY1usGmRU b7eyjjFAy/Fhlz6h6IZPDpn5JDEBIJA0FBcA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rGJfk-00000002t3A-20p8; Thu, 21 Dec 2023 15:05:12 +0100 From: Johannes Berg To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Johannes Berg , Tetsuo Handa Subject: [PATCH] debugfs: initialize cancellations earlier Date: Thu, 21 Dec 2023 15:04:45 +0100 Message-ID: <20231221150444.1e47a0377f80.If7e8ba721ba2956f12c6e8405e7d61e154aa7ae7@changeid> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg Tetsuo Handa pointed out that in the (now reverted) lockdep commit I initialized the data too late. The same is true for the cancellation data, it must be initialized before the cmpxchg(), otherwise it may be done twice and possibly even overwriting data in there already when there's a race. Fix that, which also requires destroying the mutex in case we lost the race. Fixes: 8c88a474357e ("debugfs: add API to allow debugfs operations cancellation") Reported-by: Tetsuo Handa Signed-off-by: Johannes Berg --- fs/debugfs/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 5063434be0fc..6d7c1a49581f 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -104,12 +104,14 @@ int debugfs_file_get(struct dentry *dentry) ~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT); refcount_set(&fsd->active_users, 1); init_completion(&fsd->active_users_drained); + INIT_LIST_HEAD(&fsd->cancellations); + mutex_init(&fsd->cancellations_mtx); + if (cmpxchg(&dentry->d_fsdata, d_fsd, fsd) != d_fsd) { + mutex_destroy(&fsd->cancellations_mtx); kfree(fsd); fsd = READ_ONCE(dentry->d_fsdata); } - INIT_LIST_HEAD(&fsd->cancellations); - mutex_init(&fsd->cancellations_mtx); } /* -- 2.43.0