From: ebiederm@xmission.com (Eric W. Biederman)
To: Filippo Sironi <sironi@amazon.de>
Cc: <linux-kernel@vger.kernel.org>, <dwmw@amazon.co.uk>,
<christian.brauner@ubuntu.com>, <akpm@linux-foundation.org>,
<peterz@infradead.org>, <keescook@chromium.org>,
<krisman@collabora.com>, <peterx@redhat.com>, <axboe@kernel.dk>,
<surenb@google.com>, <shakeelb@google.com>, <guro@fb.com>,
<elver@google.com>
Subject: Re: [RFC PATCH] mm: fork: Prevent a NULL deref by getting mm only if the refcount isn't 0
Date: Wed, 10 Mar 2021 11:09:58 -0600 [thread overview]
Message-ID: <m1pn07rl3t.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <20210310123703.27894-1-sironi@amazon.de> (Filippo Sironi's message of "Wed, 10 Mar 2021 13:37:02 +0100")
Filippo Sironi <sironi@amazon.de> writes:
> We've seen a number of crashes with the following signature:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> #PF: supervisor read access in kernel mode
> #PF: error_code(0x0000) - not-present page
> ...
> Oops: 0000 [#1] SMP PTI
> ...
> RIP: 0010:__rb_erase_color+0xc2/0x260
> ...
> Call Trace:
> unlink_file_vma+0x36/0x50
> free_pgtables+0x62/0x110
> exit_mmap+0xd5/0x160
> ? put_dec+0x3a/0x90
> ? num_to_str+0xa8/0xc0
> mmput+0x11/0xb0
> do_task_stat+0x940/0xc80
> proc_single_show+0x49/0x80
> ? __check_object_size+0xcc/0x1a0
> seq_read+0xd3/0x400
> vfs_read+0x72/0xb0
> ksys_read+0x9c/0xd0
> do_syscall_64+0x69/0x400
> ? schedule+0x2a/0x90
> entry_SYSCALL_64_after_hwframe+0x44/0xa9
> ...
>
> This happens when a process goes through the tasks stats in procfs while
> another is exiting. This looks like a race where the process that's
> exiting drops the last reference on the mm (with mmput) while the other
> increases it (with mmget). By only increasing when the reference isn't
> 0 to begin with, we prevent this from happening.
For this to be a race with exit this would require racing with exit_mm
where current->mm is cleared.
Looking at exit_mm() the code does:
struct mm_struct *mm = current->mm;
mmap_read_lock(mm);
mmgrab(mm);
task_lock(current);
local_irq_disable();
current->mm = NULL;
local_irq_enable();
task_unlock(current);
mmap_read_unlock(mm);
mmput(mm);
Which seems to guarantee "mm_users > 0" if "task->mm != NULL" under
tasklist_lock.
So I suggest you instrument your failing kernels and find what is
improperly decrementing mm_users.
Eric
prev parent reply other threads:[~2021-03-10 17:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-10 12:37 [RFC PATCH] mm: fork: Prevent a NULL deref by getting mm only if the refcount isn't 0 Filippo Sironi
2021-03-10 15:57 ` Jens Axboe
2021-03-10 17:09 ` Eric W. Biederman [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=m1pn07rl3t.fsf@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=christian.brauner@ubuntu.com \
--cc=dwmw@amazon.co.uk \
--cc=elver@google.com \
--cc=guro@fb.com \
--cc=keescook@chromium.org \
--cc=krisman@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=shakeelb@google.com \
--cc=sironi@amazon.de \
--cc=surenb@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox