v2 [PATCH] ocfs2: fix panic in failed foilio allocation
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
In the page to order 0 folio conversion series, the commit 7e119cff9d0a, "ocfs2: convert w_pages to w_folios" and commit 9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves -ENOMEM in the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the -ENOMEM will result in a panic. Fix by NULLing the error folio entry.
---
v2: sorry, ocfs2_grab_folios() needs the same change.
the other callers do not need the change.
--- fs/ocfs2/alloc.c | 1 + fs/ocfs2/aops.c | 1 + 2 files changed, 2 insertions(+)
fs/ocfs2/alloc.c +1 -0
@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end,if (IS_ERR (folios[numfolios])) { ret =PTR_ERR (folios[numfolios]);mlog_errno (ret); + folios[numfolios] =NULL ; goto out; } diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 40b6bce12951..89aadc6cdd87 100644
fs/ocfs2/aops.c +1 -0
@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(struct address_space *mapping,if (IS_ERR (wc->w_folios[i])) { ret =PTR_ERR (wc->w_folios[i]);mlog_errno (ret); + wc->w_folios[i] =NULL ; goto out; } }
Signature · 1 line
2.39.5 (Apple Git-154)
Matthew Wilcox
Reviewed-byQuoted 9 lines · Mark Tinguely
In the page to order 0 folio conversion series, the commit
7e119cff9d0a, "ocfs2: convertw_pagestow_folios" and commit9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves-ENOMEMin the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the-ENOMEMwill result in a panic. Fix by NULLing the error folio entry.
Quoted 7 lines
Signed-off-by Mark Tinguely <[email protected]>Cc Changwei Ge <[email protected]>Cc Joel Becker <[email protected]>Cc Junxiao Bi <[email protected]>Cc Mark Fasheh <[email protected]>Cc Matthew Wilcox <[email protected]>
Quoted 10 lines · Mark Tinguely
In the page to order 0 folio conversion series, the commit
7e119cff9d0a, "ocfs2: convertw_pagestow_folios" and commit9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves-ENOMEMin the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the-ENOMEMwill result in a panic. Fix by NULLing the error folio entry.Signed-off-by Mark Tinguely <[email protected]>
Quoted 37 lines
Cc Changwei Ge <[email protected]>Cc Joel Becker <[email protected]>Cc Junxiao Bi <[email protected]>Cc Mark Fasheh <[email protected]>Cc Matthew Wilcox <[email protected]>---
v2: sorry,ocfs2_grab_folios()needs the same change. the other callers do not need the change.
---
fs/ocfs2/alloc.c | 1 +
fs/ocfs2/aops.c | 1 +2 files changed, 2 insertions(+)fs/ocfs2/alloc.c +1
-0@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end, if (IS_ERR(folios[numfolios])) { ret = PTR_ERR(folios[numfolios]); mlog_errno(ret); + folios[numfolios] = NULL; goto out; }diff --git
a/fs/ocfs2/aops.cb/fs/ocfs2/aops.c
index40b6bce12951..89aadc6cdd87100644fs/ocfs2/aops.c +1
-0@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(struct address_space *mapping, if (IS_ERR(wc->w_folios[i])) { ret = PTR_ERR(wc->w_folios[i]); mlog_errno(ret); + wc->w_folios[i] = NULL; goto out; } }
Quoted 48 lines · Mark Tinguely
In the page to order 0 folio conversion series, the commit
7e119cff9d0a, "ocfs2: convertw_pagestow_folios" and commit9a5e08652dc4b, "ocfs2: use an array of folios instead of an array of pages", saves-ENOMEMin the folio array upon allocation failure and calls the folio array free code. The folio array free code expects either valid folio pointers or NULL. Finding the-ENOMEMwill result in a panic. Fix by NULLing the error folio entry.Signed-off-by Mark Tinguely <[email protected]>Cc Changwei Ge <[email protected]>Cc Joel Becker <[email protected]>Cc Junxiao Bi <[email protected]>Cc Mark Fasheh <[email protected]>Cc Matthew Wilcox <[email protected]>---
v2: sorry,ocfs2_grab_folios()needs the same change.
the other callers do not need the change.--- fs/ocfs2/alloc.c | 1 + fs/ocfs2/aops.c | 1 + 2 files changed, 2 insertions(+)fs/ocfs2/alloc.c +1
-0@@ -6918,6 +6918,7 @@ static int ocfs2_grab_folios(struct inode *inode, loff_t start, loff_t end, if (IS_ERR(folios[numfolios])) { ret = PTR_ERR(folios[numfolios]); mlog_errno(ret); + folios[numfolios] = NULL; goto out; }diff --git
a/fs/ocfs2/aops.cb/fs/ocfs2/aops.c
index40b6bce12951..89aadc6cdd87100644fs/ocfs2/aops.c +1
-0@@ -1071,6 +1071,7 @@ static int ocfs2_grab_folios_for_write(structaddress_space *mapping, if (IS_ERR(wc->w_folios[i])) { ret = PTR_ERR(wc->w_folios[i]); mlog_errno(ret); + wc->w_folios[i] = NULL; goto out; }
Quoted 1 line
}
It appears the Linux commit:
commit 31d4cd4eb2f8d9b87ebfa6a5e443a59e3b3d7b8c
Author: Mark Tinguely <[email protected]> Date: Fri Apr 11 11:31:24 2025 -0500
ocfs2: fix panic in failed foilio allocation
made only the alloc.c change.