Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

smb: client: set correct id, uid and cruid for multiuser automounts

When uid, gid and cruid are not specified, we need to dynamically
set them into the filesystem context used for automounting otherwise
they'll end up reusing the values from the parent mount.

Fixes: 9fd29a5bae6e ("cifs: use fs_context for automounts")
Reported-by: Shane Nehring <snehring@iastate.edu>
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2259257
Cc: stable@vger.kernel.org # 6.2+
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>

authored by

Paulo Alcantara and committed by
Steve French
4508ec17 79520587

+16
+16
fs/smb/client/namespace.c
··· 168 168 return s; 169 169 } 170 170 171 + static void fs_context_set_ids(struct smb3_fs_context *ctx) 172 + { 173 + kuid_t uid = current_fsuid(); 174 + kgid_t gid = current_fsgid(); 175 + 176 + if (ctx->multiuser) { 177 + if (!ctx->uid_specified) 178 + ctx->linux_uid = uid; 179 + if (!ctx->gid_specified) 180 + ctx->linux_gid = gid; 181 + } 182 + if (!ctx->cruid_specified) 183 + ctx->cred_uid = uid; 184 + } 185 + 171 186 /* 172 187 * Create a vfsmount that we can automount 173 188 */ ··· 220 205 tmp.leaf_fullpath = NULL; 221 206 tmp.UNC = tmp.prepath = NULL; 222 207 tmp.dfs_root_ses = NULL; 208 + fs_context_set_ids(&tmp); 223 209 224 210 rc = smb3_fs_context_dup(ctx, &tmp); 225 211 if (rc) {