From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 763B3C433F5 for ; Tue, 19 Apr 2022 15:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354127AbiDSP7h (ORCPT ); Tue, 19 Apr 2022 11:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351075AbiDSP7g (ORCPT ); Tue, 19 Apr 2022 11:59:36 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C41FC237D8 for ; Tue, 19 Apr 2022 08:56:53 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4FBF11F746; Tue, 19 Apr 2022 15:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1650383812; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtGb0B+xVaMUOR9TH3eGpGH3Rm/fFjg1NOhtMi5AUB0=; b=Q4gR8e9hF6R1WIxUXQa0AxU+tadg5Q0S/b//sEZCC6M3Qbe5z0t/+XAsNHDN05NA9tWM0f KvxuWeIhgaiWW1ydLDdLU4qx/GnAJv+aPGMkK2kEgQHMMRgB1YrBGuiz/806L2xDMDgFKx qLTrAYARB252gd04IozSIo3UEvEQDBc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1650383812; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtGb0B+xVaMUOR9TH3eGpGH3Rm/fFjg1NOhtMi5AUB0=; b=GsmktdgmvEF9My+EljUH0wy6tjAUH8F2AFdXn7ez/QNin50kfMzEoavOW1TiGFFeRHTjDV bUvOVXm95E9hiuBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D649B139BE; Tue, 19 Apr 2022 15:56:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id REqfM8PbXmLyRQAAMHmgww (envelope-from ); Tue, 19 Apr 2022 15:56:51 +0000 Message-ID: Date: Tue, 19 Apr 2022 17:56:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v3 15/16] mm/gup: trigger FAULT_FLAG_UNSHARE when R/O-pinning a possibly shared anonymous page Content-Language: en-US To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Pedro Gomes , Oded Gabbay , linux-mm@kvack.org References: <20220329160440.193848-1-david@redhat.com> <20220329160440.193848-16-david@redhat.com> From: Vlastimil Babka In-Reply-To: <20220329160440.193848-16-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/29/22 18:04, David Hildenbrand wrote: > Whenever GUP currently ends up taking a R/O pin on an anonymous page that > might be shared -- mapped R/O and !PageAnonExclusive() -- any write fault > on the page table entry will end up replacing the mapped anonymous page > due to COW, resulting in the GUP pin no longer being consistent with the > page actually mapped into the page table. > > The possible ways to deal with this situation are: > (1) Ignore and pin -- what we do right now. > (2) Fail to pin -- which would be rather surprising to callers and > could break user space. > (3) Trigger unsharing and pin the now exclusive page -- reliable R/O > pins. > > Let's implement 3) because it provides the clearest semantics and > allows for checking in unpin_user_pages() and friends for possible BUGs: > when trying to unpin a page that's no longer exclusive, clearly > something went very wrong and might result in memory corruptions that > might be hard to debug. So we better have a nice way to spot such > issues. > > This change implies that whenever user space *wrote* to a private > mapping (IOW, we have an anonymous page mapped), that GUP pins will > always remain consistent: reliable R/O GUP pins of anonymous pages. > > As a side note, this commit fixes the COW security issue for hugetlb with > FOLL_PIN as documented in: > https://lore.kernel.org/r/3ae33b08-d9ef-f846-56fb-645e3b9b4c66@redhat.com > The vmsplice reproducer still applies, because vmsplice uses FOLL_GET > instead of FOLL_PIN. > > Note that follow_huge_pmd() doesn't apply because we cannot end up in > there with FOLL_PIN. > > This commit is heavily based on prototype patches by Andrea. > > Co-developed-by: Andrea Arcangeli > Signed-off-by: Andrea Arcangeli > Signed-off-by: David Hildenbrand Acked-by: Vlastimil Babka