Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2368390rwr; Fri, 28 Apr 2023 09:23:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4von0ygXmfnBNxuR9i+evDsVR7pAo678Omzvmx09X6QSBB2QFMJrTCexsff5hNFfeu+tim X-Received: by 2002:a05:6a20:2d29:b0:ef:b897:5b0a with SMTP id g41-20020a056a202d2900b000efb8975b0amr6327619pzl.19.1682698997464; Fri, 28 Apr 2023 09:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682698997; cv=none; d=google.com; s=arc-20160816; b=VylAskfT/l9DvSYFAy+JuaqDao3kgPpu2QVw1B8s4PJrJW5nBavvTQp+KzKqwT3O7M oZL2ZCCCblWKng2TTo7KHafg/XjdogtPiLCA1rAvsSB/xZAmP4f1sS/q1sqD7q3R0BfF Vg6Ypje6gHhIAX0T0ffTmizecAss3gKWhhTuHuR+/K/0lh7wT14xrIeLMRHyGaWxyiTM +T6ppE8Idsxx4kDL8nL+W8hSOGsK/aMFOtRJA+O+/5DSrNesFIPGkgYLGW8acUDoDBQW 7rs325HbBl13dvC8RpI2HyhiiUn5cS8o/NDviUDcG6v3z8zAn3aun+zs+7WFOy93MQKL 1iRw== 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=5xkaTJLSgSiHWckTCCg+jkvg+cPl3tpnSAiaPo9ljdQ=; b=BI9uN5IAmii120dppIAgCSh8qiT0+K5aWokiTM8lUSro/DJx179Oko038EY3xRK6Ka nDwCcDOnyHpztP47sTsU4qe7M2NOoiEeOTxfRAokNYfyS1zvxJBJdWYmVq/nVxzljjzH 16SbjaBKNWiknFxV+TgNv3vn/GEUR7jpVjwVrNKNocvSAoYrTgExLvZX8kmt70dGUo2E hbOQHqoimM/u5bNgOPz00wthvWech2kUU+TsTbHzWTuAf0ww4WJg/7eeia8gQtnjIEFE dbbptXcTQvSpGG25RlNeAqQTwuE2T1T3Az3lLy7l9XxYkmD2YNdMhQu6RTUJRG92bkcY AIIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bFXqxpQe; 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 h18-20020aa796d2000000b00640f1dda998si8793386pfq.282.2023.04.28.09.23.02; Fri, 28 Apr 2023 09:23:17 -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=bFXqxpQe; 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 S235154AbjD1QN4 (ORCPT + 99 others); Fri, 28 Apr 2023 12:13:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240110AbjD1QNy (ORCPT ); Fri, 28 Apr 2023 12:13:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C9BA1706 for ; Fri, 28 Apr 2023 09:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682698390; 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=5xkaTJLSgSiHWckTCCg+jkvg+cPl3tpnSAiaPo9ljdQ=; b=bFXqxpQeR41pnrpdyEt6RuMbE7wdU80Q+sWN10Utpw+SDFlA/DM4zJUedDfuIpSEWP115E +3296zJJA/lKChLeotcqL213iVcFyUHhakT4puIeorMS2sjft7yGRi2kcUDS+RXEFq0ON4 kWhU+2gZ3D06HGSc1OHiaOdfby5i1wM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-BC1UhbilPsmCjfRDM7Ernw-1; Fri, 28 Apr 2023 12:13:08 -0400 X-MC-Unique: BC1UhbilPsmCjfRDM7Ernw-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f1793d6363so36401335e9.1 for ; Fri, 28 Apr 2023 09:13:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682698387; x=1685290387; 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=5xkaTJLSgSiHWckTCCg+jkvg+cPl3tpnSAiaPo9ljdQ=; b=bz//UxEebrmyElUgfB7X8fQTt2g9oOlxFM/emxu07bTCBlreLB841DSUeCwtXUo16S Vu0vot64ndVLW7d33DM7AAJTstLrkGsw9U/SjZz1nEcyHeCCm7JRsrnJj/b+3jHv0Fdh /9RZCXltKNBCGLIQMNV6OrU4AtgvXpEVWuBwM/iMJTiVkuk95CTv38Yzda+pFU22AVBk Ame+OR6jQawhazp7yXkAsdvJGAdwXT1WHNVOa7rmc7YZAnaOkWJU8eDZNqhwTzALBqxH QZP7fvjbxz/st/slbzqSivapfDu2PIEWvM7AMa++iocbeVA3tKIWKvPE0VwmYLLdK6dK siAw== X-Gm-Message-State: AC+VfDzF2EdtLNkNgTFO+zovmZT9iMltMCVdvSbyzrOTgSzmFAxtFvHc +6uxa90BsmYOkmQQm/bZ+wLkWt3+th2qYpdmoCWHW+BJA0YZh1b5/UyJbT8BglYVDAo5ooqS9uH pnobv2uxTzV+OaCOd13c95Yzs X-Received: by 2002:a1c:cc0f:0:b0:3f1:718d:a21c with SMTP id h15-20020a1ccc0f000000b003f1718da21cmr4546920wmb.31.1682698386872; Fri, 28 Apr 2023 09:13:06 -0700 (PDT) X-Received: by 2002:a1c:cc0f:0:b0:3f1:718d:a21c with SMTP id h15-20020a1ccc0f000000b003f1718da21cmr4546897wmb.31.1682698386533; Fri, 28 Apr 2023 09:13:06 -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 c21-20020a7bc855000000b003f17300c7dcsm24667685wml.48.2023.04.28.09.13.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Apr 2023 09:13:06 -0700 (PDT) Message-ID: <39cc0f26-8fc2-79dd-2e84-62238d27fd98@redhat.com> Date: Fri, 28 Apr 2023 18:13:03 +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: "Kirill A . Shutemov" 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 , 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> <6ddc7ac4-4091-632a-7b2c-df2005438ec4@redhat.com> <20230428160925.5medjfxkyvmzfyhq@box.shutemov.name> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230428160925.5medjfxkyvmzfyhq@box.shutemov.name> 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 18:09, Kirill A . Shutemov wrote: > On Fri, Apr 28, 2023 at 05:43:52PM +0200, David Hildenbrand wrote: >> On 28.04.23 17:34, 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(). >> >> IIRC, PageHuge() can also be called from GUP-fast and could special-case >> hugetlb eventually, as it's table while we hold a (temporary) reference. >> Shmem might be not so easy ... > > page->mapping->a_ops should be enough to whitelist whatever fs you want. > The issue is how to stabilize that from GUP-fast, such that we can safely dereference the mapping. Any idea? At least for anon page I know that page->mapping only gets cleared when freeing the page, and we don't dereference the mapping but only check a single flag stored alongside the mapping. Therefore, PageAnon() is fine in GUP-fast context. -- Thanks, David / dhildenb