Skip to content

Commit 3162745

Browse files
committed
Merge tag '6.3-rc-smb3-client-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6
Pull more cifs updates from Steve French: - xfstest generic/208 fix (memory leak) - minor netfs fix (to address smatch warning) - a DFS fix for stable - a reconnect race fix - two multichannel fixes - RDMA (smbdirect) fix - two additional writeback fixes from David * tag '6.3-rc-smb3-client-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6: cifs: Fix memory leak in direct I/O cifs: prevent data race in cifs_reconnect_tcon() cifs: improve checking of DFS links over STATUS_OBJECT_NAME_INVALID iov: Fix netfs_extract_user_to_sg() cifs: Fix cifs_write_back_from_locked_folio() cifs: reuse cifs_match_ipaddr for comparison of dstaddr too cifs: match even the scope id for ipv6 addresses cifs: Fix an uninitialised variable cifs: Add some missing xas_retry() calls
2 parents e778361 + 7156280 commit 3162745

File tree

10 files changed

+190
-157
lines changed

10 files changed

+190
-157
lines changed

fs/cifs/cifsproto.h

Lines changed: 16 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)
@@ -684,5 +694,6 @@ static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options)
684694

685695
struct super_block *cifs_get_tcon_super(struct cifs_tcon *tcon);
686696
void cifs_put_tcon_super(struct super_block *sb);
697+
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry);
687698

688699
#endif /* _CIFSPROTO_H */

fs/cifs/cifssmb.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
7272
struct cifs_ses *ses;
7373
struct TCP_Server_Info *server;
7474
struct nls_table *nls_codepage;
75-
int retries;
7675

7776
/*
7877
* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
@@ -102,45 +101,9 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
102101
}
103102
spin_unlock(&tcon->tc_lock);
104103

105-
retries = server->nr_targets;
106-
107-
/*
108-
* Give demultiplex thread up to 10 seconds to each target available for
109-
* reconnect -- should be greater than cifs socket timeout which is 7
110-
* seconds.
111-
*/
112-
while (server->tcpStatus == CifsNeedReconnect) {
113-
rc = wait_event_interruptible_timeout(server->response_q,
114-
(server->tcpStatus != CifsNeedReconnect),
115-
10 * HZ);
116-
if (rc < 0) {
117-
cifs_dbg(FYI, "%s: aborting reconnect due to a received signal by the process\n",
118-
__func__);
119-
return -ERESTARTSYS;
120-
}
121-
122-
/* are we still trying to reconnect? */
123-
spin_lock(&server->srv_lock);
124-
if (server->tcpStatus != CifsNeedReconnect) {
125-
spin_unlock(&server->srv_lock);
126-
break;
127-
}
128-
spin_unlock(&server->srv_lock);
129-
130-
if (retries && --retries)
131-
continue;
132-
133-
/*
134-
* on "soft" mounts we wait once. Hard mounts keep
135-
* retrying until process is killed or server comes
136-
* back on-line
137-
*/
138-
if (!tcon->retry) {
139-
cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n");
140-
return -EHOSTDOWN;
141-
}
142-
retries = server->nr_targets;
143-
}
104+
rc = cifs_wait_for_server_reconnect(server, tcon->retry);
105+
if (rc)
106+
return rc;
144107

145108
spin_lock(&ses->chan_lock);
146109
if (!cifs_chan_needs_reconnect(ses, server) && !tcon->need_reconnect) {

fs/cifs/connect.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs)
12941294
case AF_INET6: {
12951295
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)srcaddr;
12961296
struct sockaddr_in6 *vaddr6 = (struct sockaddr_in6 *)rhs;
1297-
return ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr);
1297+
return (ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr)
1298+
&& saddr6->sin6_scope_id == vaddr6->sin6_scope_id);
12981299
}
12991300
default:
13001301
WARN_ON(1);
@@ -1343,32 +1344,8 @@ match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
13431344

13441345
static bool match_server_address(struct TCP_Server_Info *server, struct sockaddr *addr)
13451346
{
1346-
switch (addr->sa_family) {
1347-
case AF_INET: {
1348-
struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
1349-
struct sockaddr_in *srv_addr4 =
1350-
(struct sockaddr_in *)&server->dstaddr;
1351-
1352-
if (addr4->sin_addr.s_addr != srv_addr4->sin_addr.s_addr)
1353-
return false;
1354-
break;
1355-
}
1356-
case AF_INET6: {
1357-
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
1358-
struct sockaddr_in6 *srv_addr6 =
1359-
(struct sockaddr_in6 *)&server->dstaddr;
1360-
1361-
if (!ipv6_addr_equal(&addr6->sin6_addr,
1362-
&srv_addr6->sin6_addr))
1363-
return false;
1364-
if (addr6->sin6_scope_id != srv_addr6->sin6_scope_id)
1365-
return false;
1366-
break;
1367-
}
1368-
default:
1369-
WARN_ON(1);
1370-
return false; /* don't expect to be here */
1371-
}
1347+
if (!cifs_match_ipaddr(addr, (struct sockaddr *)&server->dstaddr))
1348+
return false;
13721349

13731350
return true;
13741351
}

fs/cifs/file.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static void cifs_undirty_folios(struct inode *inode, loff_t start, unsigned int
5252

5353
end = (start + len - 1) / PAGE_SIZE;
5454
xas_for_each_marked(&xas, folio, end, PAGECACHE_TAG_DIRTY) {
55+
if (xas_retry(&xas, folio))
56+
continue;
5557
xas_pause(&xas);
5658
rcu_read_unlock();
5759
folio_lock(folio);
@@ -81,6 +83,8 @@ void cifs_pages_written_back(struct inode *inode, loff_t start, unsigned int len
8183

8284
end = (start + len - 1) / PAGE_SIZE;
8385
xas_for_each(&xas, folio, end) {
86+
if (xas_retry(&xas, folio))
87+
continue;
8488
if (!folio_test_writeback(folio)) {
8589
WARN_ONCE(1, "bad %x @%llx page %lx %lx\n",
8690
len, start, folio_index(folio), end);
@@ -112,6 +116,8 @@ void cifs_pages_write_failed(struct inode *inode, loff_t start, unsigned int len
112116

113117
end = (start + len - 1) / PAGE_SIZE;
114118
xas_for_each(&xas, folio, end) {
119+
if (xas_retry(&xas, folio))
120+
continue;
115121
if (!folio_test_writeback(folio)) {
116122
WARN_ONCE(1, "bad %x @%llx page %lx %lx\n",
117123
len, start, folio_index(folio), end);
@@ -2839,6 +2845,7 @@ static ssize_t cifs_write_back_from_locked_folio(struct address_space *mapping,
28392845
free_xid(xid);
28402846
if (rc == 0) {
28412847
wbc->nr_to_write = count;
2848+
rc = len;
28422849
} else if (is_retryable_error(rc)) {
28432850
cifs_pages_write_redirty(inode, start, len);
28442851
} else {
@@ -3605,7 +3612,7 @@ static ssize_t __cifs_writev(
36053612

36063613
ctx->nr_pinned_pages = rc;
36073614
ctx->bv = (void *)ctx->iter.bvec;
3608-
ctx->bv_need_unpin = iov_iter_extract_will_pin(&ctx->iter);
3615+
ctx->bv_need_unpin = iov_iter_extract_will_pin(from);
36093616
} else if ((iov_iter_is_bvec(from) || iov_iter_is_kvec(from)) &&
36103617
!is_sync_kiocb(iocb)) {
36113618
/*
@@ -4141,7 +4148,7 @@ static ssize_t __cifs_readv(
41414148

41424149
ctx->nr_pinned_pages = rc;
41434150
ctx->bv = (void *)ctx->iter.bvec;
4144-
ctx->bv_need_unpin = iov_iter_extract_will_pin(&ctx->iter);
4151+
ctx->bv_need_unpin = iov_iter_extract_will_pin(to);
41454152
ctx->should_dirty = true;
41464153
} else if ((iov_iter_is_bvec(to) || iov_iter_is_kvec(to)) &&
41474154
!is_sync_kiocb(iocb)) {

fs/cifs/misc.c

Lines changed: 111 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,114 @@ 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
1269+
1270+
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry)
1271+
{
1272+
int timeout = 10;
1273+
int rc;
1274+
1275+
spin_lock(&server->srv_lock);
1276+
if (server->tcpStatus != CifsNeedReconnect) {
1277+
spin_unlock(&server->srv_lock);
1278+
return 0;
1279+
}
1280+
timeout *= server->nr_targets;
1281+
spin_unlock(&server->srv_lock);
1282+
1283+
/*
1284+
* Give demultiplex thread up to 10 seconds to each target available for
1285+
* reconnect -- should be greater than cifs socket timeout which is 7
1286+
* seconds.
1287+
*
1288+
* On "soft" mounts we wait once. Hard mounts keep retrying until
1289+
* process is killed or server comes back on-line.
1290+
*/
1291+
do {
1292+
rc = wait_event_interruptible_timeout(server->response_q,
1293+
(server->tcpStatus != CifsNeedReconnect),
1294+
timeout * HZ);
1295+
if (rc < 0) {
1296+
cifs_dbg(FYI, "%s: aborting reconnect due to received signal\n",
1297+
__func__);
1298+
return -ERESTARTSYS;
1299+
}
1300+
1301+
/* are we still trying to reconnect? */
1302+
spin_lock(&server->srv_lock);
1303+
if (server->tcpStatus != CifsNeedReconnect) {
1304+
spin_unlock(&server->srv_lock);
1305+
return 0;
1306+
}
1307+
spin_unlock(&server->srv_lock);
1308+
} while (retry);
1309+
1310+
cifs_dbg(FYI, "%s: gave up waiting on reconnect\n", __func__);
1311+
return -EHOSTDOWN;
1312+
}

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)