[PATCH v2 bpf] bpf: devmap: fix wrong interface selection in notifier_call

Subsystems: bpf [general] (safe dynamic programs and tools), the rest, xdp (express data path)

STALE2878d

3 messages, 3 authors, 2018-10-26 · open the first message on its own page

[PATCH v2 bpf] bpf: devmap: fix wrong interface selection in notifier_call

From: Taehee Yoo <ap420073@gmail.com>
Date: 2018-10-24 19:43:06

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")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 kernel/bpf/devmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 141710b82a6c..191b79948424 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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

Re: [PATCH v2 bpf] bpf: devmap: fix wrong interface selection in notifier_call

From: Song Liu <hidden>
Date: 2018-10-25 02:25:24

On Wed, Oct 24, 2018 at 4:16 AM Taehee Yoo [off-list ref] 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 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")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Acked-by: Song Liu <redacted>
quoted hunk
---
 kernel/bpf/devmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 141710b82a6c..191b79948424 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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

Re: [PATCH v2 bpf] bpf: devmap: fix wrong interface selection in notifier_call

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2018-10-26 07:30:57

On 10/24/2018 01:15 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 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")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Applied to bpf, thanks Taehee!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help