@@ -1068,7 +1068,7 @@ static int shmem_getattr(struct mnt_idmap *idmap,
10681068 stat -> attributes_mask |= (STATX_ATTR_APPEND |
10691069 STATX_ATTR_IMMUTABLE |
10701070 STATX_ATTR_NODUMP );
1071- generic_fillattr (& nop_mnt_idmap , inode , stat );
1071+ generic_fillattr (idmap , inode , stat );
10721072
10731073 if (shmem_is_huge (NULL , inode , 0 , false))
10741074 stat -> blksize = HPAGE_PMD_SIZE ;
@@ -1091,7 +1091,7 @@ static int shmem_setattr(struct mnt_idmap *idmap,
10911091 bool update_mtime = false;
10921092 bool update_ctime = true;
10931093
1094- error = setattr_prepare (& nop_mnt_idmap , dentry , attr );
1094+ error = setattr_prepare (idmap , dentry , attr );
10951095 if (error )
10961096 return error ;
10971097
@@ -1129,9 +1129,9 @@ static int shmem_setattr(struct mnt_idmap *idmap,
11291129 }
11301130 }
11311131
1132- setattr_copy (& nop_mnt_idmap , inode , attr );
1132+ setattr_copy (idmap , inode , attr );
11331133 if (attr -> ia_valid & ATTR_MODE )
1134- error = posix_acl_chmod (& nop_mnt_idmap , dentry , inode -> i_mode );
1134+ error = posix_acl_chmod (idmap , dentry , inode -> i_mode );
11351135 if (!error && update_ctime ) {
11361136 inode -> i_ctime = current_time (inode );
11371137 if (update_mtime )
@@ -2329,8 +2329,9 @@ static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags)
23292329#define shmem_initxattrs NULL
23302330#endif
23312331
2332- static struct inode * shmem_get_inode (struct super_block * sb , struct inode * dir ,
2333- umode_t mode , dev_t dev , unsigned long flags )
2332+ static struct inode * shmem_get_inode (struct mnt_idmap * idmap , struct super_block * sb ,
2333+ struct inode * dir , umode_t mode , dev_t dev ,
2334+ unsigned long flags )
23342335{
23352336 struct inode * inode ;
23362337 struct shmem_inode_info * info ;
@@ -2343,7 +2344,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, struct inode *dir,
23432344 inode = new_inode (sb );
23442345 if (inode ) {
23452346 inode -> i_ino = ino ;
2346- inode_init_owner (& nop_mnt_idmap , inode , dir , mode );
2347+ inode_init_owner (idmap , inode , dir , mode );
23472348 inode -> i_blocks = 0 ;
23482349 inode -> i_atime = inode -> i_mtime = inode -> i_ctime = current_time (inode );
23492350 inode -> i_generation = get_random_u32 ();
@@ -2921,7 +2922,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
29212922 struct inode * inode ;
29222923 int error = - ENOSPC ;
29232924
2924- inode = shmem_get_inode (dir -> i_sb , dir , mode , dev , VM_NORESERVE );
2925+ inode = shmem_get_inode (idmap , dir -> i_sb , dir , mode , dev , VM_NORESERVE );
29252926 if (inode ) {
29262927 error = simple_acl_create (dir , inode );
29272928 if (error )
@@ -2952,7 +2953,7 @@ shmem_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
29522953 struct inode * inode ;
29532954 int error = - ENOSPC ;
29542955
2955- inode = shmem_get_inode (dir -> i_sb , dir , mode , 0 , VM_NORESERVE );
2956+ inode = shmem_get_inode (idmap , dir -> i_sb , dir , mode , 0 , VM_NORESERVE );
29562957 if (inode ) {
29572958 error = security_inode_init_security (inode , dir ,
29582959 NULL ,
@@ -2975,8 +2976,8 @@ static int shmem_mkdir(struct mnt_idmap *idmap, struct inode *dir,
29752976{
29762977 int error ;
29772978
2978- if (( error = shmem_mknod (& nop_mnt_idmap , dir , dentry ,
2979- mode | S_IFDIR , 0 )) )
2979+ error = shmem_mknod (idmap , dir , dentry , mode | S_IFDIR , 0 );
2980+ if ( error )
29802981 return error ;
29812982 inc_nlink (dir );
29822983 return 0 ;
@@ -2985,7 +2986,7 @@ static int shmem_mkdir(struct mnt_idmap *idmap, struct inode *dir,
29852986static int shmem_create (struct mnt_idmap * idmap , struct inode * dir ,
29862987 struct dentry * dentry , umode_t mode , bool excl )
29872988{
2988- return shmem_mknod (& nop_mnt_idmap , dir , dentry , mode | S_IFREG , 0 );
2989+ return shmem_mknod (idmap , dir , dentry , mode | S_IFREG , 0 );
29892990}
29902991
29912992/*
@@ -3055,7 +3056,7 @@ static int shmem_whiteout(struct mnt_idmap *idmap,
30553056 if (!whiteout )
30563057 return - ENOMEM ;
30573058
3058- error = shmem_mknod (& nop_mnt_idmap , old_dir , whiteout ,
3059+ error = shmem_mknod (idmap , old_dir , whiteout ,
30593060 S_IFCHR | WHITEOUT_MODE , WHITEOUT_DEV );
30603061 dput (whiteout );
30613062 if (error )
@@ -3098,7 +3099,7 @@ static int shmem_rename2(struct mnt_idmap *idmap,
30983099 if (flags & RENAME_WHITEOUT ) {
30993100 int error ;
31003101
3101- error = shmem_whiteout (& nop_mnt_idmap , old_dir , old_dentry );
3102+ error = shmem_whiteout (idmap , old_dir , old_dentry );
31023103 if (error )
31033104 return error ;
31043105 }
@@ -3136,7 +3137,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
31363137 if (len > PAGE_SIZE )
31373138 return - ENAMETOOLONG ;
31383139
3139- inode = shmem_get_inode (dir -> i_sb , dir , S_IFLNK | 0777 , 0 ,
3140+ inode = shmem_get_inode (idmap , dir -> i_sb , dir , S_IFLNK | 0777 , 0 ,
31403141 VM_NORESERVE );
31413142 if (!inode )
31423143 return - ENOSPC ;
@@ -3819,7 +3820,8 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
38193820#endif
38203821 uuid_gen (& sb -> s_uuid );
38213822
3822- inode = shmem_get_inode (sb , NULL , S_IFDIR | sbinfo -> mode , 0 , VM_NORESERVE );
3823+ inode = shmem_get_inode (& nop_mnt_idmap , sb , NULL , S_IFDIR | sbinfo -> mode , 0 ,
3824+ VM_NORESERVE );
38233825 if (!inode )
38243826 goto failed ;
38253827 inode -> i_uid = sbinfo -> uid ;
@@ -4044,7 +4046,11 @@ static struct file_system_type shmem_fs_type = {
40444046 .parameters = shmem_fs_parameters ,
40454047#endif
40464048 .kill_sb = kill_litter_super ,
4049+ #ifdef CONFIG_SHMEM
4050+ .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP ,
4051+ #else
40474052 .fs_flags = FS_USERNS_MOUNT ,
4053+ #endif
40484054};
40494055
40504056void __init shmem_init (void )
@@ -4196,7 +4202,7 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
41964202#define shmem_vm_ops generic_file_vm_ops
41974203#define shmem_anon_vm_ops generic_file_vm_ops
41984204#define shmem_file_operations ramfs_file_operations
4199- #define shmem_get_inode (sb , dir , mode , dev , flags ) ramfs_get_inode(sb, dir, mode, dev)
4205+ #define shmem_get_inode (idmap , sb , dir , mode , dev , flags ) ramfs_get_inode(sb, dir, mode, dev)
42004206#define shmem_acct_size (flags , size ) 0
42014207#define shmem_unacct_size (flags , size ) do {} while (0)
42024208
@@ -4219,8 +4225,11 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l
42194225 if (shmem_acct_size (flags , size ))
42204226 return ERR_PTR (- ENOMEM );
42214227
4222- inode = shmem_get_inode (mnt -> mnt_sb , NULL , S_IFREG | S_IRWXUGO , 0 ,
4223- flags );
4228+ if (is_idmapped_mnt (mnt ))
4229+ return ERR_PTR (- EINVAL );
4230+
4231+ inode = shmem_get_inode (& nop_mnt_idmap , mnt -> mnt_sb , NULL ,
4232+ S_IFREG | S_IRWXUGO , 0 , flags );
42244233 if (unlikely (!inode )) {
42254234 shmem_unacct_size (flags , size );
42264235 return ERR_PTR (- ENOSPC );
0 commit comments