Skip to content

Commit 63b8562

Browse files
committed
powerpc/iommu: Avoid undefined right shift in iommu_range_alloc()
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 <[email protected]>
1 parent 7efbae9 commit 63b8562

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/powerpc/kernel/iommu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static unsigned long iommu_range_alloc(struct device *dev,
190190
unsigned int pool_nr;
191191
struct iommu_pool *pool;
192192

193-
align_mask = 0xffffffffffffffffl >> (64 - align_order);
193+
align_mask = (1ull << align_order) - 1;
194194

195195
/* This allocator was derived from x86_64's bit string search */
196196

0 commit comments

Comments
 (0)