Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2343881rwr; Fri, 28 Apr 2023 09:07:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JRwQbWIkpmWUrpaIzd7An5f8/InNCSa+vv0R89xuMsHg3Bug5LpbO79way1hFY9XUFFyh X-Received: by 2002:a17:90a:5582:b0:246:97d2:dc27 with SMTP id c2-20020a17090a558200b0024697d2dc27mr5963247pji.42.1682698027377; Fri, 28 Apr 2023 09:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682698027; cv=none; d=google.com; s=arc-20160816; b=et+B0W9MtPFlTqyu9/63LZNQiQtBdrQ7tLLVs9ze9yzb9CPL2TLbT5jGZEom5eK43p sDUQTutEgmhjPbM/T11ao84T4fg8pnPOcSi9eekoRwyqgvX7DYprGzwUMdVVxNYjFq8Z cW/GMnjQvRDXEul3zjHRzjg29wUK/7OTST3YhyHjmDD0H+jJTg+gTBjB/939RyAKsb6i 2bkRPiuQ+3ZjKXsePtd/MXLyDHRScT/FsdJ3NUUjofHq0pgqS9KIUcnLirZsEf/8gscY R25Y2/vrg20pU93okjabRIVq4CRbprqTolYTH5ZJOKqxGbGGeqyeEpc/5/sgBNlIhZWD 6YDA== 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=ygEgijBc1IgIq8cFGjEh4tdLm5WBe48ZCNtdfsoShbQ=; b=Dg2wVcb2/OGgiMEJCSIW9NKnXb7xzptmAbVeR985/w941L0+shegE3Rtb/9Vxt8lT3 eEWX1fZ8Wf00BQDDvCzlYPu1eBYr1Fa6E1HyvNT37qbUP1Vsou8c9a4DNQsh5Cpd4/P9 rZk5BcbI03N42Rv0/dSbSzyuuI4R/BBA3IpCDO1aHm2Q0WmOMXCVho/3W/cbj7D6m4o1 wqacuQ2GHZGE8jo2l4Y0BbHLXkZ3Ot8PHeKnHNJYPBHaMK7QLrMhmScnm/WUHdQ7b6iJ ijjPlDTkkD3bcCWSfprcUBlRTGqA8w7XVDWyt3L3Qh5kPkqNECM28QPlJLkgQRuhdy0N 2Rkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bxmSrB6a; 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 gv23-20020a17090b11d700b00246596483a3si2518428pjb.37.2023.04.28.09.06.50; Fri, 28 Apr 2023 09:07:07 -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=bxmSrB6a; 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 S1344432AbjD1QDt (ORCPT + 99 others); Fri, 28 Apr 2023 12:03:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjD1QDp (ORCPT ); Fri, 28 Apr 2023 12:03:45 -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 ESMTPS id 439BE4EE4 for ; Fri, 28 Apr 2023 09:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682697783; 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=ygEgijBc1IgIq8cFGjEh4tdLm5WBe48ZCNtdfsoShbQ=; b=bxmSrB6av8CxUu5nHxe1QmQ9zoqybnCz6OprPzmG/VlQoKQAFq0nOPwWmS1gi+KbbbCjPm 4Vy9IpZOcjG7zo8Niu1OUXhTL+qDZLdyG3o2oBzmJFAL83xTKytJuj3V0mYwSKMTrFs7ZW EKEhPbhhpdckeib/5ZIB85tC7rFjdMI= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-j5srQV8iOnis1iqarq-tpw-1; Fri, 28 Apr 2023 12:03:01 -0400 X-MC-Unique: j5srQV8iOnis1iqarq-tpw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-2f625d521abso5860933f8f.3 for ; Fri, 28 Apr 2023 09:03:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682697779; x=1685289779; 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:subject:date:message-id :reply-to; bh=ygEgijBc1IgIq8cFGjEh4tdLm5WBe48ZCNtdfsoShbQ=; b=WTS7R/ai//I1eeibFpis+MKlrPS9eGXZDoqs9Vb450ISf/HQ1/wVxsZC+4Rw+DKqWd WnL270mVig/7umJ9sL2LHzI4Z3AgBE2bsSow0AVUARMdCxzu1m65xB4qgFipzURsIj3R scqExnN/Nqe14dn2Liy8a9HxHAZCQq7O1Cv4GKgrF7Uv6vVh9TXBM5f9iD7U9vk0+1vl YtdDqroAi3oFNwHpJAz51WcN+FZhFe3ul3Yh5OqGAbvlF4seKszYnzAHyHFSRSKULs8a mc0mCaRvuywAMjT65J0Mo0wai4S7/60qP6/fexxp6oXpJiJ6aAtJgkB6H/waN6gzMZ1K Qqzw== X-Gm-Message-State: AC+VfDxU3LcXH/jhfTZjSgiZux2nj4OdoIc0icbBOq6tyrFaoIYuxjnl 4RYIS+by2HPO/83sbVtKDx9v8kAQZ2IbFkH/DCEDWNveOmt9Bwq0G8jH7dHNi/QvQcYgfkAYDIo ePzj+IA3iuJR0HHUKWgHXg8Dz X-Received: by 2002:a5d:595a:0:b0:304:7237:729a with SMTP id e26-20020a5d595a000000b003047237729amr4261532wri.67.1682697779308; Fri, 28 Apr 2023 09:02:59 -0700 (PDT) X-Received: by 2002:a5d:595a:0:b0:304:7237:729a with SMTP id e26-20020a5d595a000000b003047237729amr4261467wri.67.1682697778920; Fri, 28 Apr 2023 09:02:58 -0700 (PDT) Received: from ?IPV6:2003:cb:c726:9300:1711:356:6550:7502? (p200300cbc72693001711035665507502.dip0.t-ipconnect.de. [2003:cb:c726:9300:1711:356:6550:7502]) by smtp.gmail.com with ESMTPSA id x8-20020a05600c21c800b003f2390bdd0csm16068630wmj.32.2023.04.28.09.02.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Apr 2023 09:02:58 -0700 (PDT) Message-ID: <0e6ef85d-d53a-c847-c70b-900eb925a413@redhat.com> Date: Fri, 28 Apr 2023 18:02:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v5] mm/gup: disallow GUP writing to file-backed mappings by default Content-Language: en-US To: Peter Xu Cc: Lorenzo Stoakes , Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Oleg Nesterov , John Hubbard , Jan Kara , "Kirill A . Shutemov" , Pavel Begunkov , Mika Penttila , David Howells , Christoph Hellwig References: <6b73e692c2929dc4613af711bdf92e2ec1956a66.1682638385.git.lstoakes@gmail.com> <094d2074-5b69-5d61-07f7-9f962014fa68@redhat.com> <400da248-a14e-46a4-420a-a3e075291085@redhat.com> <077c4b21-8806-455f-be98-d7052a584259@lucifer.local> <62ec50da-5f73-559c-c4b3-bde4eb215e08@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.7 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 28.04.23 17:56, Peter Xu wrote: > On Fri, Apr 28, 2023 at 05:34:35PM +0200, David Hildenbrand wrote: >> On 28.04.23 17:33, Lorenzo Stoakes wrote: >>> On Fri, Apr 28, 2023 at 05:23:29PM +0200, David Hildenbrand wrote: >>>>>> >>>>>> Security is the primary case where we have historically closed uAPI >>>>>> items. >>>>> >>>>> As this patch >>>>> >>>>> 1) Does not tackle GUP-fast >>>>> 2) Does not take care of !FOLL_LONGTERM >>>>> >>>>> I am not convinced by the security argument in regard to this patch. >>>>> >>>>> >>>>> If we want to sells this as a security thing, we have to block it >>>>> *completely* and then CC stable. >>>> >>>> Regarding GUP-fast, to fix the issue there as well, I guess we could do >>>> something similar as I did in gup_must_unshare(): >>>> >>>> If we're in GUP-fast (no VMA), and want to pin a !anon page writable, >>>> fallback to ordinary GUP. IOW, if we don't know, better be safe. >>> >>> How do we determine it's non-anon in the first place? The check is on the >>> VMA. We could do it by following page tables down to folio and checking >>> folio->mapping for PAGE_MAPPING_ANON I suppose? >> >> PageAnon(page) can be called from GUP-fast after grabbing a reference. See >> gup_must_unshare(). > > Hmm.. Is it a good idea at all to sacrifise all "!anon" fast-gups for this? > People will silently got degrade even on legal pins on shmem/hugetlb, I > think, which seems to be still a very major use case. > Right. Optimizing for hugetlb should be easy. Shmem is problematic. I once raised to John that PageAnonExclusive is essentially a "anon page is pinnable" flag. Too bad we don't have spare page flags ;) -- Thanks, David / dhildenb