From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Qian Cai <cai@lca.pw>
Cc: Andrew Morton <akpm@linux-foundation.org>,
elver@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, peterz@infradead.org,
syzbot+c034966b0b02f94f7f34@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH -next] fork: annotate a data race in vm_area_dup()
Date: Tue, 18 Feb 2020 13:30:02 +0300 [thread overview]
Message-ID: <20200218103002.6rtjreyqjepo3yxe@box> (raw)
In-Reply-To: <EAD6E54D-8A57-4494-94F2-2EEEC3265560@lca.pw>
On Mon, Feb 17, 2020 at 10:59:47PM -0500, Qian Cai wrote:
>
>
> > On Feb 17, 2020, at 5:31 PM, Kirill A. Shutemov <kirill@shutemov.name> wrote:
> >
> > I'm confused. AFAICS both sides hold mmap_sem on write:
> >
> > - vm_mmap_pgoff() takes mmap_sem for the write on the write side
> >
> > - do_mprotect_pkey() takes mmap_sem for the write on the read side
> >
> >
> > What do I miss?
>
> Ah, good catch. I missed the locking for the read there. This is interesting because Marco
> did confirmed that the concurrency could happen,
>
> https://lore.kernel.org/lkml/20191025173511.181416-1-elver@google.com/
>
> If that means KCSAN is not at fault, then I could think of two things,
>
> 1) someone downgrades the lock.
>
> I don’t think that a case here. Only __do_munmap() will do that but I did not see how
> it will affect us here.
>
> 2) the reader and writer are two different processes.
>
> So, they held a different mmap_sem, but I can’t see how could two processes shared
> the same vm_area_struct. Also, file->f_mapping->i_mmap was also stored in the
> writer, but I can’t see how it was also loaded in the reader.
>
> Any ideas?
I think I've got this:
vm_area_dup() blindly copies all fields of orignal VMA to the new one.
This includes coping vm_area_struct::shared.rb which is normally protected
by i_mmap_lock. But this is fine because the read value will be
overwritten on the following __vma_link_file() under proper protectection.
So the fix is correct, but justificaiton is lacking.
Also, I would like to more fine-grained annotation: marking with
data_race() 200 bytes copy may hide other issues.
--
Kirill A. Shutemov
next prev parent reply other threads:[~2020-02-18 10:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 20:33 [PATCH -next] fork: annotate a data race in vm_area_dup() Qian Cai
2020-02-17 22:31 ` Kirill A. Shutemov
2020-02-18 3:59 ` Qian Cai
2020-02-18 10:30 ` Kirill A. Shutemov [this message]
2020-02-18 12:40 ` Qian Cai
2020-02-18 14:09 ` Marco Elver
2020-02-18 15:00 ` Qian Cai
2020-02-18 15:18 ` Kirill A. Shutemov
2020-02-18 16:46 ` Qian Cai
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=20200218103002.6rtjreyqjepo3yxe@box \
--to=kirill@shutemov.name \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=syzbot+c034966b0b02f94f7f34@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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;
as well as URLs for NNTP newsgroup(s).