Skip to contentSkip to conversation

iommu: Fix shift-out-of-bounds in iova_bitmap_offset_to_index()

PATCH Qasim Ijaz 1 participant 1 message Jan 13, 2025

lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw
Quoted 28 lines · Joao Martins
Quoted 27 lines · Jason Gunthorpe
Quoted 25 lines · Joao Martins
Quoted 1 line · Qasim Ijaz

This patch resolves a UBSAN shift-out-of-bounds issue in

Avoid the 'this patch' e.g. Resolve a UBSAN shift-out-of-bonds (...)

The Subject component part could also be a bit more specific e.g.

iommufd/iova_bitmap: Fix shift-out-of-bounds in iova_bitmap_offset_to_index()

Quoted 6 lines

iova_bitmap_offset_to_index() where shifting the constant "1" (of type int) by bitmap->mapped.pgshift (an unsigned long value) could result in undefined behavior.

The constant "1" defaults to a 32-bit "int", and when "pgshift" exceeds 31 (e.g., pgshift = 63) the shift operation overflows, as the result cannot be represented in a 32-bit type.

Quoted 6 lines

To resolve this, the constant is updated to "1UL", promoting it to an unsigned long type to match the operand's type.

With those two nits:

Quoted 7 lines
Quoted 1 line

It needs a fixes line too

It should be

Fixes 495c06d82ba ("vfio: Add an IOVA bitmap support")

Joao

Thank you for your feedback on the initial patch Jason and Joao. I’ve incorporated your suggestions and submitted a v2 patch for review.

Please let me know if further adjustments are needed.

Best regards,
Qasim