cifs: use helpers when parsing uid/gid mount options and
Subsystems (2)
cover cifs: use helpers when parsing uid/gid mount options and
Steve,
This is a small patch to use the existing helpers to validate the uid/gid values that can be passed as mount arguments.
PATCH 1/1 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.
--- fs/cifs/fs_context.c | 24 +++++++++++++++++++----- fs/cifs/fs_context.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-)
fs/cifs/fs_context.c +19 -5
@@ -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() */
@@ -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);
@@ -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:
fs/cifs/fs_context.h +1 -0
@@ -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;
Signature · 1 line
2.30.2
Re: [PATCH] cifs: use helpers when parsing uid/gid mount options and validate them
tentatively merged into cifs-2.6.git pending testing
Quoted 81 lines · Ronnie Sahlberg
Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount arguments.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/fs_context.c | 24 +++++++++++++++++++----- fs/cifs/fs_context.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-)fs/cifs/fs_context.c +19
-5@@ -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() */ @@ -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);@@ -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:fs/cifs/fs_context.h +1
-1@@ -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
Signature · 3 lines
Thanks, Steve
Re: [PATCH] cifs: use helpers when parsing uid/gid mount options and validate them
In reply to Ronnie Sahlbergср, 7 июл. 2021 г. в 16:25, Ronnie Sahlberg <[email protected]>:
Quoted 71 lines
Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount arguments.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/fs_context.c | 24 +++++++++++++++++++----- fs/cifs/fs_context.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-)fs/cifs/fs_context.c +19
-5@@ -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() */ @@ -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);@@ -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:fs/cifs/fs_context.h +0
-0
fs/cifs/fs_context.h enum cifs_param { · line 158
Quoted 4 lines
fs/cifs/fs_context.h +1
-0@@ -155,6 +155,7 @@ enum cifs_param {struct smb3_fs_context {bool uid_specified; +bool cruid_specified;
Is it going to be used somewhere?
Quoted 6 lines
fs/cifs/fs_context.h +0
-1bool gid_specified;bool sloppy;bool got_ip; --2.30.2
--
Best regards,
Pavel Shilovsky
ronnie sahlberg
reviewerRe: [PATCH] cifs: use helpers when parsing uid/gid mount options and validate them
Quoted 74 lines · Pavel Shilovsky
ср, 7 июл. 2021 г. в 16:25, Ronnie Sahlberg <[email protected]>:
Quoted 72 lines
Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount arguments.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/fs_context.c | 24 +++++++++++++++++++----- fs/cifs/fs_context.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-)fs/cifs/fs_context.c +19
-5@@ -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() */ @@ -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);@@ -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:fs/cifs/fs_context.h +0
-0@@ -155,6 +155,7 @@ enum cifs_param {
Quoted 5 lines
fs/cifs/fs_context.h enum cifs_param { · line 158
Quoted 3 lines
fs/cifs/fs_context.h +1
-0struct smb3_fs_context {bool uid_specified; +bool cruid_specified;Is it going to be used somewhere?
I use it in other patches, and may add a similar variable to the session structure as well so we can change the code where we print the mount argument and make it conditional on whether cruid was set on the original command line or not.
We currently always print cruid as a mount argument in the mount output and print it as cruid=0 if it was not specified, which is fine but may be confusing/redundant.
I am fine with either leaving it in or removing it, and I can add it back later once it actually starts being used.
Quoted 13 lines
Quoted 7 lines
fs/cifs/fs_context.h +0
-1bool gid_specified;bool sloppy;bool got_ip; --2.30.2
Acked-by Pavel Shilovsky <[email protected]>--
Best regards,
Pavel Shilovsky
Re: [PATCH] cifs: use helpers when parsing uid/gid mount options and validate them
mildy easier to leave it in at the moment - if you want to remove it later with a followon that is fine too
Quoted 106 lines · ronnie sahlberg
Quoted 74 lines · Pavel Shilovsky
ср, 7 июл. 2021 г. в 16:25, Ronnie Sahlberg <[email protected]>:
Quoted 72 lines
Use the nice helpers to initialize and the uid/gid/cred_uid when passed as mount arguments.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/fs_context.c | 24 +++++++++++++++++++----- fs/cifs/fs_context.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-)fs/cifs/fs_context.c +19
-5@@ -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() */ @@ -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);@@ -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:fs/cifs/fs_context.h +0
-0@@ -155,6 +155,7 @@ enum cifs_param {Quoted 5 lines
fs/cifs/fs_context.h enum cifs_param { · line 158
Quoted 3 lines
fs/cifs/fs_context.h +1
-0struct smb3_fs_context {bool uid_specified; +bool cruid_specified;Is it going to be used somewhere?
I use it in other patches, and may add a similar variable to the session structure as well so we can change the code where we print the mount argument and make it conditional on whether cruid was set on the original command line or not.
We currently always print cruid as a mount argument in the mount output and print it as cruid=0 if it was not specified, which is fine but may be confusing/redundant.I am fine with either leaving it in or removing it, and I can add it back later once it actually starts being used.
Quoted 13 lines
Quoted 7 lines
fs/cifs/fs_context.h +0
-1bool gid_specified;bool sloppy;bool got_ip; --2.30.2
Acked-by Pavel Shilovsky <[email protected]>--
Best regards,
Pavel Shilovsky
Signature · 3 lines
Thanks, Steve