All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call
@ 2018-10-22 15:41 Taehee Yoo
  2018-10-24  9:07 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Taehee Yoo @ 2018-10-22 15:41 UTC (permalink / raw)
  To: daniel, ast; +Cc: netdev, ap420073

The dev_map_notification() removes interface in devmap if
unregistering interface's ifindex is same.
But only checking ifindex is not enough because other netns can have
same ifindex. so that wrong interface selection could occurred.
Hence the net_eq() is needed.

Fixes: 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 kernel/bpf/devmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 141710b82a6c..0d9211e49a4a 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -496,6 +496,7 @@ static int dev_map_notification(struct notifier_block *notifier,
 				ulong event, void *ptr)
 {
 	struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
+	struct net *net = dev_net(netdev);
 	struct bpf_dtab *dtab;
 	int i;
 
@@ -512,7 +513,7 @@ static int dev_map_notification(struct notifier_block *notifier,
 				struct bpf_dtab_netdev *dev, *odev;
 
 				dev = READ_ONCE(dtab->netdev_map[i]);
-				if (!dev ||
+				if (!dev || !net_eq(net, dev_net(dev->dev)) ||
 				    dev->dev->ifindex != netdev->ifindex)
 					continue;
 				odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call
  2018-10-22 15:41 [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call Taehee Yoo
@ 2018-10-24  9:07 ` Daniel Borkmann
  2018-10-24 11:03   ` Taehee Yoo
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2018-10-24  9:07 UTC (permalink / raw)
  To: Taehee Yoo, ast; +Cc: netdev, john.fastabend

[ +John ]

On 10/22/2018 05:41 PM, Taehee Yoo wrote:
> The dev_map_notification() removes interface in devmap if
> unregistering interface's ifindex is same.
> But only checking ifindex is not enough because other netns can have
> same ifindex. so that wrong interface selection could occurred.
> Hence the net_eq() is needed.
> 
> Fixes: 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
> ---
>  kernel/bpf/devmap.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 141710b82a6c..0d9211e49a4a 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -496,6 +496,7 @@ static int dev_map_notification(struct notifier_block *notifier,
>  				ulong event, void *ptr)
>  {
>  	struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
> +	struct net *net = dev_net(netdev);
>  	struct bpf_dtab *dtab;
>  	int i;
>  
> @@ -512,7 +513,7 @@ static int dev_map_notification(struct notifier_block *notifier,
>  				struct bpf_dtab_netdev *dev, *odev;
>  
>  				dev = READ_ONCE(dtab->netdev_map[i]);
> -				if (!dev ||
> +				if (!dev || !net_eq(net, dev_net(dev->dev)) ||
>  				    dev->dev->ifindex != netdev->ifindex)

Can't we just compare netdev pointers directly here?

>  					continue;
>  				odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call
  2018-10-24  9:07 ` Daniel Borkmann
@ 2018-10-24 11:03   ` Taehee Yoo
  0 siblings, 0 replies; 3+ messages in thread
From: Taehee Yoo @ 2018-10-24 11:03 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: ast, Netdev, john.fastabend

Hi Daniel!

On Wed, 24 Oct 2018 at 18:07, Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> [ +John ]
>
> On 10/22/2018 05:41 PM, Taehee Yoo wrote:
> > The dev_map_notification() removes interface in devmap if
> > unregistering interface's ifindex is same.
> > But only checking ifindex is not enough because other netns can have
> > same ifindex. so that wrong interface selection could occurred.
> > Hence the net_eq() is needed.
> >
> > Fixes: 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")
> > Signed-off-by: Taehee Yoo <ap420073@gmail.com>
> > ---
> >  kernel/bpf/devmap.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> > index 141710b82a6c..0d9211e49a4a 100644
> > --- a/kernel/bpf/devmap.c
> > +++ b/kernel/bpf/devmap.c
> > @@ -496,6 +496,7 @@ static int dev_map_notification(struct notifier_block *notifier,
> >                               ulong event, void *ptr)
> >  {
> >       struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
> > +     struct net *net = dev_net(netdev);
> >       struct bpf_dtab *dtab;
> >       int i;
> >
> > @@ -512,7 +513,7 @@ static int dev_map_notification(struct notifier_block *notifier,
> >                               struct bpf_dtab_netdev *dev, *odev;
> >
> >                               dev = READ_ONCE(dtab->netdev_map[i]);
> > -                             if (!dev ||
> > +                             if (!dev || !net_eq(net, dev_net(dev->dev)) ||
> >                                   dev->dev->ifindex != netdev->ifindex)
>
> Can't we just compare netdev pointers directly here?
>

Thank you for review!
I tested what you suggested, It works well and it's more simple.
So that I will send v2 patch that just compares netdev pointer instead of
using ifindex and net_eq().

> >                                       continue;
> >                               odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
> >
>

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-24 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22 15:41 [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call Taehee Yoo
2018-10-24  9:07 ` Daniel Borkmann
2018-10-24 11:03   ` Taehee Yoo

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.