All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Duncan Roe <duncan_roe@optusnet.com.au>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH libnetfilter_queue] Stop a memory leak in nfq_close
Date: Wed, 5 Jun 2024 17:19:23 +0200	[thread overview]
Message-ID: <ZmCB-walvbM9SnX7@calendula> (raw)
In-Reply-To: <20240506231719.9589-1-duncan_roe@optusnet.com.au>

Hi Duncan,

On Tue, May 07, 2024 at 09:17:19AM +1000, Duncan Roe wrote:
> 0c5e5fb introduced struct nfqnl_q_handle *qh_list which can point to
> dynamically acquired memory. Without this patch, that memory is not freed.

Indeed.

Looking at the example available at utils, I can see this assumes
that:

        nfq_destroy_queue(qh);

needs to be called.

qh->data can be also set to heap structure, in that case this would leak too.

It seems nfq_destroy_queue() needs to be called before nfq_close() by design.

Probably add:

        assert(h->qh_list == NULL);

at the top of nfq_close() instead to give a chance to users of this to
fix their code in case they are leaking qh?

Thanks

> Fixes: 0c5e5fb15205 ("sync with all 'upstream' changes in libnfnetlink_log")
> Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
> ---
>  src/libnetfilter_queue.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/libnetfilter_queue.c b/src/libnetfilter_queue.c
> index bf67a19..f152efb 100644
> --- a/src/libnetfilter_queue.c
> +++ b/src/libnetfilter_queue.c
> @@ -481,7 +481,13 @@ EXPORT_SYMBOL
>  int nfq_close(struct nfq_handle *h)
>  {
>  	int ret;
> +	struct nfq_q_handle *qh;
>  
> +	while (h->qh_list) {
> +		qh = h->qh_list;
> +		h->qh_list = qh->next;
> +		free(qh);
> +	}
>  	ret = nfnl_close(h->nfnlh);
>  	if (ret == 0)
>  		free(h);
> -- 
> 2.35.8
> 
> 

  reply	other threads:[~2024-06-05 15:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 23:17 [PATCH libnetfilter_queue] Stop a memory leak in nfq_close Duncan Roe
2024-06-05 15:19 ` Pablo Neira Ayuso [this message]
2024-06-11  2:46   ` Duncan Roe
2024-06-11 22:21     ` Pablo Neira Ayuso
2024-06-13  3:09       ` Duncan Roe

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=ZmCB-walvbM9SnX7@calendula \
    --to=pablo@netfilter.org \
    --cc=duncan_roe@optusnet.com.au \
    --cc=netfilter-devel@vger.kernel.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.