linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Philippe Ombredanne <pombredanne@nexb.com>,
	Linux-MM <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm: mempool: Fix a possible sleep-in-atomic-context bug in mempool_resize()
Date: Thu, 21 Jun 2018 07:54:18 +0200	[thread overview]
Message-ID: <CACT4Y+avpKvoRKUsoZ=VUiN79RVEJAtzOCgkz0ZXRLFL4fSCbg@mail.gmail.com> (raw)
In-Reply-To: <7a900944-5281-2e07-54f9-fc7574d2c538@gmail.com>

On Thu, Jun 21, 2018 at 5:46 AM, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> On 2018/6/21 11:38, Matthew Wilcox wrote:
>>
>> On Thu, Jun 21, 2018 at 11:07:14AM +0800, Jia-Ju Bai wrote:
>>>
>>> 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.
>>
>> But ... we don't use the flags argument.
>>
>> static void *remove_element(mempool_t *pool, gfp_t flags)
>> {
>>          void *element = pool->elements[--pool->curr_nr];
>>
>>          BUG_ON(pool->curr_nr < 0);
>>          kasan_unpoison_element(pool, element, flags);
>>          check_element(pool, element);
>>          return element;
>> }
>>
>> ...
>>
>> static void kasan_unpoison_element(mempool_t *pool, void *element, gfp_t
>> flags)
>> {
>>          if (pool->alloc == mempool_alloc_slab || pool->alloc ==
>> mempool_kmalloc)
>>                  kasan_unpoison_slab(element);
>>          if (pool->alloc == mempool_alloc_pages)
>>                  kasan_alloc_pages(element, (unsigned
>> long)pool->pool_data);
>> }
>>
>> So the correct patch would just remove this argument to remove_element()
>> and
>> kasan_unpoison_element()?
>
>
> Yes, I also find this.
> I can submit a patch that removes the flag in:
> Definitions of kasan_unpoison_element() and remove_element()
> Three calls to remove_element() and one call to kasan_unpoison_element() in
> mempool.c.
>
> Do you think it is okay?

Hi Jia-Ju,

Removing an unused argument within a single file looks good to me.

      reply	other threads:[~2018-06-21  5:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21  3:07 Jia-Ju Bai
2018-06-21  3:38 ` Matthew Wilcox
2018-06-21  3:46   ` Jia-Ju Bai
2018-06-21  5:54     ` Dmitry Vyukov [this message]

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='CACT4Y+avpKvoRKUsoZ=VUiN79RVEJAtzOCgkz0ZXRLFL4fSCbg@mail.gmail.com' \
    --to=dvyukov@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=baijiaju1990@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jthumshirn@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pombredanne@nexb.com \
    --cc=willy@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