From: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Jason Gunthorpe <jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
RDMA mailing list
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Daniel Jurgens <danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Mark Bloch <markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Parav Pandit <parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH rdma-next 5/6] RDMA/cma: Protect ifindex access during IPv6 route lookup
Date: Tue, 23 Jan 2018 10:50:14 +0200 [thread overview]
Message-ID: <20180123085014.GO1393@mtr-leonro.local> (raw)
In-Reply-To: <20180122183820.GM14358-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 2751 bytes --]
On Mon, Jan 22, 2018 at 11:38:20AM -0700, Jason Gunthorpe wrote:
> On Tue, Jan 09, 2018 at 03:58:58PM +0200, Leon Romanovsky wrote:
> > From: Parav Pandit <parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> >
> > Netdev ifindex can change while performing IPv6 rt6_lookup().
> > Therefore access 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-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> > Signed-off-by: Parav Pandit <parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> > Signed-off-by: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > drivers/infiniband/core/cma.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> > index 90dead30de4c..690ed4238d72 100644
> > +++ b/drivers/infiniband/core/cma.c
> > @@ -1333,11 +1333,15 @@ static bool validate_ipv6_net_dev(struct net_device *net_dev,
> > #if IS_ENABLED(CONFIG_IPV6)
> > const int strict = ipv6_addr_type(&dst_addr->sin6_addr) &
> > IPV6_ADDR_LINKLOCAL;
> > - struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr,
> > - &src_addr->sin6_addr, net_dev->ifindex,
> > - strict);
> > + struct rt6_info *rt;
> > bool ret;
> >
> > + rcu_read_lock();
> > + rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr,
> > + &src_addr->sin6_addr, net_dev->ifindex,
> > + strict);
> > + rcu_read_unlock();
>
> This doesn't make sense to me.
>
> rcu is not supposed to be used in cases where two variables can change
> concurrently.
>
> For instance if the ifindex is changed due to dev_change_net_namespace()
> then you have this:
>
> dev_net_set(dev, net);
> if (__dev_get_by_index(net, dev->ifindex))
> dev->ifindex = dev_new_index(net);
>
> Racing with this:
>
> rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr,
> &src_addr->sin6_addr, net_dev->ifindex,
> strict);
>
> And we will get a racy incoherent result for dev_net(net_dev) and
> net_dev->ifindex.
I think that rcu_derefence over net_dev will solve the race.
>
> Same comment for the next patch too.
>
> It kind of looks to me like the locking scheme in the netdev side
> shuts down the netdev while moving it. So the RCU protected test
> should be if the netdev is DOWN ?
It is not the case for ipv6 tunnel interface, they use RCU protection
for live netdevs too.
>
> Jason
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-01-23 8:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 13:58 [PATCH rdma-next 0/6] Update CMA to use net namespace Leon Romanovsky
[not found] ` <20180109135859.7676-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2018-01-09 13:58 ` [PATCH rdma-next 1/6] RDMA/cma: Check existence of netdevice during port validation Leon Romanovsky
[not found] ` <20180109135859.7676-2-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2018-01-22 18:48 ` Jason Gunthorpe
[not found] ` <20180122184807.GN14358-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-22 20:39 ` Parav Pandit
[not found] ` <VI1PR0502MB30080B452158077BBA9C9EE4D1EC0-o1MPJYiShExKsLr+rGaxW8DSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2018-01-22 20:48 ` Jason Gunthorpe
2018-01-09 13:58 ` [PATCH rdma-next 2/6] RDMA/cma: Refactor to access multiple fields of rdma_dev_addr Leon Romanovsky
2018-01-09 13:58 ` [PATCH rdma-next 3/6] RDMA/cma: Update cma_validate_port to honor net namespace Leon Romanovsky
2018-01-09 13:58 ` [PATCH rdma-next 4/6] RDMA/cma: Update RoCE multicast routines to use " Leon Romanovsky
2018-01-09 13:58 ` [PATCH rdma-next 5/6] RDMA/cma: Protect ifindex access during IPv6 route lookup Leon Romanovsky
[not found] ` <20180109135859.7676-6-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2018-01-22 18:38 ` Jason Gunthorpe
[not found] ` <20180122183820.GM14358-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-23 8:50 ` Leon Romanovsky [this message]
[not found] ` <20180123085014.GO1393-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2018-01-23 15:07 ` Jason Gunthorpe
2018-01-09 13:58 ` [PATCH rdma-next 6/6] RDMA/cma: Protect ifindex access during IPv4 " Leon Romanovsky
2018-01-22 20:17 ` [PATCH rdma-next 0/6] Update CMA to use net namespace Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180123085014.GO1393@mtr-leonro.local \
--to=leon-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=danielj-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=parav-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.