From: Christian Brauner <brauner@kernel.org>
To: Hugh Dickins <hughd@google.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
akpm@linux-foundation.org, willy@infradead.org,
linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com,
a.manzanares@samsung.com, dave@stgolabs.net,
yosryahmed@google.com, keescook@chromium.org,
patches@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/6] shmem: add support to ignore swap
Date: Tue, 18 Apr 2023 09:38:10 +0200 [thread overview]
Message-ID: <20230418-zynisch-satzglied-55821361f70a@brauner> (raw)
In-Reply-To: <79eae9fe-7818-a65c-89c6-138b55d609a@google.com>
On Mon, Apr 17, 2023 at 10:50:59PM -0700, Hugh Dickins wrote:
> On Thu, 9 Mar 2023, Luis Chamberlain wrote:
>
> > In doing experimentations with shmem having the option to avoid swap
> > becomes a useful mechanism. One of the *raves* about brd over shmem is
> > you can avoid swap, but that's not really a good reason to use brd if
> > we can instead use shmem. Using brd has its own good reasons to exist,
> > but just because "tmpfs" doesn't let you do that is not a great reason
> > to avoid it if we can easily add support for it.
> >
> > I don't add support for reconfiguring incompatible options, but if
> > we really wanted to we can add support for that.
> >
> > To avoid swap we use mapping_set_unevictable() upon inode creation,
> > and put a WARN_ON_ONCE() stop-gap on writepages() for reclaim.
>
> I have one big question here, which betrays my ignorance:
> I hope that you or Christian can reassure me on this.
>
> tmpfs has fs_flags FS_USERNS_MOUNT. I know nothing about namespaces,
> nothing; but from overhearings, wonder if an ordinary user in a namespace
> might be able to mount their own tmpfs with "noswap", and thereby evade
> all accounting of the locked memory.
>
> That would be an absolute no-no for this patch; but I assume that even
> if so, it can be easily remedied by inserting an appropriate (unknown
> to me!) privilege check where the "noswap" option is validated.
Oh, good catch. Thanks! So you would just need sm like:
diff --git a/mm/shmem.c b/mm/shmem.c
index 787e83791eb5..21ce9b26bb4d 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3571,6 +3571,10 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
ctx->seen |= SHMEM_SEEN_INUMS;
break;
case Opt_noswap:
+ if ((fc->user_ns != &init_user_ns) || !capable(CAP_SYS_ADMIN)) {
+ return invalfc(fc,
+ "Turning off swap in unprivileged tmpfs mounts unsupported");
+ }
ctx->noswap = true;
ctx->seen |= SHMEM_SEEN_NOSWAP;
break;
The fc->user_ns is the userns that the tmpfs mount will be mounted in, i.e.,
fc->user_ns will become sb->s_user_ns if FS_USERNS_MOUNT is raised. So with the
check above we require that the tmpfs instance must ultimately belong to the
initial userns and that the caller has CAP_SYS_ADMIN in the initial userns
(CAP_SYS_ADMIN guards swapon and swapoff) according to capabilities(7).
next prev parent reply other threads:[~2023-04-18 7:38 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 23:05 [PATCH v2 0/6] tmpfs: add the option to disable swap Luis Chamberlain
2023-03-09 23:05 ` [PATCH v2 1/6] shmem: remove check for folio lock on writepage() Luis Chamberlain
2023-03-09 23:05 ` [PATCH v2 2/6] shmem: set shmem_writepage() variables early Luis Chamberlain
2023-03-09 23:05 ` [PATCH v2 3/6] shmem: move reclaim check early on writepages() Luis Chamberlain
2023-03-09 23:05 ` [PATCH v2 4/6] shmem: skip page split if we're not reclaiming Luis Chamberlain
2023-03-09 23:09 ` Yosry Ahmed
2023-04-18 4:41 ` Hugh Dickins
2023-04-18 21:11 ` Luis Chamberlain
2023-04-18 21:20 ` Hugh Dickins
2023-03-09 23:05 ` [PATCH v2 5/6] shmem: update documentation Luis Chamberlain
2023-04-18 5:29 ` Hugh Dickins
2023-04-18 21:20 ` Luis Chamberlain
2023-04-18 21:41 ` Hugh Dickins
2023-04-18 21:49 ` Luis Chamberlain
2023-03-09 23:05 ` [PATCH v2 6/6] shmem: add support to ignore swap Luis Chamberlain
2023-04-18 5:50 ` Hugh Dickins
2023-04-18 7:38 ` Christian Brauner [this message]
2023-04-18 21:51 ` Luis Chamberlain
2023-04-20 8:57 ` [PATCH] shmem: restrict noswap option to initial user namespace Christian Brauner
2023-04-20 19:18 ` Luis Chamberlain
2023-04-18 21:22 ` [PATCH v2 6/6] shmem: add support to ignore swap Luis Chamberlain
2023-04-18 21:30 ` Randy Dunlap
2023-03-14 1:21 ` [PATCH v2 0/6] tmpfs: add the option to disable swap Davidlohr Bueso
2023-03-14 2:46 ` haoxin
2023-03-19 20:32 ` Luis Chamberlain
2023-03-20 11:14 ` haoxin
2023-03-20 21:36 ` Luis Chamberlain
2023-03-21 11:37 ` haoxin
2023-04-18 4:31 ` Hugh Dickins
2023-04-18 20:55 ` Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230418-zynisch-satzglied-55821361f70a@brauner \
--to=brauner@kernel.org \
--cc=a.manzanares@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=da.gomez@samsung.com \
--cc=dave@stgolabs.net \
--cc=hughd@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mcgrof@kernel.org \
--cc=p.raghav@samsung.com \
--cc=patches@lists.linux.dev \
--cc=willy@infradead.org \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox