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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4416C7618E for ; Mon, 24 Apr 2023 12:38:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55CC46B0078; Mon, 24 Apr 2023 08:38:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 510636B007B; Mon, 24 Apr 2023 08:38:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C31A6B007D; Mon, 24 Apr 2023 08:38:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1E5906B0078 for ; Mon, 24 Apr 2023 08:38:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DC62BAC4B3 for ; Mon, 24 Apr 2023 12:38:53 +0000 (UTC) X-FDA: 80716238946.02.CAD58C2 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf16.hostedemail.com (Postfix) with ESMTP id 0D7B8180028 for ; Mon, 24 Apr 2023 12:38:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ctcFbIKD; spf=pass (imf16.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682339932; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lx7DmyFlRlvWUed6TjzQKWfcWFQg770oVH4KZSEDJpQ=; b=cp6+ZLfIRyk3yx/YNuJm05bF94gXDBCBK2HEJSwFpg5kxV9HfJauEuAcGdtcger+ESHaOO PG8wPiG9osMtKdHtEzzQR+fqJIULpiv+z1cTtKejZuy7UoNnyG36d3HJG3wV+cghj8gEcI Z/Pxs8gSGlXe3PWQYuI7agkzaqGZ0sg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ctcFbIKD; spf=pass (imf16.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682339932; a=rsa-sha256; cv=none; b=ep3OgnKZ6M9eT2Et9VTH74Vs4C01IP7lOIbdVHNSoDTYW82hgI6DU++h5w/T6HCE0ZEpjH 0Cv72iKlRwULyC8odVLslqleBb5G2fat87xF5cuHWtqHU7VEgSj+0BjaH+QrNSrxG3smYU gyTETEwV46h+7F25It4L+M5VbtHGx4c= Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-2f27a9c7970so3987255f8f.2 for ; Mon, 24 Apr 2023 05:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339930; x=1684931930; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lx7DmyFlRlvWUed6TjzQKWfcWFQg770oVH4KZSEDJpQ=; b=ctcFbIKD3/sGh/iRlKPOiUUf9u0p65PjOOh7L5IKugl3B7DMfLYLvPD05JAT4UfIRU owA8xENxL0+tiOFgLY36MuWtu4e9t6FSMc4QOG4U3IyE2FEfx0trObDGyfie+q47qXCI prKTVusoC1ooNsxJ+bJHAxX8dWA5mNJ0K4SQvsZty9PgmHEPOg1IUSZK9GkkKSFQ+y9s Lm0dCdsW+glzrX7WYQIS1MKuL/WSAaLen7zJzXkIxHf2Y+KPcNo+765UmjHhr4ra7Ocb Fh6Ut9GErO6ltAqq6EOmcyMPBenOQDLrEeXCwP3jyzP4JIKlkPnXC2V171/wrctulpFI qVzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339930; x=1684931930; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lx7DmyFlRlvWUed6TjzQKWfcWFQg770oVH4KZSEDJpQ=; b=V78F0hQpRzlrynL4zbMetYBteQ2ambAhTZ9ETbIn2MUftdqZjS+m7/cozY4vUHsltq asRB6LwvcVMbUjRX8o2pDaj2JkthOf5PDlZlriHBme4K5m82aZafiSYIaEtmsqYQ/wIL 1fba7bet8e6iWmn2+Ib2r3VoP8nwf5E8nN3TSVfMi8suW01S0lvdk7dshAppG7GQ9RIM AoDkX4z0eZKa9Kbm+F4IpllZzt/XLtYZmY9EYaQfobyCEPTCqAcxqRcx429GnHC/5g2H +1RqUjryFmwTt4cCAj7UEYvFlIp26WriW2uwp2GIIPTEjZMUzQugORWBcPAbwPxjZwQ4 rxdA== X-Gm-Message-State: AAQBX9fqseGqlIb2iRDY/hR6YvdN0GgvxgvXrqO1qaIro/1YK3IgGOHE 6lK7MKF3s0/g6ZQWPlUAqXw= X-Google-Smtp-Source: AKy350bDDaww1oPOEwHvoL6ufxQ6NB1xIwzcfg9BIoIp8pQcVilhbJJtyq1J1gNXn/x7K284jT2KmA== X-Received: by 2002:a5d:690e:0:b0:2f8:f3da:72cf with SMTP id t14-20020a5d690e000000b002f8f3da72cfmr8518834wru.18.1682339930413; Mon, 24 Apr 2023 05:38:50 -0700 (PDT) Received: from localhost (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.gmail.com with ESMTPSA id i1-20020a05600011c100b002cff06039d7sm10651491wrx.39.2023.04.24.05.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:38:49 -0700 (PDT) Date: Mon, 24 Apr 2023 13:38:49 +0100 From: Lorenzo Stoakes To: Jason Gunthorpe Cc: Christoph Hellwig , 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 Subject: Re: [PATCH v2] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: References: <90a54439-5d30-4711-8a86-eba816782a66@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0D7B8180028 X-Rspam-User: X-Stat-Signature: p6aw81ahtpuuetajxft3k5nm4u8jirtj X-HE-Tag: 1682339931-246119 X-HE-Meta: U2FsdGVkX1972m0XLoTrUPZBYTELN5qpHH6SV6OohHwABrht1FEfCvO2IdIXQ5B01TvQ5ni1haMQEEKjWNF4LF1H/Tq8FEWMd9vkKAgi9Hm52NuLvIZ/a7VwYhFqJnqAtkKK+ctZJrQNAKeF09fa+c46qQzpp63Ydil4O6joUtRMp6PG+ZcGaHgMMO0Kfe8j9Jog2p49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5A0WM8jKQ2RnW5IGFDuBPArCIIGZguck7/G+vbhmE+JW/A3p8Jb50HuhFh6WEc/XKXR3/flK9NOLL9I7HkLS6imUJuTnTv9ge+dORGtfzn7O+GAhoQEG1mvu6aYwd5xFZXXVzB9wPVinvXjz+w1h7gLmC7dYeplTQgS2+EQGlZoACs1FkAB5duyJoUdApMQ== 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, Apr 24, 2023 at 09:28:07AM -0300, Jason Gunthorpe wrote: > On Mon, Apr 24, 2023 at 11:17:55AM +0100, Lorenzo Stoakes wrote: > > On Mon, Apr 24, 2023 at 02:43:56AM -0700, Christoph Hellwig wrote: > > > I'm pretty sure DIRECT I/O reads that write into file backed mappings > > > are out there in the wild. > > I wonder if that is really the case? I know people tried this with > RDMA and it didn't get very far before testing uncovered data > corruption and kernel crashes.. Maybe O_DIRECT has a much smaller race > window so people can get away with it? > > > I know Jason is keen on fixing this at a fundamental level and this flag is > > ultimately his suggestion, so it certainly doesn't stand in the way of this > > work moving forward. > > Yeah, the point is to close it off, because while we wish it was > fixed properly, it isn't. We are still who knows how far away from it. > > In the mean time this is a fairly simple way to oops the kernel, > especially with cases like io_uring and RDMA. So, I view it as a > security problem. > > My general dislike was that io_uring protected itself from the > security problem and we left all the rest of the GUP users out to dry. > > So, my suggestion was to mark the places where we want to allow this, > eg O_DIRECT, and block everwhere else. Lorenzo, I would significantly > par back the list you have. I was being fairly conservative in that list, though we certainly need to set the flag for /proc/$pid/mem and ptrace to avoid breaking this functionality (I observed breakpoints breaking without it which obviously is a no go :). I'm not sure if there's a more general way we could check for this though? A perhaps slightly unpleasant solution might be to not enforce this when FOLL_FORCE is specified which is mostly a ptrace + friends thing then we could drop all those exceptions. I wouldn't be totally opposed to dropping it for RDMA too, because I suspect accessing file-backed mappings for that is pretty iffy. Do you have a sense of which in the list you feel could be pared back? > > I also suggest we force block it at some kernel lockdown level.. > > Alternatively, perhaps we abuse FOLL_LONGTERM and prevent it from > working with filebacked pages since, I think, the ease of triggering a > bug goes up the longer the pages are pinned. > This would solve the io_uring case and it is certainly more of a concern when the pin is intended to be kept around, though it feels a bit icky as a non-FOLL_LONGTERM pin could surely be problematic too? > Jason