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 52E6DC433E0 for ; Tue, 22 Dec 2020 19:20:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03CBE23130 for ; Tue, 22 Dec 2020 19:20:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03CBE23130 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 7102C8D000A; Tue, 22 Dec 2020 14:20:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 698E88D0001; Tue, 22 Dec 2020 14:20:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 589CD8D000A; Tue, 22 Dec 2020 14:20:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 3F29C8D0001 for ; Tue, 22 Dec 2020 14:20:27 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 03A96181AC9CC for ; Tue, 22 Dec 2020 19:20:27 +0000 (UTC) X-FDA: 77621884494.03.skirt74_3f13d3727462 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id BA88E28A4E8 for ; Tue, 22 Dec 2020 19:20:26 +0000 (UTC) X-HE-Tag: skirt74_3f13d3727462 X-Filterd-Recvd-Size: 5967 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Dec 2020 19:20:26 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id f17so8992690pge.6 for ; Tue, 22 Dec 2020 11:20:26 -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=F5AMnLvseBLwD4CSY72NfvaqVdYyFOwme+T8yzDx3b4=; b=NAEFAdESyBeAhxfpWp0L2gvl3DEqFJ3nrPzeclRSSpJ8vtv9sAf6JBaOWZ/EuTduCg eAAjkSWS3gkrV7xm0bWp5uBScT9aRj70jvUYSefltZvReHiKLVNbSJ6eoS6YwIhnX0O9 EIYBsprjoUSOzuApPGT/nXm8thSTvZV+iebQUZftF1jrLL+QXFuZwBbTXhN3FCVasCvq VPlq/diIas69vWuOhV8v7V/MjoDy8aOSWRdqbZQ0Wd1Apx7tqai/LlJ4JPTNEJLubRuX hVkzPuZb9UwyKGOfZ++fejJWnTXWEJWrBOFBFNW61I75vgt9K21iieIXVAfjsO7Qmr6s FeVQ== 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=F5AMnLvseBLwD4CSY72NfvaqVdYyFOwme+T8yzDx3b4=; b=PZLUYtTepM8mvTC4niIB4qHKa0G1Hd0uvFA393QKttLNwXKkobyg+8lvWlnVSKBh9v DUOoqUF8Fnr1FxQSSn7tDpz+2pYr4QTGvJWPdtRYHz/pJd4LQ55tsAfBB1nhImvSk716 SafnCLPI/i18pZ+p+WsDiy8OR6J4WeXswB8oe1/Pjc6BoczfcS8H02pyXV0XJG+YgoYA fh5Wdx+4utr2+ZNNc05N6vh6f1v0MUYxek2Lv3zj0e7gdJF+AFHWKuv1ZI1loezaelzF biWSX56WL8pU16p2bqOJmfa+erlGMZ4Hx/+36BarreHPYSViwp2haCVr5Y0h65H1Qrna 7B0g== X-Gm-Message-State: AOAM533VDhL29GIE0yrxAKaCJcL/LFDz+mTmymj5SX5MqegC5vK6Y6D8 ALxgQV1WtQ/5/2IsZP6Cns8= X-Google-Smtp-Source: ABdhPJwUI29C82tgtHYmx78kGGb+xdlrRNFNTXAf8QZn5A/wiuk/5BA6I/kn1gFRkOwOEWcLf8jjBA== X-Received: by 2002:a05:6a00:22c9:b029:198:15b2:bbd3 with SMTP id f9-20020a056a0022c9b029019815b2bbd3mr928100pfj.64.1608664825069; Tue, 22 Dec 2020 11:20:25 -0800 (PST) Received: from ?IPv6:2601:647:4700:9b2:9423:6a08:cbd0:8220? ([2601:647:4700:9b2:9423:6a08:cbd0:8220]) by smtp.gmail.com with ESMTPSA id t18sm21640050pfl.138.2020.12.22.11.20.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Dec 2020 11:20:24 -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: Date: Tue, 22 Dec 2020 11:20:21 -0800 Cc: Peter Zijlstra , Minchan Kim , Linus Torvalds , Peter Xu , Andrea Arcangeli , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Andy Lutomirski , Will Deacon 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> To: Yu Zhao 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 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) Yet, something still goes bad. Debugging.