Skip to content

Commit

Permalink
cifs: use helpers when parsing uid/gid mount options and validate them
Browse files Browse the repository at this point in the history
[ Upstream commit e0a3cbc ]

Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount arguments.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Acked-by: Pavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Ronnie Sahlberg authored and gregkh committed Aug 8, 2021
1 parent 2abe7e0 commit cf5663d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions fs/cifs/fs_context.c
Expand Up @@ -322,7 +322,6 @@ 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;

/*
* Make sure to stay in sync with smb3_cleanup_fs_context_contents()
*/
Expand Down Expand Up @@ -792,6 +791,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);

Expand Down Expand Up @@ -904,18 +905,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:
Expand Down
1 change: 1 addition & 0 deletions fs/cifs/fs_context.h
Expand Up @@ -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;
Expand Down

0 comments on commit cf5663d

Please sign in to comment.