AS_RELEASE_ALWAYS tells the memory management code to always call ->release_folio() when releasing a folio, even if it has no private data. Setting this flag without providing release_folio callback leads to try_to_free_buffers() being called on folios without buffer_heads, causing a NULL pointer dereference. Add a VM_WARN_ONCE() alert to mapping_set_release_always() to catch this programming error early and help prevent similar bugs in other filesystems. Suggested-by: Jan Kara Signed-off-by: Deepakkumar Karn --- include/linux/pagemap.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 31a848485ad9..cc352e87ac2d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -296,6 +296,9 @@ static inline bool mapping_release_always(const struct address_space *mapping) static inline void mapping_set_release_always(struct address_space *mapping) { + /* Alert while setting the flag with no release_folio callback */ + VM_WARN_ONCE(!mapping->a_ops->release_folio, + "Setting AS_RELEASE_ALWAYS with no release_folio"); set_bit(AS_RELEASE_ALWAYS, &mapping->flags); } -- 2.52.0