mm/shmem.c | 4 ++++ 1 file changed, 4 insertions(+)
Prevent tmpfs instances mounted in an unprivileged namespaces from
evading accounting of locked memory by using the "noswap" mount option.
Cc: Luis Chamberlain <mcgrof@kernel.org>
Reported-by: Hugh Dickins <hughd@google.com>
Link: https://lore.kernel.org/lkml/79eae9fe-7818-a65c-89c6-138b55d609a@google.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
mm/shmem.c | 4 ++++
1 file changed, 4 insertions(+)
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;
--
2.34.1
On Thu, Apr 20, 2023 at 10:57:43AM +0200, Christian Brauner wrote: > Prevent tmpfs instances mounted in an unprivileged namespaces from > evading accounting of locked memory by using the "noswap" mount option. > > Cc: Luis Chamberlain <mcgrof@kernel.org> > Reported-by: Hugh Dickins <hughd@google.com> > Link: https://lore.kernel.org/lkml/79eae9fe-7818-a65c-89c6-138b55d609a@google.com > Signed-off-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Luis
© 2016 - 2025 Red Hat, Inc.