]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb3: fix lock breakage for cached writes
authorSteve French <stfrench@microsoft.com>
Thu, 15 Aug 2024 19:03:43 +0000 (14:03 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Aug 2024 15:35:37 +0000 (17:35 +0200)
commit 836bb3268db405cf9021496ac4dbc26d3e4758fe upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/file.c

index 04ec1b9737a897314800ff95308e3b52f461f3bb..2e3c4d0277dbbc22e2a643ef12d01baa785bee54 100644 (file)
@@ -2719,6 +2719,7 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
        struct inode *inode = file->f_mapping->host;
        struct cifsInodeInfo *cinode = CIFS_I(inode);
        struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        ssize_t rc;
 
        rc = netfs_start_io_write(inode);
@@ -2735,12 +2736,16 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
        if (rc <= 0)
                goto out;
 
-       if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from),
+       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) &&
+           (cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from),
                                     server->vals->exclusive_lock_type, 0,
-                                    NULL, CIFS_WRITE_OP))
-               rc = netfs_buffered_write_iter_locked(iocb, from, NULL);
-       else
+                                    NULL, CIFS_WRITE_OP))) {
                rc = -EACCES;
+               goto out;
+       }
+
+       rc = netfs_buffered_write_iter_locked(iocb, from, NULL);
+
 out:
        up_read(&cinode->lock_sem);
        netfs_end_io_write(inode);