From bcf620a59e1d7ea9cc9aa035180cd89588532b3c Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 27 Jan 2025 15:22:26 +0100 Subject: [PATCH] smbd: call locking_close_file() while still holding a glock on the locking.tdb record BUG: https://bugzilla.samba.org/show_bug.cgi?id=15767 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (cherry picked from commit 4d680b6c17ee7674b9686aec2b69038f89e1989a) --- source3/smbd/close.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/source3/smbd/close.c b/source3/smbd/close.c index c5b6c622d70..cf0e0e6419d 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -321,6 +321,17 @@ static void close_share_mode_lock_prepare(struct share_mode_lock *lck, */ *keep_locked = false; + if (fsp->current_lock_count > 0) { + /* + * Remove the byte-range locks under the glock + */ + *keep_locked = true; + } + + if (fh_get_refcount(fsp->fh) > 1) { + return; + } + if (fsp->oplock_type != NO_OPLOCK) { ok = remove_share_oplock(lck, fsp); if (!ok) { @@ -474,6 +485,12 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp, return status; } + locking_close_file(fsp, close_type); + + if (fh_get_refcount(fsp->fh) > 1) { + goto done; + } + /* Remove the oplock before potentially deleting the file. */ if (fsp->oplock_type != NO_OPLOCK) { release_file_oplock(fsp); @@ -939,13 +956,8 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, the same handle we only have one share mode. Ensure we only remove the share mode on the last close. */ - if (fh_get_refcount(fsp->fh) == 1) { - /* Should we return on error here... ? */ - tmp = close_remove_share_mode(fsp, close_type); - status = ntstatus_keeperror(status, tmp); - } - - locking_close_file(fsp, close_type); + tmp = close_remove_share_mode(fsp, close_type); + status = ntstatus_keeperror(status, tmp); /* * Ensure pending modtime is set before closing underlying fd. -- 2.47.2