From: Patrick McHardy <kaber@trash.net>
To: Jesper Juhl <jj@chaosbits.net>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
coreteam@netfilter.org, netfilter@vger.kernel.org,
netfilter-devel@vger.kernel.org,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
James Morris <jmorris@namei.org>,
"Pekka Savola (ipv6)" <pekkas@netcore.fi>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH][RFC] netfilter: Fix small leak in ipq_build_packet_message()
Date: Fri, 29 Jul 2011 16:39:47 +0200 [thread overview]
Message-ID: <4E32C633.5000205@trash.net> (raw)
In-Reply-To: <alpine.LNX.2.00.1107171942400.32359@swampdragon.chaosbits.net>
On 17.07.2011 19:46, Jesper Juhl wrote:
> ipq_build_packet_message() in net/ipv4/netfilter/ip_queue.c and
> net/ipv6/netfilter/ip6_queue.c contain a small potential mem leak as
> far as I can tell.
>
> We allocate memory for 'skb' with alloc_skb() annd then call
> nlh = NLMSG_PUT(skb, 0, 0, IPQM_PACKET, size - sizeof(*nlh));
>
> NLMSG_PUT is a macro
> NLMSG_PUT(skb, pid, seq, type, len) \
> NLMSG_NEW(skb, pid, seq, type, len, 0)
>
> that expands to NLMSG_NEW, which is also a macro which expands to:
> NLMSG_NEW(skb, pid, seq, type, len, flags) \
> ({ if (unlikely(skb_tailroom(skb) < (int)NLMSG_SPACE(len))) \
> goto nlmsg_failure; \
> __nlmsg_put(skb, pid, seq, type, len, flags); })
>
> If we take the true branch of the 'if' statement and 'goto
> nlmsg_failure', then we'll, at that point, return from
> ipq_build_packet_message() without having assigned 'skb' to anything
> and we'll leak the memory we allocated for it when it goes out of
> scope.
>
> Fix this by placing a 'kfree(skb)' at 'nlmsg_failure'.
>
> I admit that I do not know how likely this to actually happen or even
> if there's something that guarantees that it will never happen - I'm
> not that familiar with this code, but if that is so, I've not been
> able to spot it.
>
> Please review and commit if you believe this is correct. Thanks.
>
Looks correct, applied, thanks.
prev parent reply other threads:[~2011-07-29 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-17 17:46 [PATCH][RFC] netfilter: Fix small leak in ipq_build_packet_message() Jesper Juhl
2011-07-29 14:39 ` Patrick McHardy [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=4E32C633.5000205@trash.net \
--to=kaber@trash.net \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=jj@chaosbits.net \
--cc=jmorris@namei.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.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).