Received: by 2002:ab3:5012:0:b0:1d7:b7fe:f8b7 with SMTP id y18csp3089748ltb; Tue, 9 Aug 2022 12:26:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TvgkSgD2Up01pLxbT/xxkGq1eFvFCb058x/KEyjTkPpes48eGJwlCIopRbLGkjJyNUgGK X-Received: by 2002:a17:903:1ce:b0:16f:1c1f:50e5 with SMTP id e14-20020a17090301ce00b0016f1c1f50e5mr25418566plh.132.1660073206283; Tue, 09 Aug 2022 12:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660073206; cv=none; d=google.com; s=arc-20160816; b=IwX8TJlG7Q03NFM79DnNe8NL8mbpWpTtem52S5ro7crEKes3Wd+qEVwBT2zyMO9+0n SSQTejh188MYi+pO3EHh6ZIo4hO/q4/BsC9lob8TIWULQSVMwIOB5W2LnZmt+B7Wfjml By9ejo6FMWnYoG2xJDLAW2L+DUXYx55VKHRIr8i9Cun9a4mNYEaIiAReFaytBXx9AbJZ D9BjRPLfJXYjW7DP83iAgzb1Its9JwXINTHUa+rUXDdVqe0DFNLJpt4ddUMMi4tfjUHw W2bg9B09jyaemaXaJjPUkS2WY91zmyda4DZ8LrPDn4G39zvyTtSXBpYDFMUf/vbLSt8q 43Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=5MxbEkPFfHnhv9lIG9SKrVYa+3yd5Ii2mgv7KMCMiKA=; b=0wXGiIDwOvSj6LGBzMW0NeeIvaSXmjYiglA+ubAQ76Ac245TcfqkjjUPO2/4D9o8Ls mPn5L817y0z3QQF9g3eMLuJBXphVX4W2YoA3vyTfrHMJei9DfR11q761eJAfoMcaX5gp wLUfXSjbTaTCy67txJK7X42pzV1FvonIcnA3edcZdiwuNwl3TnlgiyYECqBgUMQFNzfL 0OlV17BT/pPH3ufffsxka3A189MIhy0/Qm4/PdFBCrvo6s1CBqxUgbVcsBDPXorzdKox ToSa0IMdmaH4r9lJBtRus0Jsh3LPqljnndSooz01AG9LbbL1VfGjfcSExKDsMIAscPbQ sEDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MwVPwrnk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a17090ab28300b001f20f502bfesi1452312pjr.178.2022.08.09.12.26.32; Tue, 09 Aug 2022 12:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MwVPwrnk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245027AbiHITIL (ORCPT + 99 others); Tue, 9 Aug 2022 15:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348391AbiHITGu (ORCPT ); Tue, 9 Aug 2022 15:06:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3787286E7 for ; Tue, 9 Aug 2022 11:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660071185; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5MxbEkPFfHnhv9lIG9SKrVYa+3yd5Ii2mgv7KMCMiKA=; b=MwVPwrnkbAFEUC9IAx+zOQqkmwQfCd6a7ltEHWCNbPk67eHZPR1jwf7uDDEwWZB/eJon8s 3qycWranGQzYZcaupPw1qLifh2lQ2Osl1GA2nNHQoAenDGtHeci32O0E2GVvoLxtpCRubP AHLKWXkzo5ngpzYg7O9qxK0agRfxhsk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-67-9_fQZhxqMiax6J7_tDvuYw-1; Tue, 09 Aug 2022 14:53:03 -0400 X-MC-Unique: 9_fQZhxqMiax6J7_tDvuYw-1 Received: by mail-wr1-f69.google.com with SMTP id n7-20020adfc607000000b0021a37d8f93aso1999192wrg.21 for ; Tue, 09 Aug 2022 11:53:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=5MxbEkPFfHnhv9lIG9SKrVYa+3yd5Ii2mgv7KMCMiKA=; b=lpbbcE9yWrJmKIuGTtOZ10276m8AGjepsxWffxlddJZtdphskflzEMCxbOBdZotI/6 S498q5adoIcaIfaF+oj11e3WS6ZBkv3sRJsTAHJ8STxHVxLJVxJHVEcQAci1SPaBxsQB E0LQtsz12podyzMROx/fXBrWIcZ4X/FE6rMAWsEOb0dhpfPLyohHCLeYwkzAz4tYtGYS yDjiXBw0IQBet4/01ugNYUY8XvGOvV0V/a4u7nfqsPWcxbSTwXl0rIjrUg0SMa1MD2qM PqGSJVjnbn+mguV+N4v+DMmXKrksvY8LIIq3iA/8tX+NGpm+/09oEhjZBCPGffeIaWLk +FOw== X-Gm-Message-State: ACgBeo2ZCz+2ITfVfDXhqch9JNv/Fob8aOHzy2sCV84lu0QKL4+aP5ac r/6szM180XhA/u6LV88egCfvWPNiFygq97Fq2N3v0lFeoTYKiF4CWF+CsyAfau7DFA5DHZOQceU SpRXUb05MkJoa4BDJgKqs45Xy X-Received: by 2002:a05:6000:15c5:b0:220:727a:24bf with SMTP id y5-20020a05600015c500b00220727a24bfmr15682594wry.621.1660071182504; Tue, 09 Aug 2022 11:53:02 -0700 (PDT) X-Received: by 2002:a05:6000:15c5:b0:220:727a:24bf with SMTP id y5-20020a05600015c500b00220727a24bfmr15682577wry.621.1660071182244; Tue, 09 Aug 2022 11:53:02 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:3700:aed2:a0f8:c270:7f30? (p200300cbc7053700aed2a0f8c2707f30.dip0.t-ipconnect.de. [2003:cb:c705:3700:aed2:a0f8:c270:7f30]) by smtp.gmail.com with ESMTPSA id o4-20020a056000010400b0021e501519d3sm14070439wrx.67.2022.08.09.11.53.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Aug 2022 11:53:01 -0700 (PDT) Message-ID: Date: Tue, 9 Aug 2022 20:53:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1] mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW Content-Language: en-US To: Jason Gunthorpe , Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Andrew Morton , Greg Kroah-Hartman , Axel Rasmussen , Peter Xu , Hugh Dickins , Andrea Arcangeli , Matthew Wilcox , Vlastimil Babka , John Hubbard References: <20220808073232.8808-1-david@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09.08.22 20:48, Jason Gunthorpe wrote: > On Tue, Aug 09, 2022 at 11:40:50AM -0700, Linus Torvalds wrote: >> On Mon, Aug 8, 2022 at 12:32 AM David Hildenbrand wrote: >>> >>> For example, a write() via /proc/self/mem to a uffd-wp-protected range has >>> to fail instead of silently granting write access and bypassing the >>> userspace fault handler. Note that FOLL_FORCE is not only used for debug >>> access, but also triggered by applications without debug intentions, for >>> example, when pinning pages via RDMA. >> >> So this made me go "Whaa?" >> >> I didn't even realize that the media drivers and rdma used FOLL_FORCE. >> >> That's just completely bogus. >> >> Why do they do that? >> >> It seems to be completely bogus, and seems to have no actual valid >> reason for it. Looking through the history, it goes back to the >> original code submission in 2006, and doesn't have a mention of why. > > It is because of all this madness with COW. > > Lets say an app does: > > buf = mmap(MAP_PRIVATE) > rdma_pin_for_read(buf) > buf[0] = 1 > > Then the store to buf[0] will COW the page and the pin will become > decoherent. > > The purpose of the FORCE is to force COW to happen early so this is > avoided. > > Sadly there are real apps that end up working this way, eg because > they are using buffer in .data or something. > > I've hoped David's new work on this provided some kind of path to a > proper solution, as the need is very similar to all the other places > where we need to ensure there is no possiblity of future COW. > > So, these usage can be interpreted as a FOLL flag we don't have - some > kind of (FOLL_EXCLUSIVE | FOLL_READ) to match the PG_anon_exclusive > sort of idea. Thanks Jason for the explanation. I have patches in the works to no longer use FOLL_FORCE|FOLL_WRITE for taking a reliable longerterm R/O pin in a MAP_PRIVATE mapping. The patches are mostly done (and comparably simple), I merely deferred sending them out because I stumbled over this issue first. Some ugly corner cases of MAP_SHARED remain, but for most prominent use cases, my upcoming patches should allow us to just have longterm R/O pins working as expected. -- Thanks, David / dhildenb