336-v4.15-netfilter-exit_net-cleanup-check-added.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. From: Vasily Averin <vvs@virtuozzo.com>
  2. Date: Sun, 12 Nov 2017 14:32:37 +0300
  3. Subject: [PATCH] netfilter: exit_net cleanup check added
  4. Be sure that lists initialized in net_init hook was return to initial
  5. state.
  6. Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
  7. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  8. ---
  9. --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
  10. +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
  11. @@ -835,6 +835,7 @@ static void clusterip_net_exit(struct ne
  12. cn->procdir = NULL;
  13. #endif
  14. nf_unregister_net_hook(net, &cip_arp_ops);
  15. + WARN_ON_ONCE(!list_empty(&cn->configs));
  16. }
  17. static struct pernet_operations clusterip_net_ops = {
  18. --- a/net/netfilter/nf_tables_api.c
  19. +++ b/net/netfilter/nf_tables_api.c
  20. @@ -6573,6 +6573,12 @@ static int __net_init nf_tables_init_net
  21. return 0;
  22. }
  23. +static void __net_exit nf_tables_exit_net(struct net *net)
  24. +{
  25. + WARN_ON_ONCE(!list_empty(&net->nft.af_info));
  26. + WARN_ON_ONCE(!list_empty(&net->nft.commit_list));
  27. +}
  28. +
  29. int __nft_release_basechain(struct nft_ctx *ctx)
  30. {
  31. struct nft_rule *rule, *nr;
  32. @@ -6650,6 +6656,7 @@ static void __nft_release_afinfo(struct
  33. static struct pernet_operations nf_tables_net_ops = {
  34. .init = nf_tables_init_net,
  35. + .exit = nf_tables_exit_net,
  36. };
  37. static int __init nf_tables_module_init(void)
  38. --- a/net/netfilter/nfnetlink_log.c
  39. +++ b/net/netfilter/nfnetlink_log.c
  40. @@ -1093,10 +1093,15 @@ static int __net_init nfnl_log_net_init(
  41. static void __net_exit nfnl_log_net_exit(struct net *net)
  42. {
  43. + struct nfnl_log_net *log = nfnl_log_pernet(net);
  44. + unsigned int i;
  45. +
  46. #ifdef CONFIG_PROC_FS
  47. remove_proc_entry("nfnetlink_log", net->nf.proc_netfilter);
  48. #endif
  49. nf_log_unset(net, &nfulnl_logger);
  50. + for (i = 0; i < INSTANCE_BUCKETS; i++)
  51. + WARN_ON_ONCE(!hlist_empty(&log->instance_table[i]));
  52. }
  53. static struct pernet_operations nfnl_log_net_ops = {
  54. --- a/net/netfilter/nfnetlink_queue.c
  55. +++ b/net/netfilter/nfnetlink_queue.c
  56. @@ -1510,10 +1510,15 @@ static int __net_init nfnl_queue_net_ini
  57. static void __net_exit nfnl_queue_net_exit(struct net *net)
  58. {
  59. + struct nfnl_queue_net *q = nfnl_queue_pernet(net);
  60. + unsigned int i;
  61. +
  62. nf_unregister_queue_handler(net);
  63. #ifdef CONFIG_PROC_FS
  64. remove_proc_entry("nfnetlink_queue", net->nf.proc_netfilter);
  65. #endif
  66. + for (i = 0; i < INSTANCE_BUCKETS; i++)
  67. + WARN_ON_ONCE(!hlist_empty(&q->instance_table[i]));
  68. }
  69. static void nfnl_queue_net_exit_batch(struct list_head *net_exit_list)
  70. --- a/net/netfilter/x_tables.c
  71. +++ b/net/netfilter/x_tables.c
  72. @@ -1781,8 +1781,17 @@ static int __net_init xt_net_init(struct
  73. return 0;
  74. }
  75. +static void __net_exit xt_net_exit(struct net *net)
  76. +{
  77. + int i;
  78. +
  79. + for (i = 0; i < NFPROTO_NUMPROTO; i++)
  80. + WARN_ON_ONCE(!list_empty(&net->xt.tables[i]));
  81. +}
  82. +
  83. static struct pernet_operations xt_net_ops = {
  84. .init = xt_net_init,
  85. + .exit = xt_net_exit,
  86. };
  87. static int __init xt_init(void)