From: Jeff Moyer <jmoyer@redhat.com>
To: autofs@linux.kernel.org
Cc: raven@themaw.net, linux-kernel@vger.kernel.org
Subject: autofs4 patch: autofs4_wait can leak memory
Date: Fri, 4 Mar 2005 10:48:03 -0500 [thread overview]
Message-ID: <16936.33587.974061.237160@segfault.boston.redhat.com> (raw)
[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 1378 bytes --]
Hi,
There is a memory in the autofs4_wait function, if multiple processes are
waiting on the same queue:
name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
if (!name)
return -ENOMEM;
...
if ( !wq ) {
/* Create a new wait queue */
wq = kmalloc(sizeof(struct autofs_wait_queue), GFP_KERNEL);
if ( !wq ) {
kfree(name);
up(&sbi->wq_sem);
return -ENOMEM;
}
...
wq->name = name;
...
} else {
atomic_inc(&wq->wait_ctr);
up(&sbi->wq_sem);
...
}
In the else clause, we forget to free the name we kmalloc'd above. This is
pretty easy to trigger with the following reproducer:
setup an automount map as follows:
for n in `seq 1 48`; do echo "$n server:/export/$n" >> /etc/auto.test; done
setup a master map entry to point at this:
echo "/test /etc/auto.test --timeout=1" >> /etc/auto.master
Now, assuming the nfs server was setup to export said directories, run the
following shell script in two xterms:
#!/bin/sh
while true; do
for n in `seq 1 48`; do
ls /test/$n
done
sleep 2
done
and watch the size-256 slab cache grow
Within 4 minutes, I had the size-256 cache grow to 384k. On a kernel with
the below patch applied, the size-256 remained constant during an over-night
run.
The patch is against linux-2.6.9, but it applies to 2.6.11, as well.
-Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
[-- Attachment #2: linux-2.6.9-autofs-mem-leak.patch --]
[-- Type: text/plain, Size: 422 bytes --]
--- linux-2.6.9/fs/autofs4/waitq.c.orig 2005-03-03 17:09:11.534047192 -0500
+++ linux-2.6.9/fs/autofs4/waitq.c 2005-03-03 17:09:21.777489952 -0500
@@ -224,6 +224,7 @@ int autofs4_wait(struct autofs_sb_info *
} else {
atomic_inc(&wq->wait_ctr);
up(&sbi->wq_sem);
+ kfree(name);
DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
(unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
}
next reply other threads:[~2005-03-04 15:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-04 15:48 Jeff Moyer [this message]
2005-03-07 8:15 ` raven
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=16936.33587.974061.237160@segfault.boston.redhat.com \
--to=jmoyer@redhat.com \
--cc=autofs@linux.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=raven@themaw.net \
/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
all inboxes | Powered by JetHome®