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=-5.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 A0757C433DB for ; Wed, 23 Dec 2020 00:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E0172312E for ; Wed, 23 Dec 2020 00:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbgLWACp (ORCPT ); Tue, 22 Dec 2020 19:02:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbgLWACo (ORCPT ); Tue, 22 Dec 2020 19:02:44 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657B8C0613D6 for ; Tue, 22 Dec 2020 16:02:04 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 23so35950338lfg.10 for ; Tue, 22 Dec 2020 16:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KEZEPrvvOyHEjES0SNYK0E3ccD3hjt+5yzUBPutdjco=; b=XzU1oLdvDedHOW+AbIAexhPNODLtb//sgOl8JGShEdZKfQiV03IeRK19CKNwhm1tSD 3VuLtulBFA2VZCgH/YCk2yh0TP8reIQNg1xGazs2NSnNy9cYZCmo8JHBsKff32EuoxG3 QAAlrPIFglAKCoTl34p/7RmEHx235cSzHlqY8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KEZEPrvvOyHEjES0SNYK0E3ccD3hjt+5yzUBPutdjco=; b=Lc7Uhsb5lIB5iK2Lz6y3e8lqm6GucibDb8H0Mm2ElrHWEWczpzgXxGiBYyym9OnDSW iH9BnX1EnzgYOaeu+xzVMBsiFLG8EHXyBC3hiQiZiiPygKTd1mDbg0AfrZLjJgxWViqn 00L+gRbdYtOMG2TbeMdzrD3YIxRUtSYcqdc//NuomJw1Qb/LsJoHodqhyWBgXQycUcmn 6CntYiFTm8iYddaPImAlBuon51lNCOgrJqJZYZ+3sJCGqmyTBeJTL3UJR9nIzsJS8jG6 kGIL2YGnlXG5hglO+ETe00VElu2/T11iST76MHuVajrwRgawvEaiCNfleGzVqH/kJQcH LkEQ== X-Gm-Message-State: AOAM532ukjmnY8vVpNqhKjM6CEwAT2VAqZLPrj1oeS1cRESYO3I+9dXo o1RYbnnKS6g9tJhg8LqRcDQhUAK/BTvSgw== X-Google-Smtp-Source: ABdhPJyLAMQWT2+mVQ2AgiXZ8HbLqWuxOVkBqcQR9a1ns1xH1wmipfA8nxhP3J8v8r0JMh4nsbKcIg== X-Received: by 2002:ac2:4102:: with SMTP id b2mr4551056lfi.406.1608681723002; Tue, 22 Dec 2020 16:02:03 -0800 (PST) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by smtp.gmail.com with ESMTPSA id w16sm2877940lfn.227.2020.12.22.16.02.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Dec 2020 16:02:02 -0800 (PST) Received: by mail-lf1-f45.google.com with SMTP id h22so26489170lfu.2 for ; Tue, 22 Dec 2020 16:02:02 -0800 (PST) X-Received: by 2002:a19:8557:: with SMTP id h84mr9361939lfd.201.1608681721989; Tue, 22 Dec 2020 16:02:01 -0800 (PST) MIME-Version: 1.0 References: <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> <1FCC8F93-FF29-44D3-A73A-DF943D056680@gmail.com> <20201221223041.GL6640@xz-x1> In-Reply-To: From: Linus Torvalds Date: Tue, 22 Dec 2020 16:01:45 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect To: Yu Zhao Cc: Andrea Arcangeli , Andy Lutomirski , Peter Xu , Nadav Amit , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Will Deacon , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 22, 2020 at 3:50 PM Linus Torvalds wrote: > > See zap_pte_range() for an example of doing it right, even in the > presence of complexities (ie that has an example of both flushing the > TLB, and doing the actual "free the pages after flush", and it does > the two cases separately). The more I look at the mprotect code, the less I like it. We seem to be much better about the TLB flushes in other places (looking at mremap, for example). The mprotect code seems to be very laissez-faire about the TLB flushing. Does adding a TLB flush to before that pte_unmap_unlock(pte - 1, ptl); fix things for you? That's not the right fix - leaving a stale TLB entry around is fine if the TLB entry is more strict wrt protections - but it might be worth testing as a "does it at least close the problem" patch. Linus