From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: dwmw2@infradead.org
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] fs: jffs2: fix a sleep-in-atomic-context bug in jffs2_alloc_refblock()
Date: Mon, 13 Aug 2018 11:25:47 +0800 [thread overview]
Message-ID: <20180813032547.3156-1-baijiaju1990@gmail.com> (raw)
The kernel may sleep with holding a spin lock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC] kmem_cache_alloc(GFP_KERNEL)
fs/jffs2/malloc.c, 188:
kmem_cache_alloc in jffs2_alloc_refblock
fs/jffs2/malloc.c, 221:
jffs2_alloc_refblock in jffs2_prealloc_raw_node_refs
fs/jffs2/wbuf.c, 164:
jffs2_prealloc_raw_node_refs in jffs2_block_refile
fs/jffs2/wbuf.c, 927:
jffs2_block_refile in jffs2_flash_writev
fs/jffs2/wbuf.c, 924:
spin_lock in jffs2_flash_writev
To fix it, GFP_KERNEL in kmem_cache_alloc() is replaced with GFP_ATOMIC.
This is found by my static analysis tool (DSAC).
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
fs/jffs2/malloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
index ce1189793288..66496ef09716 100644
--- a/fs/jffs2/malloc.c
+++ b/fs/jffs2/malloc.c
@@ -185,7 +185,7 @@ static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
{
struct jffs2_raw_node_ref *ret;
- ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
+ ret = kmem_cache_alloc(raw_node_ref_slab, GFP_ATOMIC);
if (ret) {
int i = 0;
for (i=0; i < REFS_PER_BLOCK; i++) {
--
2.17.0
reply other threads:[~2018-08-13 3:26 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=20180813032547.3156-1-baijiaju1990@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.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).