Re: [PATCH 5.10] overflow.h: use new generic division helpers to avoid / operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 14, 2021 at 11:30:03AM -0700, Linus Torvalds wrote:
>  	case NBD_SET_SIZE_BLOCKS:
> -		if (check_mul_overflow((loff_t)arg, config->blksize, &bytesize))
> +		bytesize = arg << config->blksize_bits;
> +		if (bytesize >> config->blksize_bits != arg)
>  			return -EINVAL;

FWIW, it's probably better to avoid open-coding the check. There are
helpers for shift-left too. :)

+		if (check_shl_overflow(arg, config->blksize_bits, &bytesize))

-- 
Kees Cook



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux