]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/cifs/file.c
CIFS: fix POSIX lock leak and invalid ptr deref
[mirror_ubuntu-bionic-kernel.git] / fs / cifs / file.c
index 780cbdef3d814489c97ad4da84db8f6ce417e3e6..87d59df05509c88d3f9c1f666696ea442e65fbd2 100644 (file)
@@ -1650,8 +1650,20 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
                rc = server->ops->mand_unlock_range(cfile, flock, xid);
 
 out:
-       if (flock->fl_flags & FL_POSIX && !rc)
+       if (flock->fl_flags & FL_POSIX) {
+               /*
+                * If this is a request to remove all locks because we
+                * are closing the file, it doesn't matter if the
+                * unlocking failed as both cifs.ko and the SMB server
+                * remove the lock on file close
+                */
+               if (rc) {
+                       cifs_dbg(VFS, "%s failed rc=%d\n", __func__, rc);
+                       if (!(flock->fl_flags & FL_CLOSE))
+                               return rc;
+               }
                rc = locks_lock_file_wait(file, flock);
+       }
        return rc;
 }