[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200218103002.6rtjreyqjepo3yxe@box>
Date: Tue, 18 Feb 2020 13:30:02 +0300
From: "Kirill A. Shutemov" <kirill@...temov.name>
To: Qian Cai <cai@....pw>
Cc: Andrew Morton <akpm@...ux-foundation.org>, elver@...gle.com,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
peterz@...radead.org,
syzbot+c034966b0b02f94f7f34@...kaller.appspotmail.com,
syzkaller-bugs@...glegroups.com
Subject: Re: [PATCH -next] fork: annotate a data race in vm_area_dup()
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@...temov.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
Powered by blists - more mailing lists