]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.181/cifs-cifs_read_allocate_pages-don-t-iterate-through-whole-page-array-on-enomem.patch
Linux 4.4.181
[thirdparty/kernel/stable-queue.git] / releases / 4.4.181 / cifs-cifs_read_allocate_pages-don-t-iterate-through-whole-page-array-on-enomem.patch
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
5
6 From: Roberto Bergantinos Corpas <rbergant@redhat.com>
7
8 commit 31fad7d41e73731f05b8053d17078638cf850fa6 upstream.
9
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
13 pointer, causing oops
14
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>
20
21 ---
22 fs/cifs/file.c | 4 +++-
23 1 file changed, 3 insertions(+), 1 deletion(-)
24
25 --- a/fs/cifs/file.c
26 +++ b/fs/cifs/file.c
27 @@ -2829,7 +2829,9 @@ cifs_read_allocate_pages(struct cifs_rea
28 }
29
30 if (rc) {
31 - for (i = 0; i < nr_pages; i++) {
32 + unsigned int nr_page_failed = i;
33 +
34 + for (i = 0; i < nr_page_failed; i++) {
35 put_page(rdata->pages[i]);
36 rdata->pages[i] = NULL;
37 }