From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: akpm@linux-foundation.org, dvyukov@google.com,
gregkh@linuxfoundation.org, jthumshirn@suse.de,
pombredanne@nexb.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] mm: mempool: Fix a possible sleep-in-atomic-context bug in mempool_resize()
Date: Thu, 21 Jun 2018 11:07:14 +0800 [thread overview]
Message-ID: <20180621030714.10368-1-baijiaju1990@gmail.com> (raw)
The kernel may sleep with holding a spinlock.
The function call path (from bottom to top) in Linux-4.16.7 is:
[FUNC] remove_element(GFP_KERNEL)
mm/mempool.c, 250: remove_element in mempool_resize
mm/mempool.c, 247: _raw_spin_lock_irqsave in mempool_resize
To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.
This bug is found by my static analysis tool (DSAC-2) and checked by
my code review.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
mm/mempool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mempool.c b/mm/mempool.c
index 5c9dce34719b..d33bd5d622e7 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -247,7 +247,7 @@ int mempool_resize(mempool_t *pool, int new_min_nr)
spin_lock_irqsave(&pool->lock, flags);
if (new_min_nr <= pool->min_nr) {
while (new_min_nr < pool->curr_nr) {
- element = remove_element(pool, GFP_KERNEL);
+ element = remove_element(pool, GFP_ATOMIC);
spin_unlock_irqrestore(&pool->lock, flags);
pool->free(element, pool->pool_data);
spin_lock_irqsave(&pool->lock, flags);
--
2.17.0
next reply other threads:[~2018-06-21 3:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 3:07 Jia-Ju Bai [this message]
2018-06-21 3:38 ` Matthew Wilcox
2018-06-21 3:46 ` Jia-Ju Bai
2018-06-21 5:54 ` Dmitry Vyukov
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=20180621030714.10368-1-baijiaju1990@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jthumshirn@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pombredanne@nexb.com \
/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