From: pmeda@akamai.com
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] mempool: protect buffer overflow in mempool_resize
Date: Tue, 15 Feb 2005 11:47:43 -0800 [thread overview]
Message-ID: <200502151947.LAA20729@allur.sanmateo.akamai.com> (raw)
1. Race in mempool_resize: memcpy can copy at the end of the kmalloced elements.
2. when new_min_nr is same as min_nr, instead of reallocate and copy, just return,
changed '<' to '<='.
3. Changed while condition to the same sense of if condition from '>' to '<'; it is
easy to think with only one of the left and right brains at a time.
Signed-off-by: Prasanna Meda <pmeda@akamai.com>
--- Linux/mm/mempool.c Mon Feb 14 23:03:00 2005
+++ linux/mm/mempool.c Mon Feb 14 23:03:04 2005
@@ -114,8 +114,8 @@
BUG_ON(new_min_nr <= 0);
spin_lock_irqsave(&pool->lock, flags);
- if (new_min_nr < pool->min_nr) {
- while (pool->curr_nr > new_min_nr) {
+ if (new_min_nr <= pool->min_nr) {
+ while (new_min_nr < pool->curr_nr) {
element = remove_element(pool);
spin_unlock_irqrestore(&pool->lock, flags);
pool->free(element, pool->pool_data);
@@ -132,6 +132,12 @@
return -ENOMEM;
spin_lock_irqsave(&pool->lock, flags);
+ if (unlikely(new_min_nr <= pool->min_nr)) {
+ /* Raced, other resize will do our work */
+ spin_unlock_irqrestore(&pool->lock, flags);
+ kfree(new_elements);
+ goto out;
+ }
memcpy(new_elements, pool->elements,
pool->curr_nr * sizeof(*new_elements));
kfree(pool->elements);
@@ -149,7 +155,7 @@
} else {
spin_unlock_irqrestore(&pool->lock, flags);
pool->free(element, pool->pool_data); /* Raced */
- spin_lock_irqsave(&pool->lock, flags);
+ goto out;
}
}
out_unlock:
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>
reply other threads:[~2005-02-15 19:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=200502151947.LAA20729@allur.sanmateo.akamai.com \
--to=pmeda@akamai.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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