From: Ralph Boehme Date: Mon, 27 Jan 2025 14:22:26 +0000 (+0100) Subject: smbd: call locking_close_file() while still holding a glock on the locking.tdb record X-Git-Tag: samba-4.21.6~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=956ddc96f44da982e1804c229534b28e621dd916;p=thirdparty%2Fsamba.git 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) --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 1b027a319a4..964c3530e8d 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -303,6 +303,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) { @@ -453,6 +464,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); @@ -890,13 +907,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.