[Devel] [PATCH hci-8.1 v2 2/6] dm-qcow2: truncate unused tail of image on suspend

Alexander Ivanov alexander.ivanov at virtuozzo.com
Thu Oct 8 12:50:48 MSK 2026


> [Severity: Medium]
> Can the value returned here exceed qcow2->file_size?
>
> file_preallocated_area_start is only page aligned after
> qcow2_parse_metadata(), not aligned to clu_size.  When clu_size is larger
> than PAGE_SIZE and the file ends in the middle of a cluster, the first
> cluster examined starts below file_preallocated_area_start but extends
> past it.
>
> If that cluster has a non-zero refcount, the function returns
> pos + clu_size, which is greater than file_size.

Fixed.

> [Severity: Medium]
> Is the check against file_size sufficient here?
>
> Only end == qcow2->file_size is tested, so with used_end greater than
> file_size the code goes on to call qcow2_truncate_safe(), and ftruncate
> extends the file.  qcow2->file_size and file_preallocated_area_start are
> then set to the larger value, although this patch is meant only to shrink
> the image.
>
> The growth is at most one cluster, but would it make sense to clamp with
> min(used_end, qcow2->file_size), or to use end >= qcow2->file_size for the
> early return?
After the previous fix qcow2_calc_used_end() can't return value greater 
than file_size.

> [Severity: Low]
> This isn't a bug, but QC_ERR already adds the "dm-qcow2: " prefix through
> QCOW2_FMT, so this message prints the prefix twice:
>
>      dm-qcow2: <dev>: dm-qcow2: Can't find used end: -5
>
> The raw negative errno is also printed with %lld.  Neighbouring messages in
> the same function repeat the prefix as well.
Fixed in the old and the new code.




More information about the Devel mailing list