mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dlm: validate lockspace under ls_lock in dlm_release_lockspace()
@ 2026-11-26  6:08 Bin Luo (University of Electronic Science and Technology of China)
  0 siblings, 0 replies; only message in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-26  6:08 UTC (permalink / raw)
  To: aahringo, teigland; +Cc: gfs2, linux-kernel

dlm_release_lockspace() currently calls dlm_find_lockspace_local(),
which dereferences the raw lockspace pointer to increment ls_count, and
immediately calls dlm_put_lockspace() before acquiring ls_lock.

When two callers concurrently release the same lockspace (for example
via concurrent DLM_USER_REMOVE_LOCKSPACE requests through
device_remove_lockspace(), which also drops its lookup reference before
calling dlm_release_lockspace()), the first caller can enter
release_lockspace(), remove the lockspace from lslist, and queue
ls_free_work to free ls before the second caller dereferences ls in
dlm_find_lockspace_local() or release_lockspace().

Since lockspaces are only added to and removed from lslist while holding
ls_lock, move the lockspace lookup inside ls_lock and verify that
lockspace is still present on lslist under lslist_lock before calling
release_lockspace(). If it has already been removed, return -EINVAL
without dereferencing the pointer.

Fixes: e7fd41792fc0 ("[DLM] The core of the DLM for GFS2/CLVM")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN
(fs/dlm/lockspace.o); not runtime-tested on a live DLM cluster.

 fs/dlm/lockspace.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index a9c98b4..37ccb96 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -800,12 +800,18 @@ int dlm_release_lockspace(void *lockspace, unsigned int release_option)
 	if (release_option > __DLM_RELEASE_MAX)
 		return -EINVAL;
 
-	ls = dlm_find_lockspace_local(lockspace);
-	if (!ls)
-		return -EINVAL;
-	dlm_put_lockspace(ls);
-
 	mutex_lock(&ls_lock);
+	spin_lock_bh(&lslist_lock);
+	list_for_each_entry(ls, &lslist, ls_list) {
+		if (ls == lockspace)
+			goto found;
+	}
+	spin_unlock_bh(&lslist_lock);
+	mutex_unlock(&ls_lock);
+	return -EINVAL;
+
+found:
+	spin_unlock_bh(&lslist_lock);
 	error = release_lockspace(ls, release_option);
 	if (!error)
 		ls_count--;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26  6:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  6:08 [PATCH] dlm: validate lockspace under ls_lock in dlm_release_lockspace() Bin Luo (University of Electronic Science and Technology of China)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®