powerpc/iommu: Avoid undefined right shift in iommu_range_alloc()
Michael Ellerman
patch-notifications at ellerman.id.au
Wed Aug 16 22:29:52 AEST 2017
On Tue, 2017-08-08 at 07:06:32 UTC, Michael Ellerman wrote:
> In iommu_range_alloc() we generate a mask by right shifting ~0,
> however if the specified alignment is 0 then we right shift by 64,
> which is undefined. UBSAN tells us so:
>
> UBSAN: Undefined behaviour in ../arch/powerpc/kernel/iommu.c:193:35
> shift exponent 64 is too large for 64-bit type 'long unsigned int'
>
> We can avoid it by instead generating the mask with:
>
> align_mask = (1ull << align_order) - 1;
>
> That will also generate an undefined shift if align_order is 64 or
> greater, but that shouldn't be a problem for a while.
>
> Signed-off-by: Michael Ellerman <mpe at ellerman.id.au>
Applied to powerpc next.
https://git.kernel.org/powerpc/c/63b85621d9aa6bdc410f01b22f7821
cheers
More information about the Linuxppc-dev
mailing list