From: Aharon Landau Date: Wed, 13 Jan 2021 12:16:59 +0000 (+0200) Subject: RDMA/umem: Avoid undefined behavior of rounddown_pow_of_two() X-Git-Tag: rel_imx_5.10.35_2.0.0-somdevices.0~363^2~2204 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=56c1362981b38942c9f20ae422dcce19e8ec8527;p=linux.git 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 Reviewed-by: Jason Gunthorpe Reviewed-by: Maor Gottlieb Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index e9fecbdf391b..5157ae29a446 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -126,7 +126,7 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, */ if (mask) pgsz_bitmap &= GENMASK(count_trailing_zeros(mask), 0); - return rounddown_pow_of_two(pgsz_bitmap); + return pgsz_bitmap ? rounddown_pow_of_two(pgsz_bitmap) : 0; } EXPORT_SYMBOL(ib_umem_find_best_pgsz);