Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5512194rwr; Mon, 24 Apr 2023 05:28:28 -0700 (PDT) X-Google-Smtp-Source: AKy350YrOWY+LUS7tUQ9NQQ7DJchdwRUUXGYoRmeh3MXSPpeO4TEB5mSXc/kzH9RBkWHnayCntyP X-Received: by 2002:a17:902:ccce:b0:1a6:8442:546f with SMTP id z14-20020a170902ccce00b001a68442546fmr15005917ple.19.1682339307768; Mon, 24 Apr 2023 05:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682339307; cv=none; d=google.com; s=arc-20160816; b=AGMLwrOC3JZ8TavzIVbuM1BeHKA1cNM9tdeYFTLEp8z7yj8ll0F1GQ6pJVlBon73hw 5FgLFRh/wV8qJmueU/ap8kyKDluh8nnkIqiyDxsDL1Qnan/o7H4FBB/dApv4DVzB2mwI 411bxnafjiX8JmzIaS0yd4rE13fMgCTlKTTHn/NTak7+ZTHczs2KwZtG3XdFQ5lVpRfB /DYIg5VyTYmienQcckDVNt637xSrRs/N4n+GZOE6hXWQhdNiuEU84OoTNLKjaXp7GnDO wr4wgNYu61xAmzWXD2zIYCJLoR7gnHZFkTzicimd5Wak/fzX/3+s+dmTC+VXIR7bg/Yl 679A== 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 :dkim-signature; bh=tH3QxEeyp8kfWcz1bkYSovs9h7ImBxkgM1DNmDxhaJg=; b=coGwDnC7DAllQruuyWHW3R4Hah5w2dF4UAZ12wQgZiTPBCzoeA/yaiRrtvtTtrDxnA 8Y6HhcMp/sbWgJ/XD8aKs/uMoraKjreQCLMDQYQReCyXbqOqydCxpGZswXh4kGiA+WxC 1nkJUXp1hTTKY9vxWwQ7Ye2sy8N8FaEBcWkK1+dJSTMQIBU8RgA2Iz//mXCaN4UtgsFC 6yNNikpbZbJaGfeDIj0/dLBGaNR8u+nEBNa7wQ1W7mVypz3srFB4HbomwSIqfIeNdBN9 hJtk2XhItX/B7DMI6EdGcK4wc3+wMgnCR5zhOJIh4eWhNKilOAHh5vcfxHxLgHWven6O N06w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=U8Ap4Bg2; dkim=neutral (no key) header.i=@suse.cz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170902da8700b001a686b1dc64si12012126plx.412.2023.04.24.05.28.16; Mon, 24 Apr 2023 05:28:27 -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=@suse.cz header.s=susede2_rsa header.b=U8Ap4Bg2; dkim=neutral (no key) header.i=@suse.cz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbjDXMTl (ORCPT + 99 others); Mon, 24 Apr 2023 08:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjDXMTk (ORCPT ); Mon, 24 Apr 2023 08:19:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE8FC26B7; Mon, 24 Apr 2023 05:19:38 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7A0D81FD80; Mon, 24 Apr 2023 12:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1682338777; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tH3QxEeyp8kfWcz1bkYSovs9h7ImBxkgM1DNmDxhaJg=; b=U8Ap4Bg2ocGY4N9KLmdiXJ3k3RWwRz6oUO8RZlNHZWwp0un0OpL64bHpI1g3fOxb1woAsH ItgJw2Cfz+eEX4qrSxeIJ7TV4vEFeRG35WWd4R2qNqdsQhU9eLdW3kEbVVo4ns/APWjmbp zt0Ccr2Eo51bBlJsa3aempb+/gVFX88= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1682338777; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tH3QxEeyp8kfWcz1bkYSovs9h7ImBxkgM1DNmDxhaJg=; b=LaPP5aHf+gTxAxLtBoghtsddhF6BkLYkqb8AtLbjILPSAiTl5h9wfxFQ0tRi14O8X+GOMN 4joBTRBV5KJviMCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6B2B21390E; Mon, 24 Apr 2023 12:19:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3kogGtlzRmTzcAAAMHmgww (envelope-from ); Mon, 24 Apr 2023 12:19:37 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id E8A34A0729; Mon, 24 Apr 2023 14:19:36 +0200 (CEST) Date: Mon, 24 Apr 2023 14:19:36 +0200 From: Jan Kara To: Lorenzo Stoakes Cc: Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Matthew Wilcox , Mike Kravetz , Muchun Song , Alexander Viro , Christian Brauner , Andy Lutomirski Subject: Re: [RFC PATCH 0/3] permit write-sealed memfd read-only shared mappings Message-ID: <20230424121936.lwgqty6hifs7eecp@quack3> References: <20230421090126.tmem27kfqamkdaxo@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,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 Fri 21-04-23 22:23:12, Lorenzo Stoakes wrote: > On Fri, Apr 21, 2023 at 11:01:26AM +0200, Jan Kara wrote: > > Hi! > > > > On Mon 03-04-23 23:28:29, Lorenzo Stoakes wrote: > > > This patch series is in two parts:- > > > > > > 1. Currently there are a number of places in the kernel where we assume > > > VM_SHARED implies that a mapping is writable. Let's be slightly less > > > strict and relax this restriction in the case that VM_MAYWRITE is not > > > set. > > > > > > This should have no noticeable impact as the lack of VM_MAYWRITE implies > > > that the mapping can not be made writable via mprotect() or any other > > > means. > > > > > > 2. Align the behaviour of F_SEAL_WRITE and F_SEAL_FUTURE_WRITE on mmap(). > > > The latter already clears the VM_MAYWRITE flag for a sealed read-only > > > mapping, we simply extend this to F_SEAL_WRITE too. > > > > > > For this to have effect, we must also invoke call_mmap() before > > > mapping_map_writable(). > > > > > > As this is quite a fundamental change on the assumptions around VM_SHARED > > > and since this causes a visible change to userland (in permitting read-only > > > shared mappings on F_SEAL_WRITE mappings), I am putting forward as an RFC > > > to see if there is anything terribly wrong with it. > > > > So what I miss in this series is what the motivation is. Is it that you need > > to map F_SEAL_WRITE read-only? Why? > > > > This originated from the discussion in [1], which refers to the bug > reported in [2]. Essentially the user is write-sealing a memfd then trying > to mmap it read-only, but receives an -EPERM error. > > F_SEAL_FUTURE_WRITE _does_ explicitly permit this but F_SEAL_WRITE does not. > > The fcntl() man page states: > > Furthermore, trying to create new shared, writable memory-mappings via > mmap(2) will also fail with EPERM. > > So the kernel does not behave as the documentation states. > > I took the user-supplied repro and slightly modified it, enclosed > below. After this patch series, this code works correctly. > > I think there's definitely a case for the VM_MAYWRITE part of this patch > series even if the memfd bits are not considered useful, as we do seem to > make the implicit assumption that MAP_SHARED == writable even if > !VM_MAYWRITE which seems odd. Thanks for the explanation! Could you please include this information in the cover letter (perhaps in a form of a short note and reference to the mailing list) for future reference? Thanks! Honza -- Jan Kara SUSE Labs, CR