From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: Eric Dumazet <eric.dumazet@gmail.com>, netdev@vger.kernel.org
Subject: Re: [BUG] 2.6.37-rc5 Memory leak in net/ipv4/udp.c
Date: Fri, 17 Dec 2010 12:56:17 +0100 [thread overview]
Message-ID: <19723.20449.974043.309608@ipc1.ka-ro> (raw)
In-Reply-To: <19723.19914.961119.861405@ipc1.ka-ro>
Hi again,
Lothar Waßmann writes:
> Eric Dumazet writes:
> > Le vendredi 17 décembre 2010 à 12:11 +0100, Lothar Waßmann a écrit :
> > > Hi,
> > >
> > > Eric Dumazet writes:
> > > > Le vendredi 17 décembre 2010 à 11:18 +0100, Lothar Waßmann a écrit :
> > > > > The offending code in net/ipv4/udp.c is:
> > > > > |void __init udp_table_init(struct udp_table *table, const char *name)
> > > > > |{
> > > > > | unsigned int i;
> > > > > |
> > > > > | if (!CONFIG_BASE_SMALL)
> > > > > | table->hash = alloc_large_system_hash(name,
> > > > > | 2 * sizeof(struct udp_hslot),
> > > > > | uhash_entries,
> > > > > | 21, /* one slot per 2 MB */
> > > > > | 0,
> > > > > | &table->log,
> > > > > | &table->mask,
> > > > > | 64 * 1024);
> > > > > | /*
> > > > > | * Make sure hash table has the minimum size
> > > > > | */
> > > > > | if (CONFIG_BASE_SMALL || table->mask < UDP_HTABLE_SIZE_MIN - 1) {
> > > > > | table->hash = kmalloc(UDP_HTABLE_SIZE_MIN *
> > > > > | 2 * sizeof(struct udp_hslot), GFP_KERNEL);
> > > > > In case of !CONFIG_BASE_SMALL and 'table->mask < UDP_HTABLE_SIZE_MIN - 1)'
> > > > > the memory allocated in the previous if clause becomes inacessible!
> > > > >
> > > > > Shouldn't this be:
> > > > > | if (!CONFIG_BASE_SMALL && table->mask >= UDP_HTABLE_SIZE_MIN - 1) {
> > > > > | table->hash = alloc_large_system_hash(name,
> > > > > | 2 * sizeof(struct udp_hslot),
> > > > > | uhash_entries,
> > > > > | 21, /* one slot per 2 MB */
> > > > > | 0,
> > > > > | &table->log,
> > > > > | &table->mask,
> > > > > | 64 * 1024);
> > > > > | } else {
> > > > > | table->hash = kmalloc(UDP_HTABLE_SIZE_MIN *
> > > > > | 2 * sizeof(struct udp_hslot), GFP_KERNEL);
> > > > > [...]
> > > > >
> > > >
> > > > Nothing we can do about it, there is no API to reverse the
> > > > alloc_large_system_hash() effect. We could call kmemleak api to at least
> > > > avoid this false alarm.
> > > >
> > > Do you have to call it at all in case of table->mask < UDP_HTABLE_SIZE_MIN - 1?
> > >
> >
> > We call alloc_large_system_hash() asking it to size the table _itself_.
> > We give some hints :
> >
> > - How many slots per MB of avail memory.
> > - An upper limit (64*1024 slots because we only handle 65536 udp ports)
> > - but not a lower limit (not available in the API)
> >
> > Problem is in your case, alloc_large_system_hash() allocates a very
> > small area. Then we catch the problem, seeing table->mask is too small
> > for our needs. We prefer to 'lost' this too small memory than crashing
> > kernel later.
> >
> table->mask is not altered by alloc_large_system_hash(), so you could
> detect the situation beforhand and avoid calling that function in this
> case. As far as I can tell there is no need for
> alloc_large_system_hash() if you later decide to use kmalloc'ed memory
> instead.
>
Forget about this. I was a little confused when reading the
alloc_large_system_hash() function. No I understand.
Sorry for the noise.
Lothar Waßmann
--
___________________________________________________________
Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996
www.karo-electronics.de | info@karo-electronics.de
___________________________________________________________
next prev parent reply other threads:[~2010-12-17 11:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-17 10:18 [BUG] 2.6.37-rc5 Memory leak in net/ipv4/udp.c Lothar Waßmann
2010-12-17 10:35 ` Eric Dumazet
2010-12-17 11:11 ` Lothar Waßmann
2010-12-17 11:32 ` Eric Dumazet
2010-12-17 11:47 ` Lothar Waßmann
2010-12-17 11:56 ` Lothar Waßmann [this message]
2010-12-17 14:22 ` Eric Dumazet
2010-12-17 14:28 ` Lothar Waßmann
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=19723.20449.974043.309608@ipc1.ka-ro \
--to=lw@karo-electronics.de \
--cc=eric.dumazet@gmail.com \
--cc=netdev@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