Skip to contentSkip to conversation

bpf: devmap: fix wrong interface selection in notifier_call

PATCH Applied Taehee Yoo 3 participants 3 messages Oct 24, 2018 – Oct 26, 2018

Subsystems (4)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v2 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 netdev pointer comparison code is added.

v2: compare netdev pointer instead of using net_eq() (Daniel Borkmann)
v1: Initial patch

Fixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")
---
 kernel/bpf/devmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/bpf/devmap.c +1 -2
index 141710b82a6c..191b79948424 100644
@@ -512,8 +512,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 ||
-				    dev->dev->ifindex != netdev->ifindex)
+				if (!dev || netdev != dev->dev)
 					continue;
 				odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
 				if (dev == odev)
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#1 lore raw
Quoted 7 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 netdev pointer comparison code is added.

Quoted 5 lines

v2: compare netdev pointer instead of using net_eq() (Daniel Borkmann)
v1: Initial patch

Fixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")
Quoted 21 lines
---
 kernel/bpf/devmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/bpf/devmap.c +1 -3
index 141710b82a6c..191b79948424 100644
@@ -512,8 +512,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 ||
-                                   dev->dev->ifindex != netdev->ifindex)
+                               if (!dev || netdev != dev->dev)
                                        continue;
                                odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
                                if (dev == odev)
--

2.17.1

maintainer Applied
#2 lore raw
In reply to Taehee Yoo
Quoted 11 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 netdev pointer comparison code is added.

v2: compare netdev pointer instead of using net_eq() (Daniel Borkmann)
v1: Initial patch

Fixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")

Applied to bpf, thanks Taehee!