netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Carlos Falgueras García" <carlosfg@riseup.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 1/2] libnfntl: Fix segfault due to invalid free of rule user data
Date: Wed, 25 May 2016 10:44:23 +0200	[thread overview]
Message-ID: <20160525084423.GB4024@salvia> (raw)
In-Reply-To: <1463500816-26155-2-git-send-email-carlosfg@riseup.net>

On Tue, May 17, 2016 at 06:00:15PM +0200, Carlos Falgueras García wrote:
> If the user allocates a nftnl_udata_buf and then passes the TLV data to
> nftnl_rule_set_data, the pointer stored in rule.user.data is not the begining of
> the allocated block. In this situation, if it calls to nftnl_rule_free, it tries
> to free this pointer and segfault is thrown.
> 
> Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
> ---
>  src/rule.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/rule.c b/src/rule.c
> index c299548..3f276f8 100644
> --- a/src/rule.c
> +++ b/src/rule.c
> @@ -167,7 +167,12 @@ void nftnl_rule_set_data(struct nftnl_rule *r, uint16_t attr,
>  		if (r->user.data != NULL)
>  			xfree(r->user.data);
>  
> -		r->user.data = (void *)data;
> +		r->user.data = malloc(data_len);
> +		if (!r->user.data) {
> +			perror("libnftnl: " __FILE__ ": nftnl_rule_set_data()");

We should spot this error messages from the library. The only
exception is when netlink ABI gets broken. So I'm removing this line.

We should add a new version of these setters at some point so we can
return an error (instead of void), so the client may check if the
memory allocation has failed, later.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-05-25  8:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-17 16:00 [PATCH] libnftnl: tests: Free nftnl_udata_buf before exit Carlos Falgueras García
2016-05-17 16:00 ` [PATCH 1/2] libnfntl: Fix segfault due to invalid free of rule user data Carlos Falgueras García
2016-05-25  8:44   ` Pablo Neira Ayuso [this message]
2016-05-17 16:00 ` [PATCH 2/2] nftables: Fix memory leak linearizing " Carlos Falgueras García
2016-05-25  8:46   ` Pablo Neira Ayuso
2016-05-25  8:42 ` [PATCH] libnftnl: tests: Free nftnl_udata_buf before exit 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=20160525084423.GB4024@salvia \
    --to=pablo@netfilter.org \
    --cc=carlosfg@riseup.net \
    --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 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).