Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4834337rwr; Sun, 23 Apr 2023 14:37:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YxxLbI21zYPoh5f2F/WpKCFniXvYdUhVRQXm/iBsfAqJzTRCQRtytWaKJQaR7AKwHxSjGZ X-Received: by 2002:a05:6a00:2da7:b0:625:ea57:389b with SMTP id fb39-20020a056a002da700b00625ea57389bmr15684065pfb.5.1682285874476; Sun, 23 Apr 2023 14:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682285874; cv=none; d=google.com; s=arc-20160816; b=HLokDiFHi3KlzwvoKBzq8IdnFDi3C8yt3qVKOlIp9chW9VTbCC8WaOAaaTnTqZrw9w oSNJNEdbPi8thrp/DZJ88DrYw2OXDtjpx3jsVDYaIRQRXvUP3z4tF5CH+T2+aafxlb0G 4f8ySIIrqGjM68M5DH+xObDo+3q8QTbrSltj7XYsiMJkT0xg9qm3q86TycXxwKVyNh3Y Jrr3hAaa2r8koaFJbisfRvmdKmiC+BdhdJMG+52P8cQNQR23TVqJ3hCzQ3ZlZ6C+0248 brbwuRFKloAiJOc2tqgP5bvfF56fnvLhfh912pCorFkdg488cGc6aqyCog9ObEx85hDm p0mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VHZeXX+31ExcuP/csssW26tjb1NvKmp60UcDUIP5EEE=; b=AtFy6iSAL2a0A2iO3R0TgHqTM2jQPZ/5IgV/DNVtSbg1J6isG9/HDlRo0hQtc6mf+n DP5KW3QBLUn1fKE7KL/b7PXsiIaDvhU3mCFmiob3lbVy+HfZoQZO2cCDMnYxGGI958DD ePLfGbJnzbkdGN+1fQloTkM6RXAk2nX7ARdWjy8OZk4Z9LSWozi0QvVxU4bZb2fvgCPv QcE4a3gAS0Y2rpHYooAphdvL2LZxOygxXQVIKuAaqVRF+Tl3gJxmBr1givH1CHgjWckw EPqKSwmZMIS/gFMZgkkee/ZylYR7u6lQz2Ca+6+MHJ83e9YIJEqqjBbKsyCQfXCrU/ox 1gNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TeydC14v; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a3-20020aa79703000000b0063d19a45a93si9708161pfg.280.2023.04.23.14.37.41; Sun, 23 Apr 2023 14:37:54 -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=@kernel.org header.s=k20201202 header.b=TeydC14v; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbjDWUCZ (ORCPT + 99 others); Sun, 23 Apr 2023 16:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjDWUCY (ORCPT ); Sun, 23 Apr 2023 16:02:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C098E63; Sun, 23 Apr 2023 13:02:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 28D4D60F77; Sun, 23 Apr 2023 20:02:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD654C433D2; Sun, 23 Apr 2023 20:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682280142; bh=MXq/43kCze2RO9lP4ptWyt16cAC97gbSKdjUyiZkGe0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TeydC14vXjAcezSvOpLJ6lAgoD7kv4M6u2qpkMik63uNVRdyPydMRXOgOZl8horI+ dPMUTeoPcKNY3usBHvTn9wt3MN+OugsRnGr0IsC1oFmhWdpfSaV1Z2ZOlTUucNyFnI Dc7xJ3MsVgfv/9IzUKl8JIOxIGjmFLwo53Sw9q11W9QUhGzAN8aJtxFQ6cy32G+/6J sPWBqLbzeBzmMfJt637Yg3UjirQwtj3SDotLldKjhF9Q47+El15XA9ePt5cvIKvHTl ZLtLr/8hQ5GEStE0bg3XDleDq07tryjP50bYayKFt8JtmZOdkh1eS+Qu0bUY77irUf 0LMKZJajGU/pQ== Date: Sun, 23 Apr 2023 22:02:11 +0200 From: Simon Horman To: Lorenzo Stoakes Cc: Simon Horman , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jason Gunthorpe , 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 Subject: Re: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 Sun, Apr 23, 2023 at 08:40:53PM +0100, Lorenzo Stoakes wrote: > On Sun, Apr 23, 2023 at 09:32:01PM +0200, Simon Horman wrote: > > On Sat, Apr 22, 2023 at 02:37:05PM +0100, Lorenzo Stoakes wrote: > > > It isn't safe to write to file-backed mappings as GUP does not ensure that > > > the semantics associated with such a write are performed correctly, for > > > instance filesystems which rely upon write-notify will not be correctly > > > notified. > > > > > > There are exceptions to this - shmem and hugetlb mappings are (in effect) > > > anonymous mappings by other names so we do permit this operation in these > > > cases. > > > > > > In addition, if no pinning takes place (neither FOLL_GET nor FOLL_PIN is > > > specified and neither flags gets implicitly set) then no writing can occur > > > so we do not perform the check in this instance. > > > > > > This is an important exception, as populate_vma_page_range() invokes > > > __get_user_pages() in this way (and thus so does __mm_populate(), used by > > > MAP_POPULATE mmap() and mlock() invocations). > > > > > > There are GUP users within the kernel that do nevertheless rely upon this > > > behaviour, so we introduce the FOLL_ALLOW_BROKEN_FILE_MAPPING flag to > > > explicitly permit this kind of GUP access. > > > > > > This is required in order to not break userspace in instances where the > > > uAPI might permit file-mapped addresses - a number of RDMA users require > > > this for instance, as do the process_vm_[read/write]v() system calls, > > > /proc/$pid/mem, ptrace and SDT uprobes. Each of these callers have been > > > updated to use this flag. > > > > > > Making this change is an important step towards a more reliable GUP, and > > > explicitly indicates which callers might encouter issues moving forward. > > > > nit: s/encouter/encounter/ > > > > Ack, I always seem to leave at least one or two easter egg spelling > mistakes in :) :) > Will fix up on next respin (in unlikely event of no further review, > hopefully Andrew would pick up!) >