All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Jean <sj-netfilter@cookinglinux.org>
To: Harald Welte <laforge@netfilter.org>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH] ipt_hashlimit.c: avoid data corruption on checkentry
Date: Mon, 14 Feb 2005 23:04:19 -0500	[thread overview]
Message-ID: <421174C3.8030705@cookinglinux.org> (raw)
In-Reply-To: <20050215005255.GS3829@sunbeam.de.gnumonks.org>

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

*Sorry if you get it twice. Looks like I sent from wrong email.*

Harald Welte wrote:

> Please consider / comment the following (untested) patch.

Yes. That's much less complicated than the other proposed patch.

> 
> Not really sure whether nesting the rwlock inside the mutex is that much
> of a good idea... but as the comment indicates, I think it's the best we
> can get.

I think the best we actually can get, is also replacing those rwlock's with
simple lock's. As you said on IRC, that's a bit overkill.

Incremental (also untested, but compiles) patch to your is attached.




[-- Attachment #2: linux-2.6.11-rc4-bk2-incremental_get_rid_rwlock.patch --]
[-- Type: text/x-patch, Size: 1738 bytes --]

#
#Signed-off-by: Samuel Jean <sjean@cookinglinux.org>
#
--- d/net/ipv4/netfilter/ipt_hashlimit.c	2005-02-14 20:48:33.000000000 -0500
+++ e/net/ipv4/netfilter/ipt_hashlimit.c	2005-02-14 21:00:07.000000000 -0500
@@ -97,7 +97,7 @@ struct ipt_hashlimit_htable {
 	struct list_head hash[0];	/* hashtable itself */
 };
 
-static DECLARE_RWLOCK(hashlimit_lock);	/* protects htables list */
+static DECLARE_LOCK(hashlimit_lock);	/* protects htables list */
 static DECLARE_MUTEX(hlimit_mutex);	/* additional checkentry protection */
 static LIST_HEAD(hashlimit_htables);
 static kmem_cache_t *hashlimit_cachep;
@@ -230,9 +230,9 @@ static int htable_create(struct ipt_hash
 	hinfo->timer.function = htable_gc;
 	add_timer(&hinfo->timer);
 
-	WRITE_LOCK(&hashlimit_lock);
+	LOCK_BH(&hashlimit_lock);
 	list_add(&hinfo->list, &hashlimit_htables);
-	WRITE_UNLOCK(&hashlimit_lock);
+	UNLOCK_BH(&hashlimit_lock);
 
 	return 0;
 }
@@ -296,15 +296,15 @@ static struct ipt_hashlimit_htable *htab
 {
 	struct ipt_hashlimit_htable *hinfo;
 
-	READ_LOCK(&hashlimit_lock);
+	LOCK_BH(&hashlimit_lock);
 	list_for_each_entry(hinfo, &hashlimit_htables, list) {
 		if (!strcmp(name, hinfo->pde->name)) {
 			atomic_inc(&hinfo->use);
-			READ_UNLOCK(&hashlimit_lock);
+			UNLOCK_BH(&hashlimit_lock);
 			return hinfo;
 		}
 	}
-	READ_UNLOCK(&hashlimit_lock);
+	UNLOCK_BH(&hashlimit_lock);
 
 	return NULL;
 }
@@ -312,9 +312,9 @@ static struct ipt_hashlimit_htable *htab
 static void htable_put(struct ipt_hashlimit_htable *hinfo)
 {
 	if (atomic_dec_and_test(&hinfo->use)) {
-		WRITE_LOCK(&hashlimit_lock);
+		LOCK_BH(&hashlimit_lock);
 		list_del(&hinfo->list);
-		WRITE_UNLOCK(&hashlimit_lock);
+		UNLOCK_BH(&hashlimit_lock);
 		htable_destroy(hinfo);
 	}
 }



  reply	other threads:[~2005-02-15  4:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-02  4:07 [PATCH] ipt_hashlimit.c: avoid data corruption on checkentry Samuel Jean
2005-02-02  4:14 ` Samuel Jean
2005-02-15  0:52 ` Harald Welte
2005-02-15  4:04   ` Samuel Jean [this message]
2005-02-22 11:35     ` Harald Welte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=421174C3.8030705@cookinglinux.org \
    --to=sj-netfilter@cookinglinux.org \
    --cc=laforge@netfilter.org \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=sjean@cookinglinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.