[PATCH] ufs: Handle NULL return from ufs_get_locked_folio()

From: Ingyu Jang

Date: Thu May 14 2026 - 15:35:16 EST


ufs_get_locked_folio() may return either an error pointer (when
read_mapping_folio() fails) or NULL (when a concurrent truncate has
detached the folio from its mapping). The current IS_ERR() check in
ufs_alloc_lastblock() only handles the error-pointer case; a NULL
return falls through to folio_buffers(folio), causing a NULL pointer
dereference under the truncate race.

Use IS_ERR_OR_NULL() to cover both failure modes.

Signed-off-by: Ingyu Jang <ingyujang25@xxxxxxxxxxx>
---
fs/ufs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 440d014cc5ed5..989ff3d3ad179 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -1051,7 +1051,7 @@ static int ufs_alloc_lastblock(struct inode *inode, loff_t size)

folio = ufs_get_locked_folio(mapping, lastfrag >>
(PAGE_SHIFT - inode->i_blkbits));
- if (IS_ERR(folio)) {
+ if (IS_ERR_OR_NULL(folio)) {
err = -EIO;
goto out;
}
--
2.34.1