Re: [PATCH v3 3/9] ext4: check return value of ext4_get_block() in ext4_load_tail_bh()

From: Jan Kara

Date: Thu Jul 09 2026 - 09:32:00 EST


On Wed 08-07-26 14:20:43, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@xxxxxxxxxx>
>
> ext4_load_tail_bh() ignores the return value of ext4_get_block(), so an
> I/O or allocation failure is silently discarded. buffer_mapped(bh) stays
> false and the function returns NULL, which callers such as
> ext4_block_do_zero_range() treat as "nothing to do" and return success.
> This can mask real failures during zero-range, truncate, or punch-hole
> operations, potentially exposing stale data if the block was not
> actually a hole and needed zeroing. So propagate the error to the
> callers.
>
> Signed-off-by: Zhang Yi <yi.zhang@xxxxxxxxxx>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza

> ---
> fs/ext4/inode.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index a3f7c71b701d..ba4fc3c93bb6 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4064,7 +4064,9 @@ static struct buffer_head *ext4_load_tail_bh(struct inode *inode, loff_t from)
> }
> if (!buffer_mapped(bh)) {
> BUFFER_TRACE(bh, "unmapped");
> - ext4_get_block(inode, iblock, bh, 0);
> + err = ext4_get_block(inode, iblock, bh, 0);
> + if (err < 0)
> + goto unlock;
> /* unmapped? It's a hole - nothing to do */
> if (!buffer_mapped(bh)) {
> BUFFER_TRACE(bh, "still unmapped");
> --
> 2.52.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR