Skip to contentSkip to conversation

filemap: fix error pointer dereference in filemap_fault()

PATCH In review Ma Ke 2 participants 2 messages Jul 16, 2024

Subsystems (3)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 filemap: fix error pointer dereference in filemap_fault()

This code calls folio_put() on an error pointer which will lead to a crash. Check for both error pointers and NULL pointers before calling folio_put().

Fixes 38a55db9877c ("filemap: Handle error return from __filemap_get_folio()")
---
 mm/filemap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
index 657bcd887fdb..cd26617d8987 100644
@@ -3420,7 +3420,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 	 * re-find the vma and come back and find our hopefully still populated
 	 * page.
 	 */
-	if (!IS_ERR(folio))
+	if (!IS_ERR_OR_NULL(folio))
 		folio_put(folio);
 	if (mapping_locked)
 		filemap_invalidate_unlock_shared(mapping);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 3 lines · Ma Ke

This code calls folio_put() on an error pointer which will lead to a crash. Check for both error pointers and NULL pointers before calling folio_put().

Have you observed this, or do you just think this can happen?

If the former, please share the crash.
If the latter, please document the path which can lead to this happening.

Quoted 22 lines
Fixes 38a55db9877c ("filemap: Handle error return from __filemap_get_folio()")
---
 mm/filemap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
index 657bcd887fdb..cd26617d8987 100644
@@ -3420,7 +3420,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 	 * re-find the vma and come back and find our hopefully still populated
 	 * page.
 	 */
-	if (!IS_ERR(folio))
+	if (!IS_ERR_OR_NULL(folio))
 		folio_put(folio);
 	if (mapping_locked)
 		filemap_invalidate_unlock_shared(mapping);
Signature · 1 line
2.25.1