diff options
| author | Thiago Rafael Becker <tbecker@redhat.com> | 2023-04-05 10:16:48 -0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-04-13 16:48:24 +0200 |
| commit | 8417eb9aaf1e022cf1cc112fcb89b62a3d426cea (patch) | |
| tree | 2b667df2c1d7cb35fad5557a923b2cda2c29ee3a | |
| parent | df23c702d11ca281dffe7ca8b9e5278f8d1132aa (diff) | |
| download | linux-8417eb9aaf1e022cf1cc112fcb89b62a3d426cea.tar.gz linux-8417eb9aaf1e022cf1cc112fcb89b62a3d426cea.tar.bz2 linux-8417eb9aaf1e022cf1cc112fcb89b62a3d426cea.zip | |
cifs: sanitize paths in cifs_update_super_prepath.
[ Upstream commit d19342c6609b67f2ba83b9eccca2777e3687f625 ]
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: a31080899d5f ("cifs: sanitize multiple delimiters in prepath")
Actually-Fixes: 24e0a1eff9e2 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rw-r--r-- | fs/cifs/fs_context.c | 13 | ||||
| -rw-r--r-- | fs/cifs/fs_context.h | 3 | ||||
| -rw-r--r-- | fs/cifs/misc.c | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c index 85ad0c9e2f8b..8455db6a26f5 100644 --- a/fs/cifs/fs_context.c +++ b/fs/cifs/fs_context.c @@ -437,13 +437,14 @@ out: * but there are some bugs that prevent rename from working if there are * multiple delimiters. * - * Returns a sanitized duplicate of @path. The caller is responsible for - * cleaning up the original. + * Returns a sanitized duplicate of @path. @gfp indicates the GFP_* flags + * for kstrdup. + * The caller is responsible for freeing the original. */ #define IS_DELIM(c) ((c) == '/' || (c) == '\\') -static char *sanitize_path(char *path) +char *cifs_sanitize_prepath(char *prepath, gfp_t gfp) { - char *cursor1 = path, *cursor2 = path; + char *cursor1 = prepath, *cursor2 = prepath; /* skip all prepended delimiters */ while (IS_DELIM(*cursor1)) @@ -465,7 +466,7 @@ static char *sanitize_path(char *path) cursor2--; *(cursor2) = '\0'; - return kstrdup(path, GFP_KERNEL); + return kstrdup(prepath, gfp); } /* @@ -527,7 +528,7 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx) if (!*pos) return 0; - ctx->prepath = sanitize_path(pos); + ctx->prepath = cifs_sanitize_prepath(pos, GFP_KERNEL); if (!ctx->prepath) return -ENOMEM; diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h index ad45256cf68e..3cf8d6235162 100644 --- a/fs/cifs/fs_context.h +++ b/fs/cifs/fs_context.h @@ -283,4 +283,7 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb); */ #define SMB3_MAX_DCLOSETIMEO (1 << 30) #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */ + +extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp); + #endif diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 3a90ee314ed7..300f5f382e43 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -1301,7 +1301,7 @@ int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix) kfree(cifs_sb->prepath); if (prefix && *prefix) { - cifs_sb->prepath = kstrdup(prefix, GFP_ATOMIC); + cifs_sb->prepath = cifs_sanitize_prepath(prefix, GFP_ATOMIC); if (!cifs_sb->prepath) return -ENOMEM; |
