lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1911213.F1gzGJjR86@nvdebian>
Date:   Wed, 19 May 2021 22:46:14 +1000
From:   Alistair Popple <apopple@...dia.com>
To:     Peter Xu <peterx@...hat.com>
CC:     <linux-mm@...ck.org>, <nouveau@...ts.freedesktop.org>,
        <bskeggs@...hat.com>, <akpm@...ux-foundation.org>,
        <linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <dri-devel@...ts.freedesktop.org>, <jhubbard@...dia.com>,
        <rcampbell@...dia.com>, <jglisse@...hat.com>, <jgg@...dia.com>,
        <hch@...radead.org>, <daniel@...ll.ch>, <willy@...radead.org>,
        <bsingharora@...il.com>, Christoph Hellwig <hch@....de>
Subject: Re: [PATCH v8 5/8] mm: Device exclusive memory access

On Wednesday, 19 May 2021 10:24:27 PM AEST Peter Xu wrote:
> External email: Use caution opening links or attachments
> 
> On Wed, May 19, 2021 at 08:49:01PM +1000, Alistair Popple wrote:
> > On Wednesday, 19 May 2021 7:16:38 AM AEST Peter Xu wrote:
> > > External email: Use caution opening links or attachments
> > > 
> > > 
> > > On Wed, Apr 07, 2021 at 06:42:35PM +1000, Alistair Popple wrote:
> > > 
> > > [...]
> > > 
> > > > +static bool try_to_protect(struct page *page, struct mm_struct *mm,
> > > > +                        unsigned long address, void *arg)
> > > > +{
> > > > +     struct ttp_args ttp = {
> > > > +             .mm = mm,
> > > > +             .address = address,
> > > > +             .arg = arg,
> > > > +             .valid = false,
> > > > +     };
> > > > +     struct rmap_walk_control rwc = {
> > > > +             .rmap_one = try_to_protect_one,
> > > > +             .done = page_not_mapped,
> > > > +             .anon_lock = page_lock_anon_vma_read,
> > > > +             .arg = &ttp,
> > > > +     };
> > > > +
> > > > +     /*
> > > > +      * Restrict to anonymous pages for now to avoid potential
> > > > writeback
> > > > +      * issues.
> > > > +      */
> > > > +     if (!PageAnon(page))
> > > > +             return false;
> > > > +
> > > > +     /*
> > > > +      * During exec, a temporary VMA is setup and later moved.
> > > > +      * The VMA is moved under the anon_vma lock but not the
> > > > +      * page tables leading to a race where migration cannot
> > > > +      * find the migration ptes. Rather than increasing the
> > > > +      * locking requirements of exec(), migration skips
> > > > +      * temporary VMAs until after exec() completes.
> > > > +      */
> > > > +     if (!PageKsm(page) && PageAnon(page))
> > > > +             rwc.invalid_vma = invalid_migration_vma;
> > > > +
> > > > +     rmap_walk(page, &rwc);
> > > > +
> > > > +     return ttp.valid && !page_mapcount(page);
> > > > +}
> > > 
> > > I raised a question in the other thread regarding fork():
> > > 
> > > https://lore.kernel.org/lkml/YKQjmtMo+YQGx%2FwZ@t490s/
> > > 
> > > While I suddenly noticed that we may have similar issues even if we
> > > fork()
> > > before creating the ptes.
> > > 
> > > In that case, we may see multiple read-only ptes pointing to the same
> > > page.
> > > We will convert all of them into device exclusive read ptes in
> > > rmap_walk()
> > > above, however how do we guarantee after all COW done in the parent and
> > > all
> > > the childs processes, the device owned page will be returned to the
> > > parent?
> > 
> > I assume you are talking about a fork() followed by a call to
> > make_device_exclusive()? I think this should be ok because
> > make_device_exclusive() always calls GUP with FOLL_WRITE both to break COW
> > and because a device performing atomic operations needs to write to the
> > page. I suppose a comment here highlighting the need to break COW to
> > avoid this scenario would be useful though.
> 
> Indeed, sorry for the false alarm!  Yes it would be great to mention that
> too.

No problem! Thanks for the comments.

> --
> Peter Xu




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ