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 X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7C28C433DB for ; Wed, 23 Dec 2020 16:23:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 291C7222BB for ; Wed, 23 Dec 2020 16:23:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 291C7222BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58A448D0032; Wed, 23 Dec 2020 11:23:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53B0A8D0026; Wed, 23 Dec 2020 11:23:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44EEE8D0032; Wed, 23 Dec 2020 11:23:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 2630B8D0026 for ; Wed, 23 Dec 2020 11:23:35 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DE3C03499 for ; Wed, 23 Dec 2020 16:23:33 +0000 (UTC) X-FDA: 77625067506.12.brass96_06075102746a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 9A5D718005A53 for ; Wed, 23 Dec 2020 16:23:33 +0000 (UTC) X-HE-Tag: brass96_06075102746a X-Filterd-Recvd-Size: 4597 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 16:23:32 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6ED1E2229C; Wed, 23 Dec 2020 16:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608740611; bh=JGM+26aHL4PtP44Zg8xOYHbq6LRGGL7oFlrZL0Y3xx4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WiVzcUdXRW1Pd8E9I9Pip4Mr0xbK1ynGN7oZ+yJseqr+P3f6PM4AJtesIPRJfkaLZ wj4TNCsvRVVJNyyyxHopbcughBpG72EX3K2tJdkcmOkAp+vTJlW61J9S8lcKvGAuK8 JiqqirlP4idJizlgQnkGXfJTumL3VpgU5wKM8zTGCdPkFJJuOl36AbL0uA5pfee6TB Ymv05AGVfJ+CTbcD6/OGkXhB8CYNZWtE95Ge/p0clmZibJNaUX+Yb4eqgNTOdhOsvm aTuPsG4uuHYQFkm/XDjrjCoIJdVLPyZXbq8Gzds/oPIgVkTyTKUWFanZ1CtbRJyqxx HZ9us+z5DBO6A== Date: Wed, 23 Dec 2020 16:23:26 +0000 From: Will Deacon To: Nadav Amit Cc: Yu Zhao , Peter Zijlstra , Minchan Kim , Linus Torvalds , Peter Xu , Andrea Arcangeli , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Andy Lutomirski Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect Message-ID: <20201223162325.GA22699@willie-the-truck> References: <20201221172711.GE6640@xz-x1> <76B4F49B-ED61-47EA-9BE4-7F17A26B610D@gmail.com> <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Dec 22, 2020 at 11:20:21AM -0800, Nadav Amit wrote: > > On Dec 22, 2020, at 10:30 AM, Yu Zhao wrote: > >=20 > > On Tue, Dec 22, 2020 at 04:40:32AM -0800, Nadav Amit wrote: > >>> On Dec 21, 2020, at 1:24 PM, Yu Zhao wrote: > >>>=20 > >>> On Mon, Dec 21, 2020 at 12:26:22PM -0800, Linus Torvalds wrote: > >>>> On Mon, Dec 21, 2020 at 12:23 PM Nadav Amit = wrote: > >>>>> Using mmap_write_lock() was my initial fix and there was a strong= pushback > >>>>> on this approach due to its potential impact on performance. > >>>>=20 > >>>> From whom? > >>>>=20 > >>>> Somebody who doesn't understand that correctness is more important > >>>> than performance? And that userfaultfd is not the most important p= art > >>>> of the system? > >>>>=20 > >>>> The fact is, userfaultfd is CLEARLY BUGGY. > >>>>=20 > >>>> Linus > >>>=20 > >>> Fair enough. > >>>=20 > >>> Nadav, for your patch (you might want to update the commit message)= . > >>>=20 > >>> Reviewed-by: Yu Zhao > >>>=20 > >>> While we are all here, there is also clear_soft_dirty() that could > >>> use a similar fix=E2=80=A6 > >>=20 > >> Just an update as for why I have still not sent v2: I fixed > >> clear_soft_dirty(), created a reproducer, and the reproducer kept fa= iling. > >>=20 > >> So after some debugging, it appears that clear_refs_write() does not= flush > >> the TLB. It indeed calls tlb_finish_mmu() but since 0758cd830494 > >> ("asm-generic/tlb: avoid potential double flush=E2=80=9D), tlb_finis= h_mmu() does not > >> flush the TLB since there is clear_refs_write() does not call to > >> __tlb_adjust_range() (unless there are nested TLBs are pending). > >=20 > > Sorry Nadav, I assumed you knew this existing problem fixed by: > > https://patchwork.kernel.org/project/linux-mm/cover/20201210121110.10= 094-1-will@kernel.org/ > >=20 >=20 > Thanks, Yu! For some reason I assumed it was already upstreamed and did= not > look back (yet if I was cc=E2=80=99d on v2=E2=80=A6) I'll repost in the new year, as it was a bit tight for the merge window. I've made a note to put you on cc. > Yet, something still goes bad. Debugging. Did you figure this out? I tried to read the whole thread, but it's a bit of a rollercoaster. Will