diff options
author | Christian Brauner <[email protected]> | 2023-04-20 10:57:43 +0200 |
---|---|---|
committer | Andrew Morton <[email protected]> | 2023-04-27 13:42:16 -0700 |
commit | 01106e140835ff94fdef79d66f166b87b0c89824 (patch) | |
tree | 4a0cfc25e0915655523eeb108e47cae5c61ac3e6 | |
parent | 0175ab610c2df7c21d93e4bd63b4e67cfa86737c (diff) |
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 <[email protected]>
Reported-by: Hugh Dickins <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
Reviewed-by: Luis Chamberlain <[email protected]>
Cc: Adam Manzanares <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Pankaj Raghav <[email protected]>
Cc: Yosry Ahmed <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r-- | mm/shmem.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index 3531ebb3494e..1a6263f54ada 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3582,6 +3582,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; |