]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cifs: fix leaked reference on requeued write
authorAdam McCoy <adam@forsedomani.com>
Wed, 13 May 2020 11:53:30 +0000 (11:53 +0000)
committerSteve French <stfrench@microsoft.com>
Thu, 14 May 2020 22:47:01 +0000 (17:47 -0500)
Failed async writes that are requeued may not clean up a refcount
on the file, which can result in a leaked open. This scenario arises
very reliably when using persistent handles and a reconnect occurs
while writing.

cifs_writev_requeue only releases the reference if the write fails
(rc != 0). The server->ops->async_writev operation will take its own
reference, so the initial reference can always be released.

Signed-off-by: Adam McCoy <adam@forsedomani.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
CC: Stable <stable@vger.kernel.org>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
fs/cifs/cifssmb.c

index 182b864b3075bdd1f0b079f9047c8a0f4a5d796d..5014a82391ff92987517a43cc7188cba7670bd32 100644 (file)
@@ -2152,8 +2152,8 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
                        }
                }
 
+               kref_put(&wdata2->refcount, cifs_writedata_release);
                if (rc) {
-                       kref_put(&wdata2->refcount, cifs_writedata_release);
                        if (is_retryable_error(rc))
                                continue;
                        i += nr_pages;