lkml.org 
[lkml]   [2021]   [Dec]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
SubjectRe: [PATCH 1/1] cifs: sanitize multiple delimiters in prepath
fixed various whitespace problems (pointed out by checkpatch), added
the suggested Acked-by, Fixes etc.
and tentatively merged into cifs-2.6.git for-next pending testing

See attached.

On Wed, Dec 15, 2021 at 1:49 PM Leif Sahlberg <lsahlber@redhat.com> wrote:
>
> Steve,
>
> Acked-by: me
> Steve, we should have this in stable
>
> Fixes: 24e0a1eff9e2 ("cifs: switch to new mount api")
> Cc: stable@vger.kernel.org # 5.11+
>
>
> On Wed, Dec 15, 2021 at 1:09 PM Thiago Rafael Becker <trbecker@gmail.com> wrote:
> >
> > mount.cifs can pass a device with multiple delimiters in it. This will
> > cause rename(2) to fail with ENOENT.
> >
> > BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2031200
> > Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
> > ---
> > fs/cifs/fs_context.c | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
> > diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
> > index 6a179ae753c1..4ce8a7df3a02 100644
> > --- a/fs/cifs/fs_context.c
> > +++ b/fs/cifs/fs_context.c
> > @@ -434,6 +434,34 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
> > return rc;
> > }
> >
> > +/*
> > + * remove duplicate path delimiters. Windows is supposed to do that
> > + * but there are some bugs that prevent rename from working if there are
> > + * multiple delimiters.
> > + */
> > +void sanitize_path(char *path) {
> > + char *pos = path, last = *path;
> > + unsigned int offset = 0;
> > +
> > + while(*(++pos)) {
> > + if ((*pos == '/' || *pos == '\\') && (last == '/' || last == '\\')) {
> > + offset++;
> > + continue;
> > + }
> > +
> > + last = *pos;
> > + *(pos - offset) = *pos;
> > + }
> > +
> > + pos = pos - offset - 1;
> > +
> > + /* At this point, there should be only zero or one delimiter at the end of the string */
> > + if (*pos != '/' && *pos != '\\')
> > + pos++;
> > +
> > + *pos = '\0';
> > +}
> > +
> > /*
> > * Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
> > * fields with the result. Returns 0 on success and an error otherwise
> > @@ -497,6 +525,8 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
> > if (!ctx->prepath)
> > return -ENOMEM;
> >
> > + sanitize_path(ctx->prepath);
> > +
> > return 0;
> > }
> >
> > --
> > 2.31.1
> >
>


--
Thanks,

Steve
From 859057cc97cc949b0097cd1e776a6708b367e99c Mon Sep 17 00:00:00 2001
From: Thiago Rafael Becker <trbecker@gmail.com>
Date: Wed, 15 Dec 2021 00:08:31 -0300
Subject: [PATCH] cifs: sanitize multiple delimiters in prepath

mount.cifs can pass a device with multiple delimiters in it. This will
cause rename(2) to fail with ENOENT.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2031200
Fixes: 24e0a1eff9e2 ("cifs: switch to new mount api")
Cc: stable@vger.kernel.org # 5.11+
Acked-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/cifs/fs_context.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
index 6a179ae753c1..4ce8a7df3a02 100644
--- a/fs/cifs/fs_context.c
+++ b/fs/cifs/fs_context.c
@@ -434,6 +434,34 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
return rc;
}

+/*
+ * remove duplicate path delimiters. Windows is supposed to do that
+ * but there are some bugs that prevent rename from working if there are
+ * multiple delimiters.
+ */
+void sanitize_path(char *path)
+{
+ char *pos = path, last = *path;
+ unsigned int offset = 0;
+
+ while (*(++pos)) {
+ if ((*pos == '/' || *pos == '\\') && (last == '/' || last == '\\')) {
+ offset++;
+ continue;
+ }
+ last = *pos;
+ *(pos - offset) = *pos;
+ }
+
+ pos = pos - offset - 1;
+
+ /* At this point, there should be only zero or one delimiter at the end of the string */
+ if (*pos != '/' && *pos != '\\')
+ pos++;
+
+ *pos = '\0';
+}
+
/*
* Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
* fields with the result. Returns 0 on success and an error otherwise
@@ -497,6 +525,8 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
if (!ctx->prepath)
return -ENOMEM;

+ sanitize_path(ctx->prepath);
+
return 0;
}

--
2.32.0
\
 
 \ /
  Last update: 2021-12-16 04:15    [W:0.047 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site