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=-7.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 57D19C433DB for ; Wed, 23 Dec 2020 19:04:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA23D20867 for ; Wed, 23 Dec 2020 19:04:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA23D20867 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6683D8D004A; Wed, 23 Dec 2020 14:04:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 617E78D0026; Wed, 23 Dec 2020 14:04:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DF948D004A; Wed, 23 Dec 2020 14:04:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 360E98D0026 for ; Wed, 23 Dec 2020 14:04:21 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F0A3D180AD81D for ; Wed, 23 Dec 2020 19:04:20 +0000 (UTC) X-FDA: 77625472680.29.sheet08_6302c532746b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id B1F42180868DC for ; Wed, 23 Dec 2020 19:04:20 +0000 (UTC) X-HE-Tag: sheet08_6302c532746b X-Filterd-Recvd-Size: 6752 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 19:04:20 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id d2so10871633pfq.5 for ; Wed, 23 Dec 2020 11:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=NzLQl3piTpTW8PTRv8fdrHPax+6ZNWHiDo/bSFizPmQ=; b=FsGgEVViY6FgdgcgNws7Rh9fqlwlMDmAS6af9LzCwry9yvMUssiMShgG3obSmk1/aK yCpGKyghhwNVUWpX81DBX3xmrwWdZwFordxcxo5ECPDPLSswedjzzDGoWUi5izYeYJLk hC6igZ5EIFui1YISXl+L6xTB3bISNAAlmXaicVRS0lOn0GSROSHY0p3u9NwqoFkdz+KW S0PKQ0wssSvKsiGHIxvjX9V0MwuJB3mPQ4XAMIdkBBNmkCVJnLcC2C1c7w90Qomommm2 uzhcvom2f9kWzW/ro5kAUKmvMtllgtjVBKs1vH1rUg+MsVa0TdFFk7AKXaYwP4zyHt1Q uSFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=NzLQl3piTpTW8PTRv8fdrHPax+6ZNWHiDo/bSFizPmQ=; b=XdBAzbDNhLPTXvPFR1uEB+1gZYTRu+ar9s0835pLGgD42qDBoHKkKvs50byvDeWsG/ Pdxtp4RX1p//1mLqTA44pbvVyNLBwTqLQsgwHDDdJRqWEjO5DDTeBChxtV4cIBPzQz1h 7cl56dXhLF+fqooLTmhMW34MSnayyDsFyIBSnqxxyebhJ46L+BtI47xcxNnGIFUKD4FP /B7hCL7crehSWuTXxJDxWwqf5LSLkRzCRy4WOfDx2BHkhgMLb2pTCfg8ooo3Iqb/voKj rC3+s+P/wiqeCaV29D8tQajdk8tV2baoyc/NQRnBYEViZniUYljgxeizuTkwBLtlxwK1 cohA== X-Gm-Message-State: AOAM531VV4Q5S7i4RxPW30fx3jhJliMuHB1i+Tu3DyEhmff7a3aICInz b2YA3SYhWFdOcyANPQkS0xU= X-Google-Smtp-Source: ABdhPJzLJBXBveWqh3j9mgJpIR2luF9KsSDRHLkRkbP/bGDQwUrKhKoSkgxCWSZ5pnOVwYemdztkJA== X-Received: by 2002:a63:1f54:: with SMTP id q20mr25791663pgm.135.1608750259058; Wed, 23 Dec 2020 11:04:19 -0800 (PST) Received: from ?IPv6:2601:647:4700:9b2:50a2:5929:401b:705e? ([2601:647:4700:9b2:50a2:5929:401b:705e]) by smtp.gmail.com with ESMTPSA id 21sm24534561pfx.84.2020.12.23.11.04.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Dec 2020 11:04:18 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect From: Nadav Amit In-Reply-To: <20201223162325.GA22699@willie-the-truck> Date: Wed, 23 Dec 2020 11:04:15 -0800 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 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20201221172711.GE6640@xz-x1> <76B4F49B-ED61-47EA-9BE4-7F17A26B610D@gmail.com> <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> <20201223162325.GA22699@willie-the-truck> To: Will Deacon X-Mailer: Apple Mail (2.3608.120.23.2.4) 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 Dec 23, 2020, at 8:23 AM, Will Deacon wrote: >=20 > 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 >>>>>> =46rom whom? >>>>>>=20 >>>>>> Somebody who doesn't understand that correctness is more = important >>>>>> than performance? And that userfaultfd is not the most important = part >>>>>> 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 = failing. >>>>=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_finish_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.10094-1= -will@kernel.org/ >>=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) >=20 > 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. No worries. I just like to complain. I read v1 but forgot. >=20 >> Yet, something still goes bad. Debugging. >=20 > Did you figure this out? I tried to read the whole thread, but it's a = bit > of a rollercoaster. Yes, it was embarrassing bug of mine (not in any code sent). The soft-dirty code is entangled and the deep nesting of the code is unnecessary and confusing. I tried not to change much to ease backporting and merging with your pending patch, but some merging will be needed.