mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: aahringo@redhat.com, teigland@redhat.com
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH] dlm: validate lockspace under ls_lock in dlm_release_lockspace()
Date: Thu, 26 Nov 2026 14:08:12 +0800	[thread overview]
Message-ID: <20261126060812.2028-1-luob87709@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-26  6:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126060812.2028-1-luob87709@gmail.com \
    --to=luob87709@gmail.com \
    --cc=aahringo@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=teigland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®