1 From 31fad7d41e73731f05b8053d17078638cf850fa6 Mon Sep 17 00:00:00 2001
2 From: Roberto Bergantinos Corpas <rbergant@redhat.com>
3 Date: Tue, 28 May 2019 09:38:14 +0200
4 Subject: CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM
6 From: Roberto Bergantinos Corpas <rbergant@redhat.com>
8 commit 31fad7d41e73731f05b8053d17078638cf850fa6 upstream.
10 In cifs_read_allocate_pages, in case of ENOMEM, we go through
11 whole rdata->pages array but we have failed the allocation before
12 nr_pages, therefore we may end up calling put_page with NULL
15 Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
16 Acked-by: Pavel Shilovsky <pshilov@microsoft.com>
17 Signed-off-by: Steve French <stfrench@microsoft.com>
18 CC: Stable <stable@vger.kernel.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 fs/cifs/file.c | 4 +++-
23 1 file changed, 3 insertions(+), 1 deletion(-)
27 @@ -2829,7 +2829,9 @@ cifs_read_allocate_pages(struct cifs_rea
31 - for (i = 0; i < nr_pages; i++) {
32 + unsigned int nr_page_failed = i;
34 + for (i = 0; i < nr_page_failed; i++) {
35 put_page(rdata->pages[i]);
36 rdata->pages[i] = NULL;