netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xt_recent fix BUG()
@ 2012-12-11 19:06 Vitaly E. Lavrov
  2012-12-16 22:50 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly E. Lavrov @ 2012-12-11 19:06 UTC (permalink / raw)
  To: netfilter-devel

[-- Attachment #1: Type: text/plain, Size: 2465 bytes --]

The following patch fixes a bug in xt_recent.
Bug appears at the end of work the networks namespace, provided that the 
tables (filter/mangle/raw) have rule  with xt_recent.
The error occurs because the __net_exit recent_net_exit() is executed 
before the tables are cleared.
Change this order of calls is impossible, since tables must be 
registered earlier than extensions.
Bug exists in all versions of the kernel since 2.6.35

Cleaning tables before completing the network namespace can be used as a 
workaround.

Idea of the patch that if the files are deleted from the directory 
/proc/net/xt_recent" procedure XXXXX, then a flag is set "clean".
If cleaning the tables occurs later and the flag "clean" is set, then 
the delete files is skipped.

Patch for kernel 3.4.22

Signed-off-by: Vitaly Lavrov lve@guap.ru

--
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index d2ff15a..747d52d 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -85,6 +85,7 @@ struct recent_net {
         struct list_head        tables;
  #ifdef CONFIG_PROC_FS
         struct proc_dir_entry   *xt_recent;
+       int                     clean;
  #endif
  };

@@ -398,7 +399,8 @@ static void recent_mt_destroy(const struct 
xt_mtdtor_param *par)
                 list_del(&t->list);
                 spin_unlock_bh(&recent_lock);
  #ifdef CONFIG_PROC_FS
-               remove_proc_entry(t->name, recent_net->xt_recent);
+               if(!recent_net->clean)
+                       remove_proc_entry(t->name, recent_net->xt_recent);
  #endif
                 recent_table_flush(t);
                 kfree(t);
@@ -599,15 +601,26 @@ static int __net_init recent_net_init(struct net *net)
  {
         struct recent_net *recent_net = recent_pernet(net);

+#ifdef CONFIG_PROC_FS
+       recent_net->clean = 0;
+#endif
         INIT_LIST_HEAD(&recent_net->tables);
         return recent_proc_net_init(net);
  }

  static void __net_exit recent_net_exit(struct net *net)
  {
+#ifdef CONFIG_PROC_FS
         struct recent_net *recent_net = recent_pernet(net);
+       struct recent_table *t;

-       BUG_ON(!list_empty(&recent_net->tables));
+       spin_lock_bh(&recent_lock);
+       recent_net->clean = 1;
+       list_for_each_entry(t, &recent_net->tables, list) {
+               remove_proc_entry(t->name, recent_net->xt_recent);
+       }
+       }
+       spin_unlock_bh(&recent_lock);
+#endif
         recent_proc_net_exit(net);
  }

[-- Attachment #2: xt_recent.c.diff --]
[-- Type: text/plain, Size: 1382 bytes --]

diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index d2ff15a..747d52d 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -85,6 +85,7 @@ struct recent_net {
 	struct list_head	tables;
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry	*xt_recent;
+	int			clean;
 #endif
 };
 
@@ -398,7 +399,8 @@ static void recent_mt_destroy(const struct xt_mtdtor_param *par)
 		list_del(&t->list);
 		spin_unlock_bh(&recent_lock);
 #ifdef CONFIG_PROC_FS
-		remove_proc_entry(t->name, recent_net->xt_recent);
+		if(!recent_net->clean)
+			remove_proc_entry(t->name, recent_net->xt_recent);
 #endif
 		recent_table_flush(t);
 		kfree(t);
@@ -599,15 +601,26 @@ static int __net_init recent_net_init(struct net *net)
 {
 	struct recent_net *recent_net = recent_pernet(net);
 
+#ifdef CONFIG_PROC_FS
+	recent_net->clean = 0;
+#endif
 	INIT_LIST_HEAD(&recent_net->tables);
 	return recent_proc_net_init(net);
 }
 
 static void __net_exit recent_net_exit(struct net *net)
 {
+#ifdef CONFIG_PROC_FS
 	struct recent_net *recent_net = recent_pernet(net);
+	struct recent_table *t;
 
-	BUG_ON(!list_empty(&recent_net->tables));
+	spin_lock_bh(&recent_lock);
+	recent_net->clean = 1;
+	list_for_each_entry(t, &recent_net->tables, list) {
+		remove_proc_entry(t->name, recent_net->xt_recent);
+	}
+	spin_unlock_bh(&recent_lock);
+#endif
 	recent_proc_net_exit(net);
 }
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xt_recent fix BUG()
  2012-12-11 19:06 [PATCH] xt_recent fix BUG() Vitaly E. Lavrov
@ 2012-12-16 22:50 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2012-12-16 22:50 UTC (permalink / raw)
  To: Vitaly E. Lavrov; +Cc: netfilter-devel

Hi Vitaly,

On Tue, Dec 11, 2012 at 11:06:32PM +0400, Vitaly E. Lavrov wrote:
> The following patch fixes a bug in xt_recent.
> Bug appears at the end of work the networks namespace, provided that
> the tables (filter/mangle/raw) have rule  with xt_recent.
> The error occurs because the __net_exit recent_net_exit() is
> executed before the tables are cleared.
> Change this order of calls is impossible, since tables must be
> registered earlier than extensions.
> Bug exists in all versions of the kernel since 2.6.35
> 
> Cleaning tables before completing the network namespace can be used
> as a workaround.
> 
> Idea of the patch that if the files are deleted from the directory
> /proc/net/xt_recent" procedure XXXXX, then a flag is set "clean".
> If cleaning the tables occurs later and the flag "clean" is set,
> then the delete files is skipped.
> 
> Patch for kernel 3.4.22

I need that the patch applies to some more recent kernel tree.

Same comment for the hashlimit fix.

Could you send me a new round rebased upon it, please? Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-16 22:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-11 19:06 [PATCH] xt_recent fix BUG() Vitaly E. Lavrov
2012-12-16 22:50 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).