@@ -32,6 +32,15 @@ struct mnt_idmap nop_mnt_idmap = {
32
32
};
33
33
EXPORT_SYMBOL_GPL (nop_mnt_idmap );
34
34
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
+
35
44
/**
36
45
* initial_idmapping - check whether this is the initial mapping
37
46
* @ns: idmapping to check
@@ -75,6 +84,8 @@ vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
75
84
76
85
if (idmap == & nop_mnt_idmap )
77
86
return VFSUIDT_INIT (kuid );
87
+ if (idmap == & invalid_mnt_idmap )
88
+ return INVALID_VFSUID ;
78
89
if (initial_idmapping (fs_userns ))
79
90
uid = __kuid_val (kuid );
80
91
else
@@ -112,6 +123,8 @@ vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
112
123
113
124
if (idmap == & nop_mnt_idmap )
114
125
return VFSGIDT_INIT (kgid );
126
+ if (idmap == & invalid_mnt_idmap )
127
+ return INVALID_VFSGID ;
115
128
if (initial_idmapping (fs_userns ))
116
129
gid = __kgid_val (kgid );
117
130
else
@@ -140,6 +153,8 @@ kuid_t from_vfsuid(struct mnt_idmap *idmap,
140
153
141
154
if (idmap == & nop_mnt_idmap )
142
155
return AS_KUIDT (vfsuid );
156
+ if (idmap == & invalid_mnt_idmap )
157
+ return INVALID_UID ;
143
158
uid = map_id_up (& idmap -> uid_map , __vfsuid_val (vfsuid ));
144
159
if (uid == (uid_t )- 1 )
145
160
return INVALID_UID ;
@@ -167,6 +182,8 @@ kgid_t from_vfsgid(struct mnt_idmap *idmap,
167
182
168
183
if (idmap == & nop_mnt_idmap )
169
184
return AS_KGIDT (vfsgid );
185
+ if (idmap == & invalid_mnt_idmap )
186
+ return INVALID_GID ;
170
187
gid = map_id_up (& idmap -> gid_map , __vfsgid_val (vfsgid ));
171
188
if (gid == (gid_t )- 1 )
172
189
return INVALID_GID ;
@@ -296,7 +313,7 @@ struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns)
296
313
*/
297
314
struct mnt_idmap * mnt_idmap_get (struct mnt_idmap * idmap )
298
315
{
299
- if (idmap != & nop_mnt_idmap )
316
+ if (idmap != & nop_mnt_idmap && idmap != & invalid_mnt_idmap )
300
317
refcount_inc (& idmap -> count );
301
318
302
319
return idmap ;
@@ -312,7 +329,8 @@ EXPORT_SYMBOL_GPL(mnt_idmap_get);
312
329
*/
313
330
void mnt_idmap_put (struct mnt_idmap * idmap )
314
331
{
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 ))
316
334
free_mnt_idmap (idmap );
317
335
}
318
336
EXPORT_SYMBOL_GPL (mnt_idmap_put );
0 commit comments