netfilter: Add the missed return value check of register_netdevice_notifier
authorGao Feng <fgao@ikuai8.com>
Fri, 9 Sep 2016 15:25:09 +0000 (23:25 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 12 Sep 2016 17:54:43 +0000 (19:54 +0200)
There are some codes of netfilter module which did not check the return
value of register_netdevice_notifier. Add the checks now.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_tables_netdev.c
net/netfilter/nfnetlink_queue.c
net/netfilter/xt_TEE.c

index 3e5475a833a55fefe48cae7b966e0344a8108169..38a3e838504200c9ec1d84c503d7f3e6a876a85a 100644 (file)
@@ -151,12 +151,20 @@ static int __init nf_tables_netdev_init(void)
 
        nft_register_chain_type(&nft_filter_chain_netdev);
        ret = register_pernet_subsys(&nf_tables_netdev_net_ops);
-       if (ret < 0) {
-               nft_unregister_chain_type(&nft_filter_chain_netdev);
-               return ret;
-       }
-       register_netdevice_notifier(&nf_tables_netdev_notifier);
+       if (ret)
+               goto err1;
+
+       ret = register_netdevice_notifier(&nf_tables_netdev_notifier);
+       if (ret)
+               goto err2;
+
        return 0;
+
+err2:
+       unregister_pernet_subsys(&nf_tables_netdev_net_ops);
+err1:
+       nft_unregister_chain_type(&nft_filter_chain_netdev);
+       return ret;
 }
 
 static void __exit nf_tables_netdev_exit(void)
index f49f45081acb2200cc8acaed205f82a3298888ba..808da34f94cd3c6a7a5f9329f9f97cb363b8665c 100644 (file)
@@ -1522,9 +1522,16 @@ static int __init nfnetlink_queue_init(void)
                goto cleanup_netlink_notifier;
        }
 
-       register_netdevice_notifier(&nfqnl_dev_notifier);
+       status = register_netdevice_notifier(&nfqnl_dev_notifier);
+       if (status < 0) {
+               pr_err("nf_queue: failed to register netdevice notifier\n");
+               goto cleanup_netlink_subsys;
+       }
+
        return status;
 
+cleanup_netlink_subsys:
+       nfnetlink_subsys_unregister(&nfqnl_subsys);
 cleanup_netlink_notifier:
        netlink_unregister_notifier(&nfqnl_rtnl_notifier);
        unregister_pernet_subsys(&nfnl_queue_net_ops);
index 6e57a3966dc5748a8cbb99cdf28c62ba1d5b90f1..0471db4032c5ea6eb839229124762cbf1901e53f 100644 (file)
@@ -89,6 +89,8 @@ static int tee_tg_check(const struct xt_tgchk_param *par)
                return -EINVAL;
 
        if (info->oif[0]) {
+               int ret;
+
                if (info->oif[sizeof(info->oif)-1] != '\0')
                        return -EINVAL;
 
@@ -101,7 +103,11 @@ static int tee_tg_check(const struct xt_tgchk_param *par)
                priv->notifier.notifier_call = tee_netdev_event;
                info->priv    = priv;
 
-               register_netdevice_notifier(&priv->notifier);
+               ret = register_netdevice_notifier(&priv->notifier);
+               if (ret) {
+                       kfree(priv);
+                       return ret;
+               }
        } else
                info->priv = NULL;