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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 70258C433DB for ; Mon, 21 Dec 2020 21:55:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3D9222C9C for ; Mon, 21 Dec 2020 21:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3D9222C9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 10EA26B0036; Mon, 21 Dec 2020 16:55:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C0366B005C; Mon, 21 Dec 2020 16:55:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEFE66B0068; Mon, 21 Dec 2020 16:55:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id D98666B0036 for ; Mon, 21 Dec 2020 16:55:33 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9C1AE3625 for ; Mon, 21 Dec 2020 21:55:33 +0000 (UTC) X-FDA: 77618646546.03.shake04_4006d282745a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 4F4CA28A4E8 for ; Mon, 21 Dec 2020 21:55:33 +0000 (UTC) X-HE-Tag: shake04_4006d282745a X-Filterd-Recvd-Size: 5125 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Dec 2020 21:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608587732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Yag9dkUrJO2svaffFY55Sd1tdeWMDuxfetcMS6uoLIQ=; b=i9uo8RvQY283QrUVVLEPi2Ba1ZX/na4aksaKl0GSnXtp2mI0dZZ22bF+v+uxjoMerpisOf 1G2+HfeSmdXyww3WGhNqcpgpvKUpj9oh5RszUMzWtqE5nsZQq9P30tC12RjgFWwjvXyBsk PulyLzXN8GhWmvbCbjUHoTP67WRew00= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-560-Pzfu6eteM8KiFBJ-niDJ3Q-1; Mon, 21 Dec 2020 16:55:30 -0500 X-MC-Unique: Pzfu6eteM8KiFBJ-niDJ3Q-1 Received: by mail-qv1-f69.google.com with SMTP id j24so9094998qvg.8 for ; Mon, 21 Dec 2020 13:55:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Yag9dkUrJO2svaffFY55Sd1tdeWMDuxfetcMS6uoLIQ=; b=nXvV/KjmPfcsB57WxNvrghsvZkuvUjIudcG0itS4r4QjPzsRThRN0cR0FJbBhiJ9WQ UiUR3icfZrD30op08Z3BXdmv5JIoQTBqOsBZHqkj9v2LKhdwF18O3NTfvksTDtgoH5eV AL1eqCHRNcxAffV5YWx5GmqJorpQqdDesiJXjXmsmnwAq2jUWP5/a9adVhME2o2Icbbf ggylThVIMAVbXBMp5Pjf+AybIYV96JChF3l3He/+fXQ3LJcktytGRoPap10MdvOIRTWl JlzmSGEbUi7Z30pZf+G45B4XAxfqr+1/Em6deI/tjqYKQEVHL9tHbZMBRtIOAR5qXh7R xmyA== X-Gm-Message-State: AOAM530Z0oz515y0YJ7hEfIiPW0F00gyyfMX6PKgJhnx/YFqWL5WUY5s c7Lpet+axrD7DLtitN3bAXKkVQfGtKxSG3ci4lEZMJKXiAy+A9UF5QJghj5NiR7ga9nY71iVlRy 6U63F1anY5ZM= X-Received: by 2002:ae9:e8cf:: with SMTP id a198mr19348126qkg.11.1608587729514; Mon, 21 Dec 2020 13:55:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzatN9WDCPwo9Vy07PiXSPaoiCn0IUYUq1Z+VIHlvcPXq8+h8ImavpdP1rFFJhRQxKrzzuOZg== X-Received: by 2002:ae9:e8cf:: with SMTP id a198mr19348106qkg.11.1608587729310; Mon, 21 Dec 2020 13:55:29 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n188sm12004877qke.17.2020.12.21.13.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 13:55:28 -0800 (PST) Date: Mon, 21 Dec 2020 16:55:26 -0500 From: Peter Xu To: Nadav Amit Cc: Linus Torvalds , Yu Zhao , Andrea Arcangeli , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Andy Lutomirski , Will Deacon , Peter Zijlstra Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect Message-ID: <20201221215526.GK6640@xz-x1> References: <20201219043006.2206347-1-namit@vmware.com> <20201221172711.GE6640@xz-x1> <76B4F49B-ED61-47EA-9BE4-7F17A26B610D@gmail.com> <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> MIME-Version: 1.0 In-Reply-To: <9E301C7C-882A-4E0F-8D6D-1170E792065A@gmail.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 Mon, Dec 21, 2020 at 12:23:06PM -0800, Nadav Amit wrote: > 2. Copy the page in cow_user_page() while holding the PTL and after flushing > has been done. I am not sure if there are potential problems with > special-pages (2 flushes might be necessary for special pages). This seems to be a good thing irrelevant of userfaultfd. Frankly speaking I don't know why it's always safe to do data copy without the pgtable lock in wp_page_copy(), since I don't know what guaranteed us from data changing on the original page due to any reason. We check and make sure pte hasn't changed, but is that really enough? So the safe way to me is that wp_page_copy() not only check pte_same() but also data_same() on the old/new pages, then with that it's even easier if we just move the data copy into the ptl as what Nadav said here. But I have no idea on the penalty to the rest of the world, especially on non-modern hosts. Thanks, -- Peter Xu