Commit e42a046b authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Greg Kroah-Hartman
Browse files

iommufd: Prevent ALIGN() overflow



commit b42497e3 upstream.

When allocating IOVA the candidate range gets aligned to the target
alignment. If the range is close to ULONG_MAX then the ALIGN() can
wrap resulting in a corrupted iova.

Open code the ALIGN() using get_add_overflow() to prevent this.
This simplifies the checks as we don't need to check for length earlier
either.

Consolidate the two copies of this code under a single helper.

This bug would allow userspace to create a mapping that overlaps with some
other mapping or a reserved range.

Cc: stable@vger.kernel.org
Fixes: 51fe6141 ("iommufd: Data structure to provide IOVA to PFN mapping")
Reported-by: default avatar <syzbot+c2f65e2801743ca64e08@syzkaller.appspotmail.com>
Closes: https://lore.kernel.org/r/685af644.a00a0220.2e5631.0094.GAE@google.com


Reviewed-by: default avatarYi Liu <yi.l.liu@intel.com>
Reviewed-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Link: https://patch.msgid.link/all/1-v1-7b4a16fc390b+10f4-iommufd_alloc_overflow_jgg@nvidia.com/


Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3643a379
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment