bpf: devmap: fix wrong interface selection in notifier_call
Subsystems (4)
PATCH 1/1 bpf: devmap: fix wrong interface selection in notifier_call
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.
--- kernel/bpf/devmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/devmap.c +2 -1
@@ -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 );
Signature · 1 line
2.17.1
Daniel Borkmann
maintainer[ +John ]
Quoted 25 lines · Taehee Yoo
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 thenet_eq()is needed.Fixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")Signed-off-by Taehee Yoo <[email protected]>--- kernel/bpf/devmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/bpf/devmap.c +1
-0@@ -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;
kernel/bpf/devmap.c static int dev_map_notification(struct notifier_block *notifier, · line 517
Quoted 6 lines
kernel/bpf/devmap.c +1
-1@@ -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?
Quoted 3 lines
kernel/bpf/devmap.c +0
-0continue ; odev =cmpxchg (&dtab->netdev_map[i], dev,NULL );
Hi Daniel!
Quoted 31 lines · Daniel Borkmann
[ +John ]
Quoted 27 lines · Taehee Yoo
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 thenet_eq()is needed.Fixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")Signed-off-by Taehee Yoo <[email protected]>--- kernel/bpf/devmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/bpf/devmap.c +1
-0@@ -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;
Quoted 7 lines
kernel/bpf/devmap.c static int dev_map_notification(struct notifier_block *notifier, · line 517
Quoted 4 lines
kernel/bpf/devmap.c +1
-1dev =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().
Quoted 4 lines
kernel/bpf/devmap.c static int dev_map_notification(struct notifier_block *notifier, · line 519
Quoted 3 lines
kernel/bpf/devmap.c +0
-0continue ; odev =cmpxchg (&dtab->netdev_map[i], dev,NULL );
Thanks!