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] [day] [month] [year] [list]
Date:   Tue, 2 May 2023 10:39:47 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Jan Kara <jack@...e.cz>
Cc:     "Kirill A . Shutemov" <kirill@...temov.name>,
        David Hildenbrand <david@...hat.com>,
        Peter Xu <peterx@...hat.com>,
        Lorenzo Stoakes <lstoakes@...il.com>,
        Jason Gunthorpe <jgg@...dia.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org,
        Andrew Morton <akpm@...ux-foundation.org>,
        Jens Axboe <axboe@...nel.dk>,
        Matthew Wilcox <willy@...radead.org>,
        Dennis Dalessandro <dennis.dalessandro@...nelisnetworks.com>,
        Leon Romanovsky <leon@...nel.org>,
        Christian Benvenuti <benve@...co.com>,
        Nelson Escobar <neescoba@...co.com>,
        Bernard Metzler <bmt@...ich.ibm.com>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Bjorn Topel <bjorn@...nel.org>,
        Magnus Karlsson <magnus.karlsson@...el.com>,
        Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
        Jonathan Lemon <jonathan.lemon@...il.com>,
        "David S . Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Christian Brauner <brauner@...nel.org>,
        Richard Cochran <richardcochran@...il.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Jesper Dangaard Brouer <hawk@...nel.org>,
        John Fastabend <john.fastabend@...il.com>,
        linux-fsdevel@...r.kernel.org, linux-perf-users@...r.kernel.org,
        netdev@...r.kernel.org, bpf@...r.kernel.org,
        Oleg Nesterov <oleg@...hat.com>,
        John Hubbard <jhubbard@...dia.com>,
        Pavel Begunkov <asml.silence@...il.com>,
        Mika Penttila <mpenttil@...hat.com>,
        David Howells <dhowells@...hat.com>,
        Christoph Hellwig <hch@....de>
Subject: Re: [PATCH v5] mm/gup: disallow GUP writing to file-backed mappings
 by default

On Tue, May 02, 2023 at 10:00:16AM +0200, Jan Kara wrote:
> On Sat 29-04-23 02:43:32, Kirill A . Shutemov wrote:
> > I think I found relevant snippet of code that solves similar issue.
> > get_futex_key() uses RCU to stabilize page->mapping after GUP_fast:
> > 
> > 
> > 		/*
> > 		 * The associated futex object in this case is the inode and
> > 		 * the page->mapping must be traversed. Ordinarily this should
> > 		 * be stabilised under page lock but it's not strictly
> > 		 * necessary in this case as we just want to pin the inode, not
> > 		 * update the radix tree or anything like that.
> > 		 *
> > 		 * The RCU read lock is taken as the inode is finally freed
> > 		 * under RCU. If the mapping still matches expectations then the
> > 		 * mapping->host can be safely accessed as being a valid inode.
> > 		 */
> > 		rcu_read_lock();
> > 
> > 		if (READ_ONCE(page->mapping) != mapping) {
> > 			rcu_read_unlock();
> > 			put_page(page);
> > 
> > 			goto again;
> > 		}
> > 
> > 		inode = READ_ONCE(mapping->host);
> > 		if (!inode) {
> > 			rcu_read_unlock();
> > 			put_page(page);
> > 
> > 			goto again;
> > 		}
> > 
> > I think something similar can be used inside GUP_fast too.
> 
> Yeah, inodes (and thus struct address_space) is RCU protected these days so
> grabbing RCU lock in gup_fast() will get you enough protection for checking
> aops if you are careful (like the futex code is).

GUP_fast has IRQs disabled per definition, there is no need to then also
use rcu_read_lock().

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ