public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Matthew Wilcox <willy@infradead.org>
Cc: Jia-Ju Bai <baijiaju1990@gmail.com>,
	paul@paul-moore.com, eparis@redhat.com, jack@suse.cz,
	amir73il@gmail.com, linux-audit@redhat.com,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] kernel: audit_tree: Fix a sleep-in-atomic-context bug
Date: Fri, 22 Jun 2018 11:23:40 +0200	[thread overview]
Message-ID: <20180622092340.dzl2ea7tdkjdkdhg@quack2.suse.cz> (raw)
In-Reply-To: <20180621042912.GA4967@bombadil.infradead.org>

On Wed 20-06-18 21:29:12, Matthew Wilcox wrote:
> On Thu, Jun 21, 2018 at 11:32:45AM +0800, Jia-Ju Bai wrote:
> > The kernel may sleep with holding a spinlock.
> > The function call paths (from bottom to top) in Linux-4.16.7 are:
> > 
> > [FUNC] kmem_cache_alloc(GFP_KERNEL)
> > fs/notify/mark.c, 439: 
> > 		kmem_cache_alloc in fsnotify_attach_connector_to_object
> > fs/notify/mark.c, 520: 
> > 		fsnotify_attach_connector_to_object in fsnotify_add_mark_list
> > fs/notify/mark.c, 590: 
> > 		fsnotify_add_mark_list in fsnotify_add_mark_locked
> > kernel/audit_tree.c, 437: 
> > 		fsnotify_add_mark_locked in tag_chunk
> > kernel/audit_tree.c, 423: 
> > 		spin_lock in tag_chunk
> 
> There are several locks here; your report would be improved by saying
> which one is the problem.  I'm assuming it's old_entry->lock.
> 
>         spin_lock(&old_entry->lock);
> ...
>         if (fsnotify_add_inode_mark_locked(chunk_entry,
>                              old_entry->connector->inode, 1)) {
> ...
>         return fsnotify_add_mark_locked(mark, inode, NULL, allow_dups);
> ...
>         ret = fsnotify_add_mark_list(mark, inode, mnt, allow_dups);
> ...
>         if (inode)
>                 connp = &inode->i_fsnotify_marks;
>         conn = fsnotify_grab_connector(connp);
>         if (!conn) {
>                 err = fsnotify_attach_connector_to_object(connp, inode, mnt);
> 
> It seems to me that this is safe because old_entry is looked up from
> fsnotify_find_mark, and it can't be removed while its lock is held.
> Therefore there's always a 'conn' returned from fsnotify_grab_connector(),
> and so this path will never be taken.
> 
> But this code path is confusing to me, and I could be wrong.  Jan, please
> confirm my analysis is correct?

Yes, you are correct. The presence of another mark in the list (and the
fact we pin it there using refcount & mark_mutex) guarantees we won't need
to allocate the connector. I agree the audit code's use of fsnotify would
deserve some cleanup.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2018-06-22  9:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21  3:32 [PATCH] kernel: audit_tree: Fix a sleep-in-atomic-context bug Jia-Ju Bai
2018-06-21  4:29 ` Matthew Wilcox
2018-06-22  9:23   ` Jan Kara [this message]
2018-06-22 18:56     ` Paul Moore
2018-06-25  9:22       ` Jan Kara
2018-06-25 12:55         ` Jan Kara
2018-06-25 22:25         ` Paul Moore

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=20180622092340.dzl2ea7tdkjdkdhg@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=eparis@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@paul-moore.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