linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts
@ 2024-02-11 23:19 Paulo Alcantara
  2024-02-11 23:19 ` [PATCH 2/2] smb: client: handle path separator of created SMB symlinks Paulo Alcantara
  2024-02-12  3:06 ` [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Steve French
  0 siblings, 2 replies; 3+ messages in thread
From: Paulo Alcantara @ 2024-02-11 23:19 UTC (permalink / raw)
  To: smfrench; +Cc: linux-cifs, Paulo Alcantara, Shane Nehring

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")
Reported-by: Shane Nehring <snehring@iastate.edu>
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2259257
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
---
 fs/smb/client/namespace.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/smb/client/namespace.c b/fs/smb/client/namespace.c
index a6968573b775..4a517b280f2b 100644
--- a/fs/smb/client/namespace.c
+++ b/fs/smb/client/namespace.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] smb: client: handle path separator of created SMB symlinks
  2024-02-11 23:19 [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Paulo Alcantara
@ 2024-02-11 23:19 ` Paulo Alcantara
  2024-02-12  3:06 ` [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Steve French
  1 sibling, 0 replies; 3+ messages in thread
From: Paulo Alcantara @ 2024-02-11 23:19 UTC (permalink / raw)
  To: smfrench; +Cc: linux-cifs, Paulo Alcantara

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")
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
---
 fs/smb/client/smb2ops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 6b3c384ead0d..4695433fcf39 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts
  2024-02-11 23:19 [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Paulo Alcantara
  2024-02-11 23:19 ` [PATCH 2/2] smb: client: handle path separator of created SMB symlinks Paulo Alcantara
@ 2024-02-12  3:06 ` Steve French
  1 sibling, 0 replies; 3+ messages in thread
From: Steve French @ 2024-02-12  3:06 UTC (permalink / raw)
  To: Paulo Alcantara; +Cc: linux-cifs, Shane Nehring

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

On Sun, Feb 11, 2024 at 5:20 PM Paulo Alcantara <pc@manguebit.com> wrote:
>
> 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")
> Reported-by: Shane Nehring <snehring@iastate.edu>
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2259257
> Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
> ---
>  fs/smb/client/namespace.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/fs/smb/client/namespace.c b/fs/smb/client/namespace.c
> index a6968573b775..4a517b280f2b 100644
> --- a/fs/smb/client/namespace.c
> +++ b/fs/smb/client/namespace.c
> @@ -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
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-12  3:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-11 23:19 [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Paulo Alcantara
2024-02-11 23:19 ` [PATCH 2/2] smb: client: handle path separator of created SMB symlinks Paulo Alcantara
2024-02-12  3:06 ` [PATCH 1/2] smb: client: set correct id, uid and cruid for multiuser automounts Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).