Skip to content

Commit 01106e1

Browse files
braunerakpm00
authored andcommitted
shmem: restrict noswap option to initial user namespace
Prevent tmpfs instances mounted in an unprivileged namespaces from evading accounting of locked memory by using the "noswap" mount option. Link: https://lkml.kernel.org/r/20230420-faxen-advokat-40abb4c1a152@brauner Signed-off-by: Christian Brauner <brauner@kernel.org> Reported-by: Hugh Dickins <hughd@google.com> Link: https://lore.kernel.org/lkml/79eae9fe-7818-a65c-89c6-138b55d609a@google.com Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Adam Manzanares <a.manzanares@samsung.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Kees Cook <keescook@chromium.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Pankaj Raghav <p.raghav@samsung.com> Cc: Yosry Ahmed <yosryahmed@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0175ab6 commit 01106e1

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

mm/shmem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,6 +3582,10 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
35823582
ctx->seen |= SHMEM_SEEN_INUMS;
35833583
break;
35843584
case Opt_noswap:
3585+
if ((fc->user_ns != &init_user_ns) || !capable(CAP_SYS_ADMIN)) {
3586+
return invalfc(fc,
3587+
"Turning off swap in unprivileged tmpfs mounts unsupported");
3588+
}
35853589
ctx->noswap = true;
35863590
ctx->seen |= SHMEM_SEEN_NOSWAP;
35873591
break;

0 commit comments

Comments
 (0)