bpf: devmap: fix wrong interface selection in notifier_call
Subsystems (4)
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
--- kernel/bpf/devmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/bpf/devmap.c +1 -2
@@ -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
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 patchFixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")Signed-off-by Taehee Yoo <[email protected]>
Quoted 21 lines
--- kernel/bpf/devmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/bpf/devmap.c +1
-3@@ -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
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 patchFixes 2ddf71e23cc2 ("net: add notifier hooks for devmap bpf map")Signed-off-by Taehee Yoo <[email protected]>
Applied to bpf, thanks Taehee!