* [PATCH] CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM
@ 2019-05-28 7:38 Roberto Bergantinos Corpas
0 siblings, 0 replies; only message in thread
From: Roberto Bergantinos Corpas @ 2019-05-28 7:38 UTC (permalink / raw)
To: sfrench; +Cc: linux-cifs
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>
---
fs/cifs/file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index ce9a5be11df5..06e27ac6d82c 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -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;
}
--
2.14.5
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-28 7:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-28 7:38 [PATCH] CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM Roberto Bergantinos Corpas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox