From f9f690c451ca6b91930ac0a646f643c758c9a41c Mon Sep 17 00:00:00 2001 From: Artemy Kovalyov Date: Thu, 21 Feb 2019 17:32:27 +0800 Subject: [PATCH] IB/mlx5: Skip non-ODP MR when handling a page fault mainline inclusion from mainline-4.20-rc7 commit 4d5422a309deecec906c491f8aea77593a46321d category: bugfix bugzilla: 6625 CVE: NA ----------------------------- Since any page fault may be interrupted by a MMU invalidation and implicit It is possible that we call pagefault_single_data_segment() with a MKey that belongs to a memory region which is not on demand (i.e. pinned pages). This can happen if, for instance, a WQE that points to multiple MRs where some of them are ODP MRs and some are not. In this case we don't need to handle this MR in the ODP context besides reporting success. Otherwise the code will call pagefault_mr() which will do to_ib_umem_odp() on a non-ODP MR and thus access out of bounds. Conflicts: drivers/infiniband/hw/mlx5/odp.c [jingxiangfeng: '597ecc5 RDMA/umem: Get rid of struct ib_umem.odp_data' is not nessary to backport. so I have changed to 'umem->odp_data' instead of 'umem->is_odp'.] Fixes: 7bdf65d411c1 ("IB/mlx5: Handle page faults") Signed-off-by: Artemy Kovalyov Signed-off-by: Moni Shoua Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Jing Xiangfeng Reviewed-by: Hanjun Guo Signed-off-by: Yang Yingliang --- drivers/infiniband/hw/mlx5/odp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index 6835c37ed7fb..1fc23cd11451 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -663,6 +663,14 @@ static int pagefault_single_data_segment(struct mlx5_ib_dev *dev, goto srcu_unlock; } + if (!mr->umem->odp_data) { + mlx5_ib_dbg(dev, "skipping non ODP MR (lkey=0x%06x) in page fault handler.\n", + key); + if (bytes_mapped) + *bytes_mapped += bcnt; + goto srcu_unlock; + } + ret = pagefault_mr(dev, mr, io_virt, bcnt, bytes_mapped); if (ret < 0) goto srcu_unlock; -- GitLab