Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Salih Gönüllü" <sag@open.ch>
Cc: netfilter@vger.kernel.org
Subject: Re: ulogd2 segfault
Date: Fri, 07 Jan 2011 14:37:11 +0100	[thread overview]
Message-ID: <4D271707.60407@netfilter.org> (raw)
In-Reply-To: <4D26E9C0.9090304@open.ch>

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

On 07/01/11 11:24, Salih Gönüllü wrote:
> On 01/06/2011 02:53 PM, Pablo Neira Ayuso wrote:
> 
>> Let me check this, if the problem is what you're pointing (which makes
>> sense at first look at the code) I guess that we need some refcounting
>> for plugins to avoid double freeing.
> 
> 
> When I comment out nflog_unbind_group(ui->nful_gh) in  stop() inside
> input/packet/ulogd_inppkt_NFLOG.c,  ulogd does not segfault anymore.
> 
> Here I have question:
> 
> Does  *pi in
> static int stop(struct ulogd_pluginstance *pi)
> 
> represent the NFLOG plugin or the individual log2:NFLOG ? I am asking
> because it get started only once with pluginstance_started(), and
> therefore should be stopped once (?)

Indeed, accurate analysis. Would you give a try to the following patch?

[-- Attachment #2: refcount.patch --]
[-- Type: text/x-patch, Size: 2111 bytes --]

ulogd: fix double call of stop for reused input plugins

From: Pablo Neira Ayuso <pablo@netfilter.org>

This patch adds reference counting for plugins. This is used to fix
a double stop for input plugins that are reused.

This problem was reported by Salih Gonullu <sag@open.ch>:

http://marc.info/?l=netfilter&m=129439584700693&w=2

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/ulogd/ulogd.h |    2 ++
 src/ulogd.c           |   14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h
index 2d1b348..e48caf8 100644
--- a/include/ulogd/ulogd.h
+++ b/include/ulogd/ulogd.h
@@ -208,6 +208,8 @@ struct ulogd_plugin {
 	char name[ULOGD_MAX_KEYLEN+1];
 	/* ID for this plugin (dynamically assigned) */
 	unsigned int id;
+	/* how many stacks are using this plugin? initially set to zero. */
+	unsigned int usage;
 
 	struct ulogd_keyset input;
 	struct ulogd_keyset output;
diff --git a/src/ulogd.c b/src/ulogd.c
index f378c6f..a4b0ed1 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -762,6 +762,15 @@ static int pluginstance_started(struct ulogd_pluginstance *npi)
 	return 0;
 }
 
+static int pluginstance_stop(struct ulogd_pluginstance *npi)
+{
+	if (--npi->plugin->usage > 0 &&
+	    npi->plugin->input.type == ULOGD_DTYPE_SOURCE) {
+		return 0;
+	}
+	return 1;
+}
+
 static int create_stack_start_instances(struct ulogd_pluginstance_stack *stack)
 {
 	int ret;
@@ -839,6 +848,7 @@ static int create_stack(const char *option)
 			ret = -ENODEV;
 			goto out;
 		}
+		pl->usage++;
 
 		/* allocate */
 		pi = pluginstance_alloc_init(pl, pi_id, stack);
@@ -989,8 +999,8 @@ static void stop_pluginstances()
 
 	llist_for_each_entry(stack, &ulogd_pi_stacks, stack_list) {
 		llist_for_each_entry_safe(pi, npi, &stack->list, list) {
-			if (((pi->plugin->priv_size == 0) || pi->private[0])
-					&& *pi->plugin->stop) {
+			if ((pi->plugin->priv_size > 0 || *pi->plugin->stop) &&
+			    pluginstance_stop(pi)) {
 				ulogd_log(ULOGD_DEBUG, "calling stop for %s\n",
 					  pi->plugin->name);
 				(*pi->plugin->stop)(pi);

  reply	other threads:[~2011-01-07 13:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-31 16:23 ulogd2 segfault Salih Gönüllü
2011-01-03 18:12 ` Salih Gönüllü
2011-01-06 13:53   ` Pablo Neira Ayuso
2011-01-07 10:24     ` Salih Gönüllü
2011-01-07 13:37       ` Pablo Neira Ayuso [this message]
2011-01-07 16:40         ` Salih Gönüllü
2011-01-08 14:36           ` Pablo Neira Ayuso

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=4D271707.60407@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter@vger.kernel.org \
    --cc=sag@open.ch \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox