]> git.itanic.dy.fi Git - linux-stable/commitdiff
CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM
authorRoberto Bergantinos Corpas <rbergant@redhat.com>
Tue, 28 May 2019 07:38:14 +0000 (09:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 9 Jun 2019 07:16:16 +0000 (09:16 +0200)
commit 31fad7d41e73731f05b8053d17078638cf850fa6 upstream.

 In cifs_read_allocate_pages, in case of ENOMEM, we go through
whole rdata->pages array but we have failed the allocation before
nr_pages, therefore we may end up calling put_page with NULL
pointer, causing oops

Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
Acked-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
CC: Stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/cifs/file.c

index 7037a137fa5330c807da19a91acd054d76ad031a..9a1db37b303af611190bfe59d1b86daab105fcca 100644 (file)
@@ -3221,7 +3221,9 @@ cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages)
        }
 
        if (rc) {
-               for (i = 0; i < nr_pages; i++) {
+               unsigned int nr_page_failed = i;
+
+               for (i = 0; i < nr_page_failed; i++) {
                        put_page(rdata->pages[i]);
                        rdata->pages[i] = NULL;
                }