Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp815977imm; Wed, 17 Oct 2018 08:44:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV60kFKBug6OuI6hKBUJNuUASGKFp49+bxxE0fj45g73jbdsELaZWHuQCoFtdbJtABC3hJRpR X-Received: by 2002:a62:b90f:: with SMTP id z15-v6mr27393589pfe.171.1539791094473; Wed, 17 Oct 2018 08:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539791094; cv=none; d=google.com; s=arc-20160816; b=Glued2471pCREAQ1f9DsvD5Vt0tRzQsuoSfixYYtf8DcmcVNnv2hR8AFIGOxt9LXV+ Y9vYTXdWc7y+KCvKby5dAoJnXUfd4Wm5cxjtGVdl/7o2zkbEOwlnGeGFUjwDobBJS+dn AOQikwzKb1jSSvtrP0dMXHDftZpECDhyENQ5hJaV+i41bnUkzLcMOaqwcuXSJQueQ/WV +xSbIgwQhRVl3acEIWBG7pn6LM7tjhZXwqSfUPvVFVJrOltQPZGidbN/tDVoLNv8c0In Jmx8vUyk9Evu+6hImy8wWQAHDA5LQR1yF8keHwXQvZHmR4JI/542BtqmRJKPVcDK1/p/ 3sgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=M2Gp6gH80q43/tis0ptqhRINfH7JLOnQD2dCmFrdWQI=; b=M9qXrfAHqFrUbWiICLmggYJlTUCoLytreWMJKBj6HJl/6UzYsvQnX/hz+O3vsZ2mn2 r/6FHvCz8HFbRQXHcPsVH0rNyg4Zncb0XT2GCpTo4qiqcXNB7mfHgtJZvYGHczqZ5m65 y/ADO+KCSYUdtOC6LVPzh2lR57wb+4UZV05jnOLXyYsMgQadOE8szWxRn90MEpUiwNbI IQ4FOO4B+Dmx4H97giX5UvTh8RbRgvZAF6NzZujvvxDpOxbm5Esox6TS7UEbf1ed4r1a qpVgr73m/mTj+OZeT/5/mJnfwczAGHfAiX5Scp/SjPa19KcmTgqdwOPbfEM/qGbxnxxl 2O7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uk6W5kA3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o24-v6si16413273pgv.242.2018.10.17.08.44.39; Wed, 17 Oct 2018 08:44:54 -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=@google.com header.s=20161025 header.b=uk6W5kA3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727646AbeJQXkT (ORCPT + 99 others); Wed, 17 Oct 2018 19:40:19 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:34940 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727461AbeJQXkT (ORCPT ); Wed, 17 Oct 2018 19:40:19 -0400 Received: by mail-oi1-f194.google.com with SMTP id 22-v6so21470998oiz.2 for ; Wed, 17 Oct 2018 08:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=M2Gp6gH80q43/tis0ptqhRINfH7JLOnQD2dCmFrdWQI=; b=uk6W5kA3p3oUFI/6kzMIVNAJOh/JDlNUk8R0N7krrq2PfgQH+osftkDMWsZXg02vGw sMNUa/II4hRzZpraf8rd10+7x6GJOJogDSh8RyvhgS+qHKnVWNu1bjWYDOL1eFuotS6O uippIMMD+0Pedk1Y4lFbezZs/kY6CfkVPVzIQA5blHOSqATxuOmRURUPBYjz23oGjGGa f1Lg8RmFcVU+ZOcy01MvkI6yHypUKKBvsFv/xeiqLHkSHkGccK/piDo6EtzefNsot76z JrgyaAkbxc3p8z43+Oa36A8OLKDJVK2Q50ToF7qOE3HOim0ffVfYDTY7sDxff8QW8W3+ 90Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=M2Gp6gH80q43/tis0ptqhRINfH7JLOnQD2dCmFrdWQI=; b=muFadE4cp/J3n1KsiGrXMcoq44/itq+FedtAKAH+9Mt0d3Ycd/c/jHbi/M/SC5dkYQ OMpNuZTbb8F68diGgiTg1oNlmFiy6bg+NOHvhzR0JqmyX+gNGE59vCmiE833TxkbDBha Vu99+H6X/FzMzkxeOBzI9oxJSfVgLLnpe/9XdD7hYl1579PybtjmjpB9/sohDwdQg+rI jduNtmSFeqLh18jUNcGa+4OSdR7hjl9Y+9MWpHs/snpawZb8t7fk9psV/7FrHeH8dGxV zUSBNFVCjGkLWdNEs1pF1/erb54XN+uqwbouybZRk7LGjfziXVkSfkl9Qu7yEsAmUnK0 9ggw== X-Gm-Message-State: ABuFfojdQTAxejQkJQs6muUWFbXp3c/UTdri0G2p7QzNMaPoQp7kzQLm E3RwivOBfynb5oU7Ge9d8KFj/PYDKqi9Uu39BEVRZw== X-Received: by 2002:aca:d451:: with SMTP id l78-v6mr15236818oig.52.1539791041764; Wed, 17 Oct 2018 08:44:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:56d8:0:0:0:0:0 with HTTP; Wed, 17 Oct 2018 08:44:01 -0700 (PDT) In-Reply-To: <20181017120829.GA19731@infradead.org> References: <20181009222042.9781-1-joel@joelfernandes.org> <20181017095155.GA354@infradead.org> <20181017103958.GB230639@joelaf.mtv.corp.google.com> <20181017120829.GA19731@infradead.org> From: Daniel Colascione Date: Wed, 17 Oct 2018 08:44:01 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] mm: Add an F_SEAL_FS_WRITE seal to memfd To: Christoph Hellwig Cc: Joel Fernandes , linux-kernel , kernel-team@android.com, John Reck , John Stultz , Todd Kjos , Greg KH , Andrew Morton , "J. Bruce Fields" , Jeff Layton , Khalid Aziz , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm , Mike Kravetz , Minchan Kim , Shuah Khan Content-Type: text/plain; charset="UTF-8" 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 5:08 AM, 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. +1 >> > 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. Compare-and-exchange will suffice, right?