Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp949641imm; Wed, 17 Oct 2018 10:46:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV61asmdB92xUHQdBnjCVYL13JehncBdYzSZ2ZLN0HdMeUaO2pCq232byUQ0aokkQtRo7VEwh X-Received: by 2002:a17:902:b03:: with SMTP id 3-v6mr26713171plq.141.1539798372318; Wed, 17 Oct 2018 10:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539798372; cv=none; d=google.com; s=arc-20160816; b=bq4b00RSvJY3hMU+bRjGi2wJFN+Qdd4WOPUSiKc7rXZzE74Orwos/kk4ru6ZGmZiZ0 Si8x32StGwQm2fy45Fgmo2oGF/K5VXHagIJ2rHE79gakZiVhe6awpWSR1XhLm3I7gpwH LSSC1HDirl3casrzO1+f8aCs2kDbS+4C4GTqflB7RWPpFvRL7Ffli/oF62wC5tAu1Z/u J8z29FOsiqQew2a9B61tXtG+4kaBwq2zIIauaGXpou3SZIrog0r9P4aFxMiY4eaBiXnc ai7y+LctF4RqWPzPNEV0ipETMHvNBXMbVD2EiN5ICYstHIWwp9fgRTO1U5sdwebtQ0IA Mjfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SX5hrNTZK3elM1qxzw8VBVb4XgG7eX3IHAsodwpu4sY=; b=c9UEwZrAf3UIf/4nDft3Pr9qjNXf34QEh++eu4xD6WJVpdzZOPJgUrz1dKyW5xiXz7 hVVnX3xCYSRd2JuEyvwgyY+SrN0OMXFRaOG+/WNNfBlbQO1e8Pv2yzvhPEx/k1iIs+67 vFbFAFT8rCFxXdmSQ1TE7jMQknY63j1calo8k5ed1g6PL7XPE9dfjVbabWFOpiq8BV8E ar9ptV5eQ4RnZU2EjQlwvDvdLoi6sYcZsDfISIlFgXtl/JJFXjU2rS4sT6NsG/04baJy DN6iS+TNfnmkCg4nXN0V6SXcvbpGFNysXcWgnGMsQFupY49ht/LfX7CxQ0Mou9DGaUth yqkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=V5bmFaDR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si18836190pla.156.2018.10.17.10.45.55; Wed, 17 Oct 2018 10:46:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=V5bmFaDR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727994AbeJRBmP (ORCPT + 99 others); Wed, 17 Oct 2018 21:42:15 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36653 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbeJRBmP (ORCPT ); Wed, 17 Oct 2018 21:42:15 -0400 Received: by mail-pg1-f193.google.com with SMTP id f18-v6so12891152pgv.3 for ; Wed, 17 Oct 2018 10:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SX5hrNTZK3elM1qxzw8VBVb4XgG7eX3IHAsodwpu4sY=; b=V5bmFaDR93O9IgBkIdvjnlYVcDk6WqhKZSMhMSnIbLt4+tQ3K96ZJEK1FFCnGjrU0t 3JothcAuM+hvr8MyoIQDtxFLt3e+hjKXgVa1WPjf4Hb+pmnuzfC9uBUigvQDQyR35MI3 WgOHVCP6UUmM9Fu0yMkcQD5xLfx3MKsj4E5vU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SX5hrNTZK3elM1qxzw8VBVb4XgG7eX3IHAsodwpu4sY=; b=Y7fZ65MG7pzj8RIj5Q7o3E4+Hg9Fh6Yfbu2H0vggaVZOWaWi6Iq0WuLHGZaz394RZA eRxADAX96pATQsXHb6enCI/2vBQBEGQRMACUZQawYprdMnJGg2uHR5IRez1cP3dgInwS H1AQWxViqq2o1UBLsEAO4K3RuSgaU5/2q6t2vPxX/ktH01vp1D05B7YAjaHM6he2KnVu NklYkanyx2cGOkrnHThwVvuv7G9LRiMEauPR6BSpRwkWuxSw80iAsD1hTAT8k2LNeTg8 8+1hPp+gq6dUs5uFl75o5aYukqg0RX56Ol3H6wmrYVgh+4ozpbhrvoD4p9abN6rmB9gu 7tnA== X-Gm-Message-State: ABuFfojEYlX4SYI94G0cdnQQwSvLz0bnmkJ1vbLqhMfDXp5WVvk2zQQP 5LMJxKdfWZC8UGSwNBLS5fIo+Q== X-Received: by 2002:a63:1555:: with SMTP id 21-v6mr25055634pgv.383.1539798329785; Wed, 17 Oct 2018 10:45:29 -0700 (PDT) Received: from localhost ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id k71-v6sm27651452pge.44.2018.10.17.10.45.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Oct 2018 10:45:28 -0700 (PDT) Date: Wed, 17 Oct 2018 10:45:27 -0700 From: Joel Fernandes To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, jreck@google.com, john.stultz@linaro.org, tkjos@google.com, gregkh@linuxfoundation.org, Andrew Morton , dancol@google.com, "J. Bruce Fields" , Jeff Layton , Khalid Aziz , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , minchan@google.com, Shuah Khan Subject: Re: [PATCH v2 1/2] mm: Add an F_SEAL_FS_WRITE seal to memfd Message-ID: <20181017174527.GA107185@joelaf.mtv.corp.google.com> References: <20181009222042.9781-1-joel@joelfernandes.org> <20181017095155.GA354@infradead.org> <20181017103958.GB230639@joelaf.mtv.corp.google.com> <20181017120829.GA19731@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181017120829.GA19731@infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 17, 2018 at 05:08:29AM -0700, Christoph Hellwig wrote: > On Wed, Oct 17, 2018 at 03:39:58AM -0700, Joel Fernandes wrote: > > > > This usecase cannot be implemented with the existing F_SEAL_WRITE seal. > > > > To support the usecase, this patch adds a new F_SEAL_FS_WRITE seal which > > > > prevents any future mmap and write syscalls from succeeding while > > > > keeping the existing mmap active. The following program shows the seal > > > > working in action: > > > > > > Where does the FS come from? I'd rather expect this to be implemented > > > as a 'force' style flag that applies the seal even if the otherwise > > > required precondition is not met. > > > > The "FS" was meant to convey that the seal is preventing writes at the VFS > > layer itself, for example vfs_write checks FMODE_WRITE and does not proceed, > > it instead returns an error if the flag is not set. I could not find a better > > name for it, I could call it F_SEAL_VFS_WRITE if you prefer? > > I don't think there is anything VFS or FS about that - at best that > is an implementation detail. > > Either do something like the force flag I suggested in the last mail, > or give it a name that matches the intention, e.g F_SEAL_FUTURE_WRITE. > Ok, I agree. I like the name F_SEAL_FUTURE_WRITE you are proposing so I will use that. > > I could make it such that this seal would not be allowed unless F_SEAL_SHRINK > > and F_SEAL_GROW are either previously set, or they are passed along with this > > seal. Would that make more sense to you? > > Yes. Cool. > > > > static int memfd_add_seals(struct file *file, unsigned int seals) > > > > { > > > > @@ -219,6 +220,9 @@ static int memfd_add_seals(struct file *file, unsigned int seals) > > > > } > > > > } > > > > > > > > + if ((seals & F_SEAL_FS_WRITE) && !(*file_seals & F_SEAL_FS_WRITE)) > > > > + file->f_mode &= ~(FMODE_WRITE | FMODE_PWRITE); > > > > + > > > > > > This seems to lack any synchronization for f_mode. > > > > The f_mode is set when the struct file is first created and then memfd sets > > additional flags in memfd_create. Then later we are changing it here at the > > time of setting the seal. I donot see any possiblity of a race since it is > > impossible to set the seal before memfd_create returns. Could you provide > > more details about what kind of synchronization is needed and what is the > > race condition scenario you were thinking off? > > Even if no one changes these specific flags we still need a lock due > to rmw cycles on the field. For example fadvise can set or clear > FMODE_RANDOM. It seems to use file->f_lock for synchronization. Ok, I will acquire the f_lock before setting these, thanks for the explanation. Will post updated patches today. - Joel