]> asedeno.scripts.mit.edu Git - linux.git/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)
committerSteve French <stfrench@microsoft.com>
Wed, 29 May 2019 19:02:11 +0000 (14:02 -0500)
 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>
fs/cifs/file.c

index ce9a5be11df5a570ece28991097683dcfd923e43..06e27ac6d82c95f85e2b69b196502f0ddaed42e0 100644 (file)
@@ -3216,7 +3216,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;
                }