Skip to contentSkip to conversation

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

PATCH In review Paulo Alcantara 2 participants 3 messages Feb 11, 2024 – Feb 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 smb: client: set correct id, uid and cruid for multiuser automounts

When uid, gid and cruid are not specified, we need to set 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")
---
 fs/smb/client/namespace.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/smb/client/namespace.c +16 -0
index a6968573b775..4a517b280f2b 100644
@@ -168,6 +168,21 @@ static char *automount_fullpath(struct dentry *dentry, void *page)
 	return s;
 }
 
+static void fs_context_set_ids(struct smb3_fs_context *ctx)
+{
+	kuid_t uid = current_fsuid();
+	kgid_t gid = current_fsgid();
+
+	if (ctx->multiuser) {
+		if (!ctx->uid_specified)
+			ctx->linux_uid = uid;
+		if (!ctx->gid_specified)
+			ctx->linux_gid = gid;
+	}
+	if (!ctx->cruid_specified)
+		ctx->cred_uid = uid;
+}
+
 /*
  * Create a vfsmount that we can automount
  */
@@ -205,6 +220,7 @@ static struct vfsmount *cifs_do_automount(struct path *path)
 	tmp.leaf_fullpath = NULL;
 	tmp.UNC = tmp.prepath = NULL;
 	tmp.dfs_root_ses = NULL;
+	fs_context_set_ids(&tmp);
 
 	rc = smb3_fs_context_dup(ctx, &tmp);
 	if (rc) {
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 smb: client: handle path separator of created SMB symlinks

Convert path separator to CIFS_DIR_SEP(cifs_sb) from symlink target before sending it over the wire otherwise the created SMB symlink may become innaccesible from server side.

Fixes 514d793e27a3 ("smb: client: allow creating symlinks via reparse points")
---
 fs/smb/client/smb2ops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +6 -2
index 6b3c384ead0d..4695433fcf39 100644
@@ -5217,7 +5217,7 @@ static int smb2_create_reparse_symlink(const unsigned int xid,
 	struct inode *new;
 	struct kvec iov;
 	__le16 *path;
-	char *sym;
+	char *sym, sep = CIFS_DIR_SEP(cifs_sb);
 	u16 len, plen;
 	int rc = 0;
 
@@ -5231,7 +5231,8 @@ static int smb2_create_reparse_symlink(const unsigned int xid,
 		.symlink_target = sym,
 	};
 
-	path = cifs_convert_path_to_utf16(symname, cifs_sb);
+	convert_delimiter(sym, sep);
+	path = cifs_convert_path_to_utf16(sym, cifs_sb);
 	if (!path) {
 		rc = -ENOMEM;
 		goto out;
@@ -5254,7 +5255,10 @@ static int smb2_create_reparse_symlink(const unsigned int xid,
 	buf->PrintNameLength = cpu_to_le16(plen);
 	memcpy(buf->PathBuffer, path, plen);
 	buf->Flags = cpu_to_le32(*symname != '/' ? SYMLINK_FLAG_RELATIVE : 0);
+	if (*sym != sep)
+		buf->Flags = cpu_to_le32(SYMLINK_FLAG_RELATIVE);
 
+	convert_delimiter(sym, '/');
 	iov.iov_base = buf;
 	iov.iov_len = len;
 	new = smb2_get_reparse_inode(&data, inode->i_sb, xid,
Signature · 1 line
2.43.0
#2 lore raw
In reply to Paulo Alcantara

tentatively merged these two into cifs-2.6.git for-next pending review and testing

Quoted 50 lines · Paulo Alcantara

When uid, gid and cruid are not specified, we need to set 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")
---
 fs/smb/client/namespace.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/smb/client/namespace.c +16 -1
index a6968573b775..4a517b280f2b 100644
@@ -168,6 +168,21 @@ static char *automount_fullpath(struct dentry *dentry, void *page)
        return s;
 }
 
+static void fs_context_set_ids(struct smb3_fs_context *ctx)
+{
+       kuid_t uid = current_fsuid();
+       kgid_t gid = current_fsgid();
+
+       if (ctx->multiuser) {
+               if (!ctx->uid_specified)
+                       ctx->linux_uid = uid;
+               if (!ctx->gid_specified)
+                       ctx->linux_gid = gid;
+       }
+       if (!ctx->cruid_specified)
+               ctx->cred_uid = uid;
+}
+
 /*
  * Create a vfsmount that we can automount
  */
@@ -205,6 +220,7 @@ static struct vfsmount *cifs_do_automount(struct path *path)
        tmp.leaf_fullpath = NULL;
        tmp.UNC = tmp.prepath = NULL;
        tmp.dfs_root_ses = NULL;
+       fs_context_set_ids(&tmp);
 
        rc = smb3_fs_context_dup(ctx, &tmp);
        if (rc) {
--

2.43.0

Signature · 3 lines
Thanks,

Steve