Skip to content

Commit b9ee2e3

Browse files
Paulo AlcantaraSteve French
authored andcommitted
cifs: improve checking of DFS links over STATUS_OBJECT_NAME_INVALID
Do not map STATUS_OBJECT_NAME_INVALID to -EREMOTE under non-DFS shares, or 'nodfs' mounts or CONFIG_CIFS_DFS_UPCALL=n builds. Otherwise, in the slow path, get a referral to figure out whether it is an actual DFS link. This could be simply reproduced under a non-DFS share by running the following $ mount.cifs //srv/share /mnt -o ... $ cat /mnt/$(printf '\U110000') cat: '/mnt/'$'\364\220\200\200': Object is remote Fixes: c877ce4 ("cifs: reduce roundtrips on create/qinfo requests") CC: [email protected] # 6.2 Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4c0421f commit b9ee2e3

File tree

4 files changed

+106
-25
lines changed

4 files changed

+106
-25
lines changed

fs/cifs/cifsproto.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,21 @@ static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
667667
int match_target_ip(struct TCP_Server_Info *server,
668668
const char *share, size_t share_len,
669669
bool *result);
670-
671-
int cifs_dfs_query_info_nonascii_quirk(const unsigned int xid,
672-
struct cifs_tcon *tcon,
673-
struct cifs_sb_info *cifs_sb,
674-
const char *dfs_link_path);
670+
int cifs_inval_name_dfs_link_error(const unsigned int xid,
671+
struct cifs_tcon *tcon,
672+
struct cifs_sb_info *cifs_sb,
673+
const char *full_path,
674+
bool *islink);
675+
#else
676+
static inline int cifs_inval_name_dfs_link_error(const unsigned int xid,
677+
struct cifs_tcon *tcon,
678+
struct cifs_sb_info *cifs_sb,
679+
const char *full_path,
680+
bool *islink)
681+
{
682+
*islink = false;
683+
return 0;
684+
}
675685
#endif
676686

677687
static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options)

fs/cifs/misc.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "cifsfs.h"
2222
#ifdef CONFIG_CIFS_DFS_UPCALL
2323
#include "dns_resolve.h"
24+
#include "dfs_cache.h"
2425
#endif
2526
#include "fs_context.h"
2627
#include "cached_dir.h"
@@ -1198,4 +1199,70 @@ int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix)
11981199
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH;
11991200
return 0;
12001201
}
1202+
1203+
/*
1204+
* Handle weird Windows SMB server behaviour. It responds with
1205+
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request for
1206+
* "\<server>\<dfsname>\<linkpath>" DFS reference, where <dfsname> contains
1207+
* non-ASCII unicode symbols.
1208+
*/
1209+
int cifs_inval_name_dfs_link_error(const unsigned int xid,
1210+
struct cifs_tcon *tcon,
1211+
struct cifs_sb_info *cifs_sb,
1212+
const char *full_path,
1213+
bool *islink)
1214+
{
1215+
struct cifs_ses *ses = tcon->ses;
1216+
size_t len;
1217+
char *path;
1218+
char *ref_path;
1219+
1220+
*islink = false;
1221+
1222+
/*
1223+
* Fast path - skip check when @full_path doesn't have a prefix path to
1224+
* look up or tcon is not DFS.
1225+
*/
1226+
if (strlen(full_path) < 2 || !cifs_sb ||
1227+
(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS) ||
1228+
!is_tcon_dfs(tcon) || !ses->server->origin_fullpath)
1229+
return 0;
1230+
1231+
/*
1232+
* Slow path - tcon is DFS and @full_path has prefix path, so attempt
1233+
* to get a referral to figure out whether it is an DFS link.
1234+
*/
1235+
len = strnlen(tcon->tree_name, MAX_TREE_SIZE + 1) + strlen(full_path) + 1;
1236+
path = kmalloc(len, GFP_KERNEL);
1237+
if (!path)
1238+
return -ENOMEM;
1239+
1240+
scnprintf(path, len, "%s%s", tcon->tree_name, full_path);
1241+
ref_path = dfs_cache_canonical_path(path + 1, cifs_sb->local_nls,
1242+
cifs_remap(cifs_sb));
1243+
kfree(path);
1244+
1245+
if (IS_ERR(ref_path)) {
1246+
if (PTR_ERR(ref_path) != -EINVAL)
1247+
return PTR_ERR(ref_path);
1248+
} else {
1249+
struct dfs_info3_param *refs = NULL;
1250+
int num_refs = 0;
1251+
1252+
/*
1253+
* XXX: we are not using dfs_cache_find() here because we might
1254+
* end filling all the DFS cache and thus potentially
1255+
* removing cached DFS targets that the client would eventually
1256+
* need during failover.
1257+
*/
1258+
if (ses->server->ops->get_dfs_refer &&
1259+
!ses->server->ops->get_dfs_refer(xid, ses, ref_path, &refs,
1260+
&num_refs, cifs_sb->local_nls,
1261+
cifs_remap(cifs_sb)))
1262+
*islink = refs[0].server_type == DFS_TYPE_LINK;
1263+
free_dfs_info_array(refs, num_refs);
1264+
kfree(ref_path);
1265+
}
1266+
return 0;
1267+
}
12011268
#endif

fs/cifs/smb2inode.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,13 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
527527
struct cifs_sb_info *cifs_sb, const char *full_path,
528528
struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse)
529529
{
530-
int rc;
531530
__u32 create_options = 0;
532531
struct cifsFileInfo *cfile;
533532
struct cached_fid *cfid = NULL;
534533
struct kvec err_iov[3] = {};
535534
int err_buftype[3] = {};
535+
bool islink;
536+
int rc, rc2;
536537

537538
*adjust_tz = false;
538539
*reparse = false;
@@ -580,15 +581,15 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
580581
SMB2_OP_QUERY_INFO, cfile, NULL, NULL,
581582
NULL, NULL);
582583
goto out;
583-
} else if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
584-
hdr->Status == STATUS_OBJECT_NAME_INVALID) {
585-
/*
586-
* Handle weird Windows SMB server behaviour. It responds with
587-
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
588-
* for "\<server>\<dfsname>\<linkpath>" DFS reference,
589-
* where <dfsname> contains non-ASCII unicode symbols.
590-
*/
591-
rc = -EREMOTE;
584+
} else if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
585+
rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
586+
full_path, &islink);
587+
if (rc2) {
588+
rc = rc2;
589+
goto out;
590+
}
591+
if (islink)
592+
rc = -EREMOTE;
592593
}
593594
if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
594595
(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))

fs/cifs/smb2ops.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,15 @@ static int
796796
smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
797797
struct cifs_sb_info *cifs_sb, const char *full_path)
798798
{
799-
int rc;
800799
__le16 *utf16_path;
801800
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
802801
int err_buftype = CIFS_NO_BUFFER;
803802
struct cifs_open_parms oparms;
804803
struct kvec err_iov = {};
805804
struct cifs_fid fid;
806805
struct cached_fid *cfid;
806+
bool islink;
807+
int rc, rc2;
807808

808809
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
809810
if (!rc) {
@@ -833,15 +834,17 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
833834

834835
if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
835836
goto out;
836-
/*
837-
* Handle weird Windows SMB server behaviour. It responds with
838-
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
839-
* for "\<server>\<dfsname>\<linkpath>" DFS reference,
840-
* where <dfsname> contains non-ASCII unicode symbols.
841-
*/
842-
if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
843-
hdr->Status == STATUS_OBJECT_NAME_INVALID)
844-
rc = -EREMOTE;
837+
838+
if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
839+
rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
840+
full_path, &islink);
841+
if (rc2) {
842+
rc = rc2;
843+
goto out;
844+
}
845+
if (islink)
846+
rc = -EREMOTE;
847+
}
845848
if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
846849
(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
847850
rc = -EOPNOTSUPP;

0 commit comments

Comments
 (0)