Skip to content

Commit c7c137b

Browse files
author
Steve French
committed
smb3: do not allow insecure cifs mounts when using smb3
if mounting as smb3 do not allow cifs (vers=1.0) or insecure vers=2.0 mounts. For example: root@smf-Thinkpad-P51:~/cifs-2.6# mount -t smb3 //127.0.0.1/scratch /mnt -o username=testuser,password=Testpass1 root@smf-Thinkpad-P51:~/cifs-2.6# umount /mnt root@smf-Thinkpad-P51:~/cifs-2.6# mount -t smb3 //127.0.0.1/scratch /mnt -o username=testuser,password=Testpass1,vers=1.0 mount: /mnt: wrong fs type, bad option, bad superblock on //127.0.0.1/scratch ... root@smf-Thinkpad-P51:~/cifs-2.6# dmesg | grep smb3 [ 4302.200122] CIFS VFS: vers=1.0 (cifs) not permitted when mounting with smb3 root@smf-Thinkpad-P51:~/cifs-2.6# mount -t smb3 //127.0.0.1/scratch /mnt -o username=testuser,password=Testpass1,vers=3.11 Signed-off-by: Steve French <[email protected]> Acked-by: Pavel Shilovsky <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]> Reviewed-by: Sachin Prabhu <[email protected]>
1 parent 8ddecf5 commit c7c137b

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

fs/cifs/cifsfs.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ static int cifs_set_super(struct super_block *sb, void *data)
698698
}
699699

700700
static struct dentry *
701-
cifs_do_mount(struct file_system_type *fs_type,
702-
int flags, const char *dev_name, void *data)
701+
cifs_smb3_do_mount(struct file_system_type *fs_type,
702+
int flags, const char *dev_name, void *data, bool is_smb3)
703703
{
704704
int rc;
705705
struct super_block *sb;
@@ -710,7 +710,7 @@ cifs_do_mount(struct file_system_type *fs_type,
710710

711711
cifs_dbg(FYI, "Devname: %s flags: %d\n", dev_name, flags);
712712

713-
volume_info = cifs_get_volume_info((char *)data, dev_name);
713+
volume_info = cifs_get_volume_info((char *)data, dev_name, is_smb3);
714714
if (IS_ERR(volume_info))
715715
return ERR_CAST(volume_info);
716716

@@ -790,6 +790,20 @@ cifs_do_mount(struct file_system_type *fs_type,
790790
goto out;
791791
}
792792

793+
static struct dentry *
794+
smb3_do_mount(struct file_system_type *fs_type,
795+
int flags, const char *dev_name, void *data)
796+
{
797+
return cifs_smb3_do_mount(fs_type, flags, dev_name, data, true);
798+
}
799+
800+
static struct dentry *
801+
cifs_do_mount(struct file_system_type *fs_type,
802+
int flags, const char *dev_name, void *data)
803+
{
804+
return cifs_smb3_do_mount(fs_type, flags, dev_name, data, false);
805+
}
806+
793807
static ssize_t
794808
cifs_loose_read_iter(struct kiocb *iocb, struct iov_iter *iter)
795809
{
@@ -925,7 +939,7 @@ MODULE_ALIAS_FS("cifs");
925939
static struct file_system_type smb3_fs_type = {
926940
.owner = THIS_MODULE,
927941
.name = "smb3",
928-
.mount = cifs_do_mount,
942+
.mount = smb3_do_mount,
929943
.kill_sb = cifs_kill_sb,
930944
/* .fs_flags */
931945
};

fs/cifs/cifsproto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ extern int cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
211211
extern int cifs_match_super(struct super_block *, void *);
212212
extern void cifs_cleanup_volume_info(struct smb_vol *pvolume_info);
213213
extern struct smb_vol *cifs_get_volume_info(char *mount_data,
214-
const char *devname);
214+
const char *devname, bool is_smb3);
215215
extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *);
216216
extern void cifs_umount(struct cifs_sb_info *);
217217
extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon);

fs/cifs/connect.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static int generic_ip_connect(struct TCP_Server_Info *server);
320320
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
321321
static void cifs_prune_tlinks(struct work_struct *work);
322322
static int cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
323-
const char *devname);
323+
const char *devname, bool is_smb3);
324324

325325
/*
326326
* cifs tcp session reconnection
@@ -1166,7 +1166,7 @@ cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
11661166
}
11671167

11681168
static int
1169-
cifs_parse_smb_version(char *value, struct smb_vol *vol)
1169+
cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3)
11701170
{
11711171
substring_t args[MAX_OPT_ARGS];
11721172

@@ -1176,6 +1176,10 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
11761176
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
11771177
return 1;
11781178
}
1179+
if (is_smb3) {
1180+
cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
1181+
return 1;
1182+
}
11791183
vol->ops = &smb1_operations;
11801184
vol->vals = &smb1_values;
11811185
break;
@@ -1184,6 +1188,10 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
11841188
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
11851189
return 1;
11861190
}
1191+
if (is_smb3) {
1192+
cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n");
1193+
return 1;
1194+
}
11871195
vol->ops = &smb20_operations;
11881196
vol->vals = &smb20_values;
11891197
break;
@@ -1272,7 +1280,7 @@ cifs_parse_devname(const char *devname, struct smb_vol *vol)
12721280

12731281
static int
12741282
cifs_parse_mount_options(const char *mountdata, const char *devname,
1275-
struct smb_vol *vol)
1283+
struct smb_vol *vol, bool is_smb3)
12761284
{
12771285
char *data, *end;
12781286
char *mountdata_copy = NULL, *options;
@@ -1985,7 +1993,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
19851993
if (string == NULL)
19861994
goto out_nomem;
19871995

1988-
if (cifs_parse_smb_version(string, vol) != 0)
1996+
if (cifs_parse_smb_version(string, vol, is_smb3) != 0)
19891997
goto cifs_parse_mount_err;
19901998
got_version = true;
19911999
break;
@@ -3797,7 +3805,7 @@ expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses,
37973805
} else {
37983806
cleanup_volume_info_contents(volume_info);
37993807
rc = cifs_setup_volume_info(volume_info, mdata,
3800-
fake_devname);
3808+
fake_devname, false);
38013809
}
38023810
kfree(fake_devname);
38033811
kfree(cifs_sb->mountdata);
@@ -3810,11 +3818,11 @@ expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses,
38103818

38113819
static int
38123820
cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
3813-
const char *devname)
3821+
const char *devname, bool is_smb3)
38143822
{
38153823
int rc = 0;
38163824

3817-
if (cifs_parse_mount_options(mount_data, devname, volume_info))
3825+
if (cifs_parse_mount_options(mount_data, devname, volume_info, is_smb3))
38183826
return -EINVAL;
38193827

38203828
if (volume_info->nullauth) {
@@ -3848,7 +3856,7 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
38483856
}
38493857

38503858
struct smb_vol *
3851-
cifs_get_volume_info(char *mount_data, const char *devname)
3859+
cifs_get_volume_info(char *mount_data, const char *devname, bool is_smb3)
38523860
{
38533861
int rc;
38543862
struct smb_vol *volume_info;
@@ -3857,7 +3865,7 @@ cifs_get_volume_info(char *mount_data, const char *devname)
38573865
if (!volume_info)
38583866
return ERR_PTR(-ENOMEM);
38593867

3860-
rc = cifs_setup_volume_info(volume_info, mount_data, devname);
3868+
rc = cifs_setup_volume_info(volume_info, mount_data, devname, is_smb3);
38613869
if (rc) {
38623870
cifs_cleanup_volume_info(volume_info);
38633871
volume_info = ERR_PTR(rc);

0 commit comments

Comments
 (0)