Skip to content

Commit 9273d6c

Browse files
committed
Merge tag '5.16-rc5-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs fixes from Steve French: "Two cifs/smb3 fixes, one fscache related, and one mount parsing related for stable" * tag '5.16-rc5-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6: cifs: sanitize multiple delimiters in prepath cifs: ignore resource_id while getting fscache super cookie
2 parents 3f667b5 + a310808 commit 9273d6c

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

fs/cifs/connect.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,13 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx)
30643064
(cifs_sb->ctx->rsize > server->ops->negotiate_rsize(tcon, ctx)))
30653065
cifs_sb->ctx->rsize = server->ops->negotiate_rsize(tcon, ctx);
30663066

3067+
/*
3068+
* The cookie is initialized from volume info returned above.
3069+
* Inside cifs_fscache_get_super_cookie it checks
3070+
* that we do not get super cookie twice.
3071+
*/
3072+
cifs_fscache_get_super_cookie(tcon);
3073+
30673074
out:
30683075
mnt_ctx->server = server;
30693076
mnt_ctx->ses = ses;

fs/cifs/fs_context.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,42 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
434434
return rc;
435435
}
436436

437+
/*
438+
* Remove duplicate path delimiters. Windows is supposed to do that
439+
* but there are some bugs that prevent rename from working if there are
440+
* multiple delimiters.
441+
*
442+
* Returns a sanitized duplicate of @path. The caller is responsible for
443+
* cleaning up the original.
444+
*/
445+
#define IS_DELIM(c) ((c) == '/' || (c) == '\\')
446+
static char *sanitize_path(char *path)
447+
{
448+
char *cursor1 = path, *cursor2 = path;
449+
450+
/* skip all prepended delimiters */
451+
while (IS_DELIM(*cursor1))
452+
cursor1++;
453+
454+
/* copy the first letter */
455+
*cursor2 = *cursor1;
456+
457+
/* copy the remainder... */
458+
while (*(cursor1++)) {
459+
/* ... skipping all duplicated delimiters */
460+
if (IS_DELIM(*cursor1) && IS_DELIM(*cursor2))
461+
continue;
462+
*(++cursor2) = *cursor1;
463+
}
464+
465+
/* if the last character is a delimiter, skip it */
466+
if (IS_DELIM(*(cursor2 - 1)))
467+
cursor2--;
468+
469+
*(cursor2) = '\0';
470+
return kstrdup(path, GFP_KERNEL);
471+
}
472+
437473
/*
438474
* Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
439475
* fields with the result. Returns 0 on success and an error otherwise
@@ -493,7 +529,7 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
493529
if (!*pos)
494530
return 0;
495531

496-
ctx->prepath = kstrdup(pos, GFP_KERNEL);
532+
ctx->prepath = sanitize_path(pos);
497533
if (!ctx->prepath)
498534
return -ENOMEM;
499535

fs/cifs/inode.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,11 +1356,6 @@ struct inode *cifs_root_iget(struct super_block *sb)
13561356
goto out;
13571357
}
13581358

1359-
#ifdef CONFIG_CIFS_FSCACHE
1360-
/* populate tcon->resource_id */
1361-
tcon->resource_id = CIFS_I(inode)->uniqueid;
1362-
#endif
1363-
13641359
if (rc && tcon->pipe) {
13651360
cifs_dbg(FYI, "ipc connection - fake read inode\n");
13661361
spin_lock(&inode->i_lock);
@@ -1375,14 +1370,6 @@ struct inode *cifs_root_iget(struct super_block *sb)
13751370
iget_failed(inode);
13761371
inode = ERR_PTR(rc);
13771372
}
1378-
1379-
/*
1380-
* The cookie is initialized from volume info returned above.
1381-
* Inside cifs_fscache_get_super_cookie it checks
1382-
* that we do not get super cookie twice.
1383-
*/
1384-
cifs_fscache_get_super_cookie(tcon);
1385-
13861373
out:
13871374
kfree(path);
13881375
free_xid(xid);

0 commit comments

Comments
 (0)