@@ -114,7 +114,11 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,
114
114
{
115
115
struct fuse_conn * fc = fm -> fc ;
116
116
struct fuse_req * req ;
117
+ bool no_idmap = !fm -> sb || (fm -> sb -> s_iflags & SB_I_NOIDMAP );
118
+ kuid_t fsuid ;
119
+ kgid_t fsgid ;
117
120
int err ;
121
+
118
122
atomic_inc (& fc -> num_waiting );
119
123
120
124
if (fuse_block_alloc (fc , for_background )) {
@@ -148,29 +152,24 @@ static struct fuse_req *fuse_get_req(struct mnt_idmap *idmap,
148
152
if (for_background )
149
153
__set_bit (FR_BACKGROUND , & req -> flags );
150
154
151
- if (!fm -> sb || (fm -> sb -> s_iflags & SB_I_NOIDMAP ) || idmap ) {
152
- kuid_t idmapped_fsuid ;
153
- kgid_t idmapped_fsgid ;
155
+ /*
156
+ * Keep the old behavior when idmappings support was not
157
+ * declared by a FUSE server.
158
+ *
159
+ * For those FUSE servers who support idmapped mounts,
160
+ * we send UID/GID only along with "inode creation"
161
+ * fuse requests, otherwise idmap == &invalid_mnt_idmap and
162
+ * req->in.h.{u,g}id will be equal to FUSE_INVALID_UIDGID.
163
+ */
164
+ fsuid = no_idmap ? current_fsuid () : mapped_fsuid (idmap , fc -> user_ns );
165
+ fsgid = no_idmap ? current_fsgid () : mapped_fsgid (idmap , fc -> user_ns );
166
+ req -> in .h .uid = from_kuid (fc -> user_ns , fsuid );
167
+ req -> in .h .gid = from_kgid (fc -> user_ns , fsgid );
154
168
155
- /*
156
- * Note, that when
157
- * (fm->sb->s_iflags & SB_I_NOIDMAP) is true, then
158
- * (idmap == &nop_mnt_idmap) is always true and therefore,
159
- * mapped_fsuid(idmap, fc->user_ns) == current_fsuid().
160
- */
161
- idmapped_fsuid = idmap ? mapped_fsuid (idmap , fc -> user_ns ) : current_fsuid ();
162
- idmapped_fsgid = idmap ? mapped_fsgid (idmap , fc -> user_ns ) : current_fsgid ();
163
- req -> in .h .uid = from_kuid (fc -> user_ns , idmapped_fsuid );
164
- req -> in .h .gid = from_kgid (fc -> user_ns , idmapped_fsgid );
165
-
166
- if (unlikely (req -> in .h .uid == ((uid_t )- 1 ) ||
167
- req -> in .h .gid == ((gid_t )- 1 ))) {
168
- fuse_put_request (req );
169
- return ERR_PTR (- EOVERFLOW );
170
- }
171
- } else {
172
- req -> in .h .uid = FUSE_INVALID_UIDGID ;
173
- req -> in .h .gid = FUSE_INVALID_UIDGID ;
169
+ if (no_idmap && unlikely (req -> in .h .uid == ((uid_t )- 1 ) ||
170
+ req -> in .h .gid == ((gid_t )- 1 ))) {
171
+ fuse_put_request (req );
172
+ return ERR_PTR (- EOVERFLOW );
174
173
}
175
174
176
175
return req ;
@@ -619,7 +618,7 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args,
619
618
__set_bit (FR_BACKGROUND , & req -> flags );
620
619
} else {
621
620
WARN_ON (args -> nocreds );
622
- req = fuse_get_req (NULL , fm , true);
621
+ req = fuse_get_req (& invalid_mnt_idmap , fm , true);
623
622
if (IS_ERR (req ))
624
623
return PTR_ERR (req );
625
624
}
@@ -641,7 +640,7 @@ static int fuse_simple_notify_reply(struct fuse_mount *fm,
641
640
struct fuse_req * req ;
642
641
struct fuse_iqueue * fiq = & fm -> fc -> iq ;
643
642
644
- req = fuse_get_req (NULL , fm , false);
643
+ req = fuse_get_req (& invalid_mnt_idmap , fm , false);
645
644
if (IS_ERR (req ))
646
645
return PTR_ERR (req );
647
646
0 commit comments