All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Jia-Ju Bai <baijiaju1990@163.com>
Cc: torbjorn.lindh@gopta.se, rgooch@atnf.csiro.au,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [BUG] fs/super: a possible sleep-in-atomic bug in put_super
Date: Fri, 6 Oct 2017 13:19:30 +0100	[thread overview]
Message-ID: <20171006121930.GL21978@ZenIV.linux.org.uk> (raw)
In-Reply-To: <06badf5e-292d-ef63-7499-6888dec1b9b0@163.com>

On Fri, Oct 06, 2017 at 04:59:18PM +0800, Jia-Ju Bai wrote:
> According to fs/super.c, the kernel may sleep under a spinlock.
> The function call path is:
> put_super (acquire the spinlock)
>   __put_super
>     destroy_super
>       list_lru_destroy
>         list_lru_unregister
>           mutex_lock --> may sleep
>         memcg_get_cache_ids
>           down_read --> may sleep
> 
> This bug is found by my static analysis tool and my code review.

Invariant to watch is this: s->s_active > 0 => s->s_count > 0.  In other
words, anything that passes from __put_super() to destroy_super() has
already been through deactivate_locked_super() to list_lru_destroy().

And list_lru_destroy() called twice without list_lru_init() between
those will quietly do nothing on the second call.

All other callers of destroy_super() are from alloc_super()/sget_userns().
The former is the only place where instances are created, the latter is
the only caller of the former.  Direct calls of destroy_super() in there
	a) happen only to instances that had not been visible in any
shared data structures yet and
	b) are done with no spinlocks held.

struct super_block has probably the most complex lifecycle in the entire VFS.
These days the nastiness is fortunately limited to fs/super.c guts, but
it's very definitely still there.  I've posted sketches of description on
fsdevel several times, but never managed to turn that into coherent text ;-/

      parent reply	other threads:[~2017-10-06 12:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06  8:59 [BUG] fs/super: a possible sleep-in-atomic bug in put_super Jia-Ju Bai
2017-10-06  9:06 ` Michal Hocko
2017-10-07 11:56   ` Vladimir Davydov
2017-10-07 17:06     ` Al Viro
2017-10-07 21:14       ` Al Viro
2017-10-08  0:56         ` Al Viro
2017-10-08  2:03           ` Al Viro
2017-10-08 15:47             ` Vladimir Davydov
2017-10-08 21:13               ` Al Viro
2017-10-09  8:43                 ` Vladimir Davydov
2017-10-06 12:19 ` Al Viro [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=20171006121930.GL21978@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=baijiaju1990@163.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rgooch@atnf.csiro.au \
    --cc=torbjorn.lindh@gopta.se \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.