RDMA/umem: Avoid undefined behavior of rounddown_pow_of_two()
authorAharon Landau <aharonl@nvidia.com>
Wed, 13 Jan 2021 12:16:59 +0000 (14:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Jan 2021 10:55:08 +0000 (11:55 +0100)
commit56c1362981b38942c9f20ae422dcce19e8ec8527
tree046b42587ddd7d3a850a3eda3e813e1f911cab5b
parenteb8ca93e492928447d1307a567b51e1a0b2be546
RDMA/umem: Avoid undefined behavior of rounddown_pow_of_two()

[ Upstream commit b79f2dc5ffe17b03ec8c55f0d63f65e87bcac676 ]

rounddown_pow_of_two() is undefined when the input is 0. Therefore we need
to avoid it in ib_umem_find_best_pgsz and return 0.  Otherwise, it could
result in not rejecting an invalid page size which eventually causes a
kernel oops due to the logical inconsistency.

Fixes: 3361c29e9279 ("RDMA/umem: Use simpler logic for ib_umem_find_best_pgsz()")
Link: https://lore.kernel.org/r/20210113121703.559778-2-leon@kernel.org
Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/core/umem.c