[lvc-project] [PATCH] udf: balloc: prevent integer overflow in udf_bitmap_free_blocks()

Jan Kara jack at suse.cz
Tue Jun 11 10:48:50 MSK 2024


On Mon 10-06-24 10:25:22, Roman Smirnov wrote:
> An overflow may occur if the function is called with the last
> block and an offset greater than zero. It is necessary to add
> a check to avoid this.
> 
> Found by Linux Verification Center (linuxtesting.org) with Svace.
> 
> Signed-off-by: Roman Smirnov <r.smirnov at omp.ru>

Thanks for the patch! Actually there are overflow checks just a few lines
above the place you modify:

        if (bloc->logicalBlockNum + count < count ||
            (bloc->logicalBlockNum + count) > partmap->s_partition_len) {

So please update those to take 'offset' into account instead. Also please
use check_add_overflow() for the integer overflow check.

								Honza

> ---
>  fs/udf/balloc.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
> index ab3ffc355949..cd83bbc7d890 100644
> --- a/fs/udf/balloc.c
> +++ b/fs/udf/balloc.c
> @@ -151,6 +151,13 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
>  	block = bloc->logicalBlockNum + offset +
>  		(sizeof(struct spaceBitmapDesc) << 3);
>  
> +	if (block < offset + (sizeof(struct spaceBitmapDesc) << 3)) {
> +		udf_debug("integer overflow: %u + %u + %zu",
> +			  bloc->logicalBlockNum, offset,
> +			  sizeof(struct spaceBitmapDesc) << 3);
> +		goto error_return;
> +	}
> +
>  	do {
>  		overflow = 0;
>  		block_group = block >> (sb->s_blocksize_bits + 3);
> -- 
> 2.34.1
> 
-- 
Jan Kara <jack at suse.com>
SUSE Labs, CR



More information about the lvc-project mailing list