linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode
@ 2017-06-05  3:38 Jia-Ju Bai
  2017-06-05  8:25 ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Jia-Ju Bai @ 2017-06-05  3:38 UTC (permalink / raw)
  To: richard, dedekind1; +Cc: linux-mtd, linux-kernel, Jia-Ju Bai

The driver may sleep under a spin lock, and the function call path is:
ubifs_change_lp (acquire the lock by spin_lock)
  change_category
    ubifs_remove_from_cat
      remove_from_lpt_heap
        dbg_check_heap
          ubifs_lpt_lookup
            ubifs_read_nnode
              kzalloc(GFP_NOFS) --> may sleep

To fix it, "GFP_NOFS" is replaced with "GFP_ATOMIC".

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 fs/ubifs/lpt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 9a51710..4247934c 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -1205,7 +1205,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
 		lnum = c->lpt_lnum;
 		offs = c->lpt_offs;
 	}
-	nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_NOFS);
+	nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_ATOMIC);
 	if (!nnode) {
 		err = -ENOMEM;
 		goto out;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode
  2017-06-05  3:38 [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode Jia-Ju Bai
@ 2017-06-05  8:25 ` Richard Weinberger
  2017-06-05  8:39   ` Richard Weinberger
  2017-06-05  8:43   ` Jia-Ju Bai
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Weinberger @ 2017-06-05  8:25 UTC (permalink / raw)
  To: Jia-Ju Bai, dedekind1; +Cc: linux-mtd, linux-kernel

Jia-Ju Bai,

Am 05.06.2017 um 05:38 schrieb Jia-Ju Bai:
> The driver may sleep under a spin lock, and the function call path is:
> ubifs_change_lp (acquire the lock by spin_lock)
>   change_category
>     ubifs_remove_from_cat
>       remove_from_lpt_heap
>         dbg_check_heap
>           ubifs_lpt_lookup
>             ubifs_read_nnode
>               kzalloc(GFP_NOFS) --> may sleep
> 
> To fix it, "GFP_NOFS" is replaced with "GFP_ATOMIC".

So, this happens only when dbg_check_heap() is activated, right?

Thanks,
//richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode
  2017-06-05  8:25 ` Richard Weinberger
@ 2017-06-05  8:39   ` Richard Weinberger
  2017-06-05  8:43   ` Jia-Ju Bai
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Weinberger @ 2017-06-05  8:39 UTC (permalink / raw)
  To: Jia-Ju Bai, dedekind1; +Cc: linux-mtd, linux-kernel

Am 05.06.2017 um 10:25 schrieb Richard Weinberger:
> Jia-Ju Bai,
> 
> Am 05.06.2017 um 05:38 schrieb Jia-Ju Bai:
>> The driver may sleep under a spin lock, and the function call path is:
>> ubifs_change_lp (acquire the lock by spin_lock)
>>   change_category
>>     ubifs_remove_from_cat
>>       remove_from_lpt_heap
>>         dbg_check_heap
>>           ubifs_lpt_lookup
>>             ubifs_read_nnode
>>               kzalloc(GFP_NOFS) --> may sleep
>>
>> To fix it, "GFP_NOFS" is replaced with "GFP_ATOMIC".
> 
> So, this happens only when dbg_check_heap() is activated, right?

Why do we call change_category() anyway with c->space_lock held?

Thanks,
//richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode
  2017-06-05  8:25 ` Richard Weinberger
  2017-06-05  8:39   ` Richard Weinberger
@ 2017-06-05  8:43   ` Jia-Ju Bai
  1 sibling, 0 replies; 4+ messages in thread
From: Jia-Ju Bai @ 2017-06-05  8:43 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: dedekind1, linux-mtd, linux-kernel

On 06/05/2017 04:25 PM, Richard Weinberger wrote:
> Jia-Ju Bai,
>
> Am 05.06.2017 um 05:38 schrieb Jia-Ju Bai:
>> The driver may sleep under a spin lock, and the function call path is:
>> ubifs_change_lp (acquire the lock by spin_lock)
>>    change_category
>>      ubifs_remove_from_cat
>>        remove_from_lpt_heap
>>          dbg_check_heap
>>            ubifs_lpt_lookup
>>              ubifs_read_nnode
>>                kzalloc(GFP_NOFS) -->  may sleep
>>
>> To fix it, "GFP_NOFS" is replaced with "GFP_ATOMIC".
> So, this happens only when dbg_check_heap() is activated, right?
>
> Thanks,
> //richard
Yes, I think so.

Thanks,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-05  8:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05  3:38 [PATCH] ubifs: Fix a sleep-in-atomic bug in ubifs_read_nnode Jia-Ju Bai
2017-06-05  8:25 ` Richard Weinberger
2017-06-05  8:39   ` Richard Weinberger
2017-06-05  8:43   ` Jia-Ju Bai

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).