diff mbox

[rdma-next,6/6] RDMA/cma: Protect ifindex access during IPv4 route lookup

Message ID 20180109135859.7676-7-leon@kernel.org (mailing list archive)
State Rejected
Headers show

Commit Message

Leon Romanovsky Jan. 9, 2018, 1:58 p.m. UTC
From: Parav Pandit <parav@mellanox.com>

Netdev ifindex can change while performing IPv4 fib_lookup(), therefore
access to ifindex under RCU lock.

This ensures that ifindex won't change while lookup is in progress.

Fixes: f887f2ac87c2 ("IB/cma: Validate routing of incoming requests")
Reviewed-by: Daniel Jurgens <danielj@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
---
 drivers/infiniband/core/cma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 690ed4238d72..1d5dc0d13105 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1314,11 +1314,11 @@  static bool validate_ipv4_net_dev(struct net_device *net_dev,
 		return false;
 
 	memset(&fl4, 0, sizeof(fl4));
-	fl4.flowi4_iif = net_dev->ifindex;
 	fl4.daddr = daddr;
 	fl4.saddr = saddr;
 
 	rcu_read_lock();
+	fl4.flowi4_iif = net_dev->ifindex;
 	err = fib_lookup(dev_net(net_dev), &fl4, &res, 0);
 	ret = err == 0 && FIB_RES_DEV(res) == net_dev;
 	rcu_read_unlock();