Re: [PATCH 27/27] fs: make nop_mnt_idmap and invalid_mnt_idmap const

From: Jan Kara

Date: Wed Sep 02 2026 - 12:36:10 EST


On Tue 01-09-26 14:14:52, Christian Brauner wrote:
> Make both static maps const so they end up in rodata. Any attempt to
> modify them now faults instead of silently corrupting the initial
> idmapping.
>
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza

> ---
> fs/mnt_idmapping.c | 4 ++--
> include/linux/mnt_idmapping.h | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/mnt_idmapping.c b/fs/mnt_idmapping.c
> index 26704eeb7318..bed57094cef0 100644
> --- a/fs/mnt_idmapping.c
> +++ b/fs/mnt_idmapping.c
> @@ -28,7 +28,7 @@ struct mnt_idmap {
> * mapping. This means that {g,u}id 0 is mapped to {g,u}id 0, {g,u}id 1 is
> * mapped to {g,u}id 1, [...], {g,u}id 1000 to {g,u}id 1000, [...].
> */
> -struct mnt_idmap nop_mnt_idmap = {
> +const struct mnt_idmap nop_mnt_idmap = {
> .count = REFCOUNT_INIT(1),
> };
> EXPORT_SYMBOL_GPL(nop_mnt_idmap);
> @@ -37,7 +37,7 @@ EXPORT_SYMBOL_GPL(nop_mnt_idmap);
> * Carries the invalid idmapping of a full 0-4294967295 {g,u}id range.
> * This means that all {g,u}ids are mapped to INVALID_VFS{G,U}ID.
> */
> -struct mnt_idmap invalid_mnt_idmap = {
> +const struct mnt_idmap invalid_mnt_idmap = {
> .count = REFCOUNT_INIT(1),
> };
> EXPORT_SYMBOL_GPL(invalid_mnt_idmap);
> diff --git a/include/linux/mnt_idmapping.h b/include/linux/mnt_idmapping.h
> index b445c7660040..78eeef4c2996 100644
> --- a/include/linux/mnt_idmapping.h
> +++ b/include/linux/mnt_idmapping.h
> @@ -8,8 +8,8 @@
> struct mnt_idmap;
> struct user_namespace;
>
> -extern struct mnt_idmap nop_mnt_idmap;
> -extern struct mnt_idmap invalid_mnt_idmap;
> +extern const struct mnt_idmap nop_mnt_idmap;
> +extern const struct mnt_idmap invalid_mnt_idmap;
> extern struct user_namespace init_user_ns;
>
> typedef struct {
>
> --
> 2.53.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR