Skip to content

Commit d19342c

Browse files
trbeckerSteve French
authored andcommitted
cifs: sanitize paths in cifs_update_super_prepath.
After a server reboot, clients are failing to move files with ENOENT. This is caused by DFS referrals containing multiple separators, which the server move call doesn't recognize. v1: Initial patch. v2: Move prototype to header. Link: https://bugzilla.redhat.com/show_bug.cgi?id=2182472 Fixes: a310808 ("cifs: sanitize multiple delimiters in prepath") Actually-Fixes: 24e0a1e ("cifs: switch to new mount api") Reviewed-by: Paulo Alcantara (SUSE) <pc@manguebit.com> Signed-off-by: Thiago Rafael Becker <tbecker@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 7e364e5 commit d19342c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

fs/cifs/fs_context.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,14 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
441441
* but there are some bugs that prevent rename from working if there are
442442
* multiple delimiters.
443443
*
444-
* Returns a sanitized duplicate of @path. The caller is responsible for
445-
* cleaning up the original.
444+
* Returns a sanitized duplicate of @path. @gfp indicates the GFP_* flags
445+
* for kstrdup.
446+
* The caller is responsible for freeing the original.
446447
*/
447448
#define IS_DELIM(c) ((c) == '/' || (c) == '\\')
448-
static char *sanitize_path(char *path)
449+
char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
449450
{
450-
char *cursor1 = path, *cursor2 = path;
451+
char *cursor1 = prepath, *cursor2 = prepath;
451452

452453
/* skip all prepended delimiters */
453454
while (IS_DELIM(*cursor1))
@@ -469,7 +470,7 @@ static char *sanitize_path(char *path)
469470
cursor2--;
470471

471472
*(cursor2) = '\0';
472-
return kstrdup(path, GFP_KERNEL);
473+
return kstrdup(prepath, gfp);
473474
}
474475

475476
/*
@@ -531,7 +532,7 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
531532
if (!*pos)
532533
return 0;
533534

534-
ctx->prepath = sanitize_path(pos);
535+
ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL);
535536
if (!ctx->prepath)
536537
return -ENOMEM;
537538

fs/cifs/fs_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,7 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
287287
*/
288288
#define SMB3_MAX_DCLOSETIMEO (1 << 30)
289289
#define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */
290+
291+
extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
292+
290293
#endif

fs/cifs/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix)
11951195
kfree(cifs_sb->prepath);
11961196

11971197
if (prefix && *prefix) {
1198-
cifs_sb->prepath = kstrdup(prefix, GFP_ATOMIC);
1198+
cifs_sb->prepath = cifs_sanitize_prepath(prefix, GFP_ATOMIC);
11991199
if (!cifs_sb->prepath)
12001200
return -ENOMEM;
12011201

0 commit comments

Comments
 (0)