smb3: fix lock breakage for cached writes
authorSteve French <stfrench@microsoft.com>
Thu, 15 Aug 2024 19:03:43 +0000 (14:03 -0500)
committerSteve French <stfrench@microsoft.com>
Thu, 15 Aug 2024 21:04:47 +0000 (16:04 -0500)
commit836bb3268db405cf9021496ac4dbc26d3e4758fe
treedd840c1adb699998087426c07fe63389ec7b1a38
parent74c2ab6d653b4c2354df65a7f7f2df1925a40a51
smb3: fix lock breakage for cached writes

Mandatory locking is enforced for cached writes, which violates
default posix semantics, and also it is enforced inconsistently.
This apparently breaks recent versions of libreoffice, but can
also be demonstrated by opening a file twice from the same
client, locking it from handle one and writing to it from
handle two (which fails, returning EACCES).

Since there was already a mount option "forcemandatorylock"
(which defaults to off), with this change only when the user
intentionally specifies "forcemandatorylock" on mount will we
break posix semantics on write to a locked range (ie we will
only fail the write in this case, if the user mounts with
"forcemandatorylock").

Fixes: 85160e03a79e ("CIFS: Implement caching mechanism for mandatory brlocks")
Cc: stable@vger.kernel.org
Cc: Pavel Shilovsky <piastryyy@gmail.com>
Reported-by: abartlet@samba.org
Reported-by: Kevin Ottens <kevin.ottens@enioka.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/file.c