linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs: set the cred_uid/linux_uid/linux_gid when duplicating contexts
@ 2021-06-23 22:00 Ronnie Sahlberg
  2021-06-24  0:34 ` Steve French
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2021-06-23 22:00 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount
arguments.
Also, when we duplicate a context, for example in multiuser,cruid=xxx we need to
re-set these uid/gids to the current user or else we may get a crash.

Fixes: 24e0a1eff9e2 ("cifs: switch to new mount api")
Cc: stable@vger.kernel.org # 5.11
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/fs_context.c | 27 ++++++++++++++++++++++-----
 fs/cifs/fs_context.h |  1 +
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
index 92d4ab029c91..39bebe298387 100644
--- a/fs/cifs/fs_context.c
+++ b/fs/cifs/fs_context.c
@@ -322,7 +322,9 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
 	new_ctx->UNC = NULL;
 	new_ctx->source = NULL;
 	new_ctx->iocharset = NULL;
-
+	new_ctx->linux_uid = current_fsuid();
+	new_ctx->cred_uid = current_fsuid();
+	new_ctx->linux_gid = current_fsgid();
 	/*
 	 * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
 	 */
@@ -792,6 +794,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 	int i, opt;
 	bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
 	bool skip_parsing = false;
+	kuid_t uid;
+	kgid_t gid;
 
 	cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
 
@@ -904,18 +908,31 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 		}
 		break;
 	case Opt_uid:
-		ctx->linux_uid.val = result.uint_32;
+		uid = make_kuid(current_user_ns(), result.uint_32);
+		if (!uid_valid(uid))
+			goto cifs_parse_mount_err;
+		ctx->linux_uid = uid;
 		ctx->uid_specified = true;
 		break;
 	case Opt_cruid:
-		ctx->cred_uid.val = result.uint_32;
+		uid = make_kuid(current_user_ns(), result.uint_32);
+		if (!uid_valid(uid))
+			goto cifs_parse_mount_err;
+		ctx->cred_uid = uid;
+		ctx->cruid_specified = true;
 		break;
 	case Opt_backupgid:
-		ctx->backupgid.val = result.uint_32;
+		gid = make_kgid(current_user_ns(), result.uint_32);
+		if (!gid_valid(gid))
+			goto cifs_parse_mount_err;
+		ctx->backupgid = gid;
 		ctx->backupgid_specified = true;
 		break;
 	case Opt_gid:
-		ctx->linux_gid.val = result.uint_32;
+		gid = make_kgid(current_user_ns(), result.uint_32);
+		if (!gid_valid(gid))
+			goto cifs_parse_mount_err;
+		ctx->linux_gid = gid;
 		ctx->gid_specified = true;
 		break;
 	case Opt_port:
diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h
index 2a71c8e411ac..b6243972edf3 100644
--- a/fs/cifs/fs_context.h
+++ b/fs/cifs/fs_context.h
@@ -155,6 +155,7 @@ enum cifs_param {
 
 struct smb3_fs_context {
 	bool uid_specified;
+	bool cruid_specified;
 	bool gid_specified;
 	bool sloppy;
 	bool got_ip;
-- 
2.30.2


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

* Re: [PATCH] cifs: set the cred_uid/linux_uid/linux_gid when duplicating contexts
  2021-06-23 22:00 [PATCH] cifs: set the cred_uid/linux_uid/linux_gid when duplicating contexts Ronnie Sahlberg
@ 2021-06-24  0:34 ` Steve French
  0 siblings, 0 replies; 2+ messages in thread
From: Steve French @ 2021-06-24  0:34 UTC (permalink / raw)
  To: Ronnie Sahlberg; +Cc: linux-cifs

tentatively merged into cifs-2.6.git for-next pending more testing

On Wed, Jun 23, 2021 at 5:00 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount
> arguments.
> Also, when we duplicate a context, for example in multiuser,cruid=xxx we need to
> re-set these uid/gids to the current user or else we may get a crash.
>
> Fixes: 24e0a1eff9e2 ("cifs: switch to new mount api")
> Cc: stable@vger.kernel.org # 5.11
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/fs_context.c | 27 ++++++++++++++++++++++-----
>  fs/cifs/fs_context.h |  1 +
>  2 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
> index 92d4ab029c91..39bebe298387 100644
> --- a/fs/cifs/fs_context.c
> +++ b/fs/cifs/fs_context.c
> @@ -322,7 +322,9 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
>         new_ctx->UNC = NULL;
>         new_ctx->source = NULL;
>         new_ctx->iocharset = NULL;
> -
> +       new_ctx->linux_uid = current_fsuid();
> +       new_ctx->cred_uid = current_fsuid();
> +       new_ctx->linux_gid = current_fsgid();
>         /*
>          * Make sure to stay in sync with smb3_cleanup_fs_context_contents()
>          */
> @@ -792,6 +794,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
>         int i, opt;
>         bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
>         bool skip_parsing = false;
> +       kuid_t uid;
> +       kgid_t gid;
>
>         cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
>
> @@ -904,18 +908,31 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
>                 }
>                 break;
>         case Opt_uid:
> -               ctx->linux_uid.val = result.uint_32;
> +               uid = make_kuid(current_user_ns(), result.uint_32);
> +               if (!uid_valid(uid))
> +                       goto cifs_parse_mount_err;
> +               ctx->linux_uid = uid;
>                 ctx->uid_specified = true;
>                 break;
>         case Opt_cruid:
> -               ctx->cred_uid.val = result.uint_32;
> +               uid = make_kuid(current_user_ns(), result.uint_32);
> +               if (!uid_valid(uid))
> +                       goto cifs_parse_mount_err;
> +               ctx->cred_uid = uid;
> +               ctx->cruid_specified = true;
>                 break;
>         case Opt_backupgid:
> -               ctx->backupgid.val = result.uint_32;
> +               gid = make_kgid(current_user_ns(), result.uint_32);
> +               if (!gid_valid(gid))
> +                       goto cifs_parse_mount_err;
> +               ctx->backupgid = gid;
>                 ctx->backupgid_specified = true;
>                 break;
>         case Opt_gid:
> -               ctx->linux_gid.val = result.uint_32;
> +               gid = make_kgid(current_user_ns(), result.uint_32);
> +               if (!gid_valid(gid))
> +                       goto cifs_parse_mount_err;
> +               ctx->linux_gid = gid;
>                 ctx->gid_specified = true;
>                 break;
>         case Opt_port:
> diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h
> index 2a71c8e411ac..b6243972edf3 100644
> --- a/fs/cifs/fs_context.h
> +++ b/fs/cifs/fs_context.h
> @@ -155,6 +155,7 @@ enum cifs_param {
>
>  struct smb3_fs_context {
>         bool uid_specified;
> +       bool cruid_specified;
>         bool gid_specified;
>         bool sloppy;
>         bool got_ip;
> --
> 2.30.2
>


-- 
Thanks,

Steve

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

end of thread, other threads:[~2021-06-24  0:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 22:00 [PATCH] cifs: set the cred_uid/linux_uid/linux_gid when duplicating contexts Ronnie Sahlberg
2021-06-24  0:34 ` 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).