All of lore.kernel.org
 help / color / mirror / Atom feed
From: jeffy <jeffy.chen@rock-chips.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Cc: zlpnobody@gmail.com, dianders@chromium.org, briannorris@chromium.org
Subject: Re: [PATCH 2/2 nf] netfilter: cthelper: Fix memory leak
Date: Wed, 22 Mar 2017 10:43:30 +0800	[thread overview]
Message-ID: <58D1E4D2.3060207@rock-chips.com> (raw)
In-Reply-To: <1490100094-32269-2-git-send-email-pablo@netfilter.org>

Hi Pablo,

On chromebook kevin:
Tested-by: Jeffy Chen <jeffy.chen@rock-chips.com>

On 03/21/2017 08:41 PM, Pablo Neira Ayuso wrote:
> From: Jeffy Chen <jeffy.chen@rock-chips.com>
>
> We have memory leaks of nf_conntrack_helper & expect_policy.
>
> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> Heavily based on your original patch, so I'm keeping you as original author
> for this fix.
>
>   net/netfilter/nfnetlink_cthelper.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
> index ffb51b91e646..bc43d8635cb8 100644
> --- a/net/netfilter/nfnetlink_cthelper.c
> +++ b/net/netfilter/nfnetlink_cthelper.c
> @@ -214,7 +214,7 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
>
>   	ret = nfnl_cthelper_parse_expect_policy(helper, tb[NFCTH_POLICY]);
>   	if (ret < 0)
> -		goto err;
> +		goto err1;
it's safe to kfree a null pointer, so we can use the same goto label 
with err2.
But it's up to you, just matter of taste :)

>
>   	strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
>   	helper->data_len = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
> @@ -245,10 +245,12 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
>
>   	ret = nf_conntrack_helper_register(helper);
>   	if (ret < 0)
> -		goto err;
> +		goto err2;
>
>   	return 0;
> -err:
> +err2:
> +	kfree(helper->expect_policy);
> +err1:
>   	kfree(helper);
>   	return ret;
>   }
> @@ -676,6 +678,8 @@ static int nfnl_cthelper_del(struct net *net, struct sock *nfnl,
>
>   			found = true;
>   			nf_conntrack_helper_unregister(cur);
> +			kfree(cur->expect_policy);
> +			kfree(cur);
>   		}
>   	}
>   	/* Make sure we return success if we flush and there is no helpers */
> @@ -739,6 +743,8 @@ static void __exit nfnl_cthelper_exit(void)
>   				continue;
>
>   			nf_conntrack_helper_unregister(cur);
> +			kfree(cur->expect_policy);
> +			kfree(cur);
>   		}
>   	}
>   }
>



      reply	other threads:[~2017-03-22  2:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21 12:41 [PATCH 1/2 nf] netfilter: nfnetlink_cthelper: fix runtime expectation policy updates Pablo Neira Ayuso
2017-03-21 12:41 ` [PATCH 2/2 nf] netfilter: cthelper: Fix memory leak Pablo Neira Ayuso
2017-03-22  2:43   ` jeffy [this message]

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=58D1E4D2.3060207@rock-chips.com \
    --to=jeffy.chen@rock-chips.com \
    --cc=briannorris@chromium.org \
    --cc=dianders@chromium.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=zlpnobody@gmail.com \
    /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.