From: ebiederm@xmission.com (Eric W. Biederman)
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] exit: move exit_task_namespaces() after exit_task_work()
Date: Fri, 15 Dec 2017 00:56:40 -0600 [thread overview]
Message-ID: <87efnwcwd3.fsf@xmission.com> (raw)
In-Reply-To: <20171214201757.5393-1-xiyou.wangcong@gmail.com> (Cong Wang's message of "Thu, 14 Dec 2017 12:17:57 -0800")
Cong Wang <xiyou.wangcong@gmail.com> writes:
> syzbot reported we have a use-after-free when mqueue_evict_inode()
> is called on __cleanup_mnt() path, where the ipc ns is already
> freed by the previous exit_task_namespaces(). We can just move
> it after after exit_task_work() to avoid this use-after-free.
How does that possibly work. (I haven't seen this syzbot report).
Looking at the code we have get_ns_from_inode. Which takes the mq_lock,
sees if the pointer is NULL and takes a reference if it is non-NULL.
Meanwhile put_ipc_ns calls mq_clear_sbinfo(ns) with the mq_lock held
when the count drops to zero.
Where is the race in that?
The rest of mqueue_evict_inode uses the returned pointer and
tests that the pointer is non-NULL before user it.
So either szbot is giving you a bad report or there is a subtle race
there I am not seeing. The change below is not at all the proper way to
fix a subtle race.
Eric
>
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> kernel/exit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 6b4298a41167..909e43c45158 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -861,8 +861,8 @@ void __noreturn do_exit(long code)
> exit_fs(tsk);
> if (group_dead)
> disassociate_ctty(1);
> - exit_task_namespaces(tsk);
> exit_task_work(tsk);
> + exit_task_namespaces(tsk);
> exit_thread(tsk);
>
> /*
next prev parent reply other threads:[~2017-12-15 6:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-14 20:17 [PATCH] exit: move exit_task_namespaces() after exit_task_work() Cong Wang
2017-12-14 21:08 ` Al Viro
2017-12-15 23:59 ` Cong Wang
2017-12-16 22:04 ` Giuseppe Scrivano
2017-12-15 6:56 ` Eric W. Biederman [this message]
2017-12-15 7:35 ` Dmitry Vyukov
2017-12-15 8:00 ` Dmitry Vyukov
2017-12-16 0:00 ` Cong Wang
2017-12-16 7:40 ` Dmitry Vyukov
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=87efnwcwd3.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xiyou.wangcong@gmail.com \
/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.