@@ -32,6 +32,15 @@ struct mnt_idmap nop_mnt_idmap = {
3232};
3333EXPORT_SYMBOL_GPL (nop_mnt_idmap );
3434
35+ /*
36+ * Carries the invalid idmapping of a full 0-4294967295 {g,u}id range.
37+ * This means that all {g,u}ids are mapped to INVALID_VFS{G,U}ID.
38+ */
39+ struct mnt_idmap invalid_mnt_idmap = {
40+ .count = REFCOUNT_INIT (1 ),
41+ };
42+ EXPORT_SYMBOL_GPL (invalid_mnt_idmap );
43+
3544/**
3645 * initial_idmapping - check whether this is the initial mapping
3746 * @ns: idmapping to check
@@ -75,6 +84,8 @@ vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
7584
7685 if (idmap == & nop_mnt_idmap )
7786 return VFSUIDT_INIT (kuid );
87+ if (idmap == & invalid_mnt_idmap )
88+ return INVALID_VFSUID ;
7889 if (initial_idmapping (fs_userns ))
7990 uid = __kuid_val (kuid );
8091 else
@@ -112,6 +123,8 @@ vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
112123
113124 if (idmap == & nop_mnt_idmap )
114125 return VFSGIDT_INIT (kgid );
126+ if (idmap == & invalid_mnt_idmap )
127+ return INVALID_VFSGID ;
115128 if (initial_idmapping (fs_userns ))
116129 gid = __kgid_val (kgid );
117130 else
@@ -140,6 +153,8 @@ kuid_t from_vfsuid(struct mnt_idmap *idmap,
140153
141154 if (idmap == & nop_mnt_idmap )
142155 return AS_KUIDT (vfsuid );
156+ if (idmap == & invalid_mnt_idmap )
157+ return INVALID_UID ;
143158 uid = map_id_up (& idmap -> uid_map , __vfsuid_val (vfsuid ));
144159 if (uid == (uid_t )- 1 )
145160 return INVALID_UID ;
@@ -167,6 +182,8 @@ kgid_t from_vfsgid(struct mnt_idmap *idmap,
167182
168183 if (idmap == & nop_mnt_idmap )
169184 return AS_KGIDT (vfsgid );
185+ if (idmap == & invalid_mnt_idmap )
186+ return INVALID_GID ;
170187 gid = map_id_up (& idmap -> gid_map , __vfsgid_val (vfsgid ));
171188 if (gid == (gid_t )- 1 )
172189 return INVALID_GID ;
@@ -296,7 +313,7 @@ struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns)
296313 */
297314struct mnt_idmap * mnt_idmap_get (struct mnt_idmap * idmap )
298315{
299- if (idmap != & nop_mnt_idmap )
316+ if (idmap != & nop_mnt_idmap && idmap != & invalid_mnt_idmap )
300317 refcount_inc (& idmap -> count );
301318
302319 return idmap ;
@@ -312,7 +329,8 @@ EXPORT_SYMBOL_GPL(mnt_idmap_get);
312329 */
313330void mnt_idmap_put (struct mnt_idmap * idmap )
314331{
315- if (idmap != & nop_mnt_idmap && refcount_dec_and_test (& idmap -> count ))
332+ if (idmap != & nop_mnt_idmap && idmap != & invalid_mnt_idmap &&
333+ refcount_dec_and_test (& idmap -> count ))
316334 free_mnt_idmap (idmap );
317335}
318336EXPORT_SYMBOL_GPL (mnt_idmap_put );
0 commit comments