Skip to content

Commit e0a3cbc

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: use helpers when parsing uid/gid mount options and validate them
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>
1 parent d4dc277 commit e0a3cbc

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

fs/cifs/fs_context.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
322322
new_ctx->UNC = NULL;
323323
new_ctx->source = NULL;
324324
new_ctx->iocharset = NULL;
325-
326325
/*
327326
* Make sure to stay in sync with smb3_cleanup_fs_context_contents()
328327
*/
@@ -792,6 +791,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
792791
int i, opt;
793792
bool is_smb3 = !strcmp(fc->fs_type->name, "smb3");
794793
bool skip_parsing = false;
794+
kuid_t uid;
795+
kgid_t gid;
795796

796797
cifs_dbg(FYI, "CIFS: parsing cifs mount option '%s'\n", param->key);
797798

@@ -904,18 +905,31 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
904905
}
905906
break;
906907
case Opt_uid:
907-
ctx->linux_uid.val = result.uint_32;
908+
uid = make_kuid(current_user_ns(), result.uint_32);
909+
if (!uid_valid(uid))
910+
goto cifs_parse_mount_err;
911+
ctx->linux_uid = uid;
908912
ctx->uid_specified = true;
909913
break;
910914
case Opt_cruid:
911-
ctx->cred_uid.val = result.uint_32;
915+
uid = make_kuid(current_user_ns(), result.uint_32);
916+
if (!uid_valid(uid))
917+
goto cifs_parse_mount_err;
918+
ctx->cred_uid = uid;
919+
ctx->cruid_specified = true;
912920
break;
913921
case Opt_backupgid:
914-
ctx->backupgid.val = result.uint_32;
922+
gid = make_kgid(current_user_ns(), result.uint_32);
923+
if (!gid_valid(gid))
924+
goto cifs_parse_mount_err;
925+
ctx->backupgid = gid;
915926
ctx->backupgid_specified = true;
916927
break;
917928
case Opt_gid:
918-
ctx->linux_gid.val = result.uint_32;
929+
gid = make_kgid(current_user_ns(), result.uint_32);
930+
if (!gid_valid(gid))
931+
goto cifs_parse_mount_err;
932+
ctx->linux_gid = gid;
919933
ctx->gid_specified = true;
920934
break;
921935
case Opt_port:

fs/cifs/fs_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ enum cifs_param {
155155

156156
struct smb3_fs_context {
157157
bool uid_specified;
158+
bool cruid_specified;
158159
bool gid_specified;
159160
bool sloppy;
160161
bool got_ip;

0 commit comments

Comments
 (0)