mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ceph: fix inode and i_filelock_ref leak on file lock rollback
@ 2026-11-05  5:53 zhangdaolong
  2026-11-22 19:38 ` Alex Markuze
  0 siblings, 1 reply; 2+ messages in thread
From: zhangdaolong @ 2026-11-05  5:53 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: ceph-devel, linux-kernel, zhangdaolong

When ceph_lock() or ceph_flock() succeeds in acquiring a file lock on
the MDS via ceph_lock_message() but fails to install the lock locally in
VFS (for example when posix_lock_file() returns -EAGAIN or -EDEADLK, or
locks_lock_file_wait() is interrupted), it sends a CEPH_LOCK_UNLOCK
rollback request to the MDS reusing the same struct file_lock instance.

Because ceph_lock_message() unconditionally invokes
fl->fl_ops->fl_copy_lock(fl, NULL) for every CEPH_MDS_OP_SETFILELOCK
operation, the rollback call increments ci->i_filelock_ref a second time
and overwrites fl->fl_u.ceph.inode with a second igrab(inode) reference.
When the caller subsequently frees or releases the request file_lock,
ceph_fl_release_lock() only runs once, permanently leaking one
i_filelock_ref count and one inode reference per rollback and causing
'VFS: Busy inodes after unmount of ceph' on unmount.

Fix this by:
1. Skipping fl_copy_lock() in ceph_lock_message() when cmd is
   CEPH_LOCK_UNLOCK, since unlocking does not add a file_lock to the
   inode.
2. Guarding ceph_fl_copy_lock() against being called when
   dst->fl_u.ceph.inode is already set, ensuring a single file_lock
   never acquires multiple inode references across retries or rollbacks.

Fixes: 89aa59301013 ("ceph: keep auth cap when inode has flocks or posix locks")
Fixes: 8e1858710d9a ("ceph: avoid use-after-free in ceph_fl_release_lock()")
Link: https://tracker.ceph.com/issues/81372
Signed-off-by: zhangdaolong <dlzhangak@isoftstone.com>
---
 fs/ceph/locks.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 677221bd64e0..17b893c234d3 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -34,6 +34,10 @@ void __init ceph_flock_init(void)
 static void ceph_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
 {
 	struct inode *inode = file_inode(dst->c.flc_file);
+
+	if (dst->fl_u.ceph.inode)
+		return;
+
 	atomic_inc(&ceph_inode(inode)->i_filelock_ref);
 	dst->fl_u.ceph.inode = igrab(inode);
 }
@@ -81,7 +85,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct inode *inode,
 	u64 length = 0;
 	u64 owner;
 
-	if (operation == CEPH_MDS_OP_SETFILELOCK) {
+	if (operation == CEPH_MDS_OP_SETFILELOCK && cmd != CEPH_LOCK_UNLOCK) {
 		/*
 		 * increasing i_filelock_ref closes race window between
 		 * handling request reply and adding file_lock struct to
-- 
2.48.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ceph: fix inode and i_filelock_ref leak on file lock rollback
  2026-11-05  5:53 [PATCH] ceph: fix inode and i_filelock_ref leak on file lock rollback zhangdaolong
@ 2026-11-22 19:38 ` Alex Markuze
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Markuze @ 2026-11-22 19:38 UTC (permalink / raw)
  To: zhangdaolong; +Cc: Ilya Dryomov, Viacheslav Dubeyko, ceph-devel, linux-kernel

Hi Daolong,

NACK. The rollback leak is real, but skipping fl_copy_lock() for every
unlock is not the right fix.

try_unlock_file() removes the local lock before the MDS unlock is sent.
The temporary i_filelock_ref keeps the auth cap from being trimmed during
that request. Without it, another cap can cover the bits the request is
using, and the auth cap can be released while the unlock is still in
flight. A second lock from the same client can then be granted without a
new auth cap. Processing that cap release removes every advisory lock the
client holds on the inode, including the new one. The new lock remains
installed locally, so another client can be granted a conflicting lock.

The guard in ceph_fl_copy_lock() already stops a second reference when the
request lock is attached. That covers the rollback. Please keep the
reference for an ordinary unlock.

Thanks,
Alex


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-22 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05  5:53 [PATCH] ceph: fix inode and i_filelock_ref leak on file lock rollback zhangdaolong
2026-11-22 19:38 ` Alex Markuze

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®