From mboxrd@z Thu Jan 1 00:00:00 1970 From: Taehee Yoo Subject: [PATCH bpf] bpf: devmap: fix wrong interface selection in notifier_call Date: Tue, 23 Oct 2018 00:41:43 +0900 Message-ID: <20181022154143.15396-1-ap420073@gmail.com> Cc: netdev@vger.kernel.org, ap420073@gmail.com To: daniel@iogearbox.net, ast@kernel.org Return-path: Received: from mail-pl1-f193.google.com ([209.85.214.193]:45968 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728172AbeJWAAw (ORCPT ); Mon, 22 Oct 2018 20:00:52 -0400 Received: by mail-pl1-f193.google.com with SMTP id o19-v6so3471028pll.12 for ; Mon, 22 Oct 2018 08:41:50 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: 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 --- 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