From: Jeremy Allison Date: Wed, 10 Aug 2016 21:42:07 +0000 (-0700) Subject: s3: oplock: Fix race condition when closing an oplocked file. X-Git-Tag: samba-4.3.12~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08a3ca1f974cb684aada6712b0ce6d406a98dd98;p=thirdparty%2Fsamba.git s3: oplock: Fix race condition when closing an oplocked file. We must send the 'oplock released' message whilst the lock is held in the close path. Otherwise the messaged smbd can race with the share mode delete. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12139 Signed-off-by: Jeremy Allison Reviewed-by: Volker Lendecke (cherry picked from commit df83b17c60a08a27a7ddd1d88dc125e15b3ee06d) --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 66840aed5f3..6a87ccc8484 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -279,6 +279,11 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp, return NT_STATUS_INVALID_PARAMETER; } + /* Remove the oplock before potentially deleting the file. */ + if(fsp->oplock_type) { + remove_oplock_under_lock(fsp, lck); + } + if (fsp->write_time_forced) { DEBUG(10,("close_remove_share_mode: write time forced " "for file %s\n", @@ -743,11 +748,6 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp, return NT_STATUS_OK; } - /* Remove the oplock before potentially deleting the file. */ - if(fsp->oplock_type) { - remove_oplock(fsp); - } - /* If this is an old DOS or FCB open and we have multiple opens on the same handle we only have one share mode. Ensure we only remove the share mode on the last close. */