linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs: refactor and clean up arguments in the reparse point parsing
@ 2019-07-06 21:45 Ronnie Sahlberg
  2019-07-06 22:50 ` Steve French
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2019-07-06 21:45 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French, Ronnie Sahlberg

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 66 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index c4047ad7b43f..4b0b14946343 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -2383,11 +2383,6 @@ parse_reparse_posix(struct reparse_posix_data *symlink_buf,
 	/* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
 	len = le16_to_cpu(symlink_buf->ReparseDataLength);
 
-	if (len + sizeof(struct reparse_data_buffer) > plen) {
-		cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
-		return -EINVAL;
-	}
-
 	if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
 		cifs_dbg(VFS, "%lld not a supported symlink type\n",
 			le64_to_cpu(symlink_buf->InodeType));
@@ -2437,22 +2432,38 @@ parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
 }
 
 static int
-parse_reparse_point(struct reparse_symlink_data_buffer *buf,
-		      u32 plen, char **target_path,
-		      struct cifs_sb_info *cifs_sb)
+parse_reparse_point(struct reparse_data_buffer *buf,
+		    u32 plen, char **target_path,
+		    struct cifs_sb_info *cifs_sb)
 {
-	/* See MS-FSCC 2.1.2 */
-	if (le32_to_cpu(buf->ReparseTag) == IO_REPARSE_TAG_NFS)
-		return parse_reparse_posix((struct reparse_posix_data *)buf,
-			plen, target_path, cifs_sb);
-	else if (le32_to_cpu(buf->ReparseTag) == IO_REPARSE_TAG_SYMLINK)
-		return parse_reparse_symlink(buf, plen, target_path,
-					cifs_sb);
+	if (plen < sizeof(struct reparse_data_buffer)) {
+		cifs_dbg(VFS, "reparse buffer is too small. Must be "
+			 "at least 8 bytes but was %d\n", plen);
+		return -EIO;
+	}
 
-	cifs_dbg(VFS, "srv returned invalid symlink buffer tag:%d\n",
-		le32_to_cpu(buf->ReparseTag));
+	if (plen < le16_to_cpu(buf->ReparseDataLength) +
+	    sizeof(struct reparse_data_buffer)) {
+		cifs_dbg(VFS, "srv returned invalid reparse buf "
+			 "length: %d\n", plen);
+		return -EIO;
+	}
 
-	return -EIO;
+	/* See MS-FSCC 2.1.2 */
+	switch (le32_to_cpu(buf->ReparseTag)) {
+	case IO_REPARSE_TAG_NFS:
+		return parse_reparse_posix(
+			(struct reparse_posix_data *)buf,
+			plen, target_path, cifs_sb);
+	case IO_REPARSE_TAG_SYMLINK:
+		return parse_reparse_symlink(
+			(struct reparse_symlink_data_buffer *)buf,
+			plen, target_path, cifs_sb);
+	default:
+		cifs_dbg(VFS, "srv returned unknown symlink buffer "
+			 "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag));
+		return -EOPNOTSUPP;
+	}
 }
 
 #define SMB2_SYMLINK_STRUCT_SIZE \
@@ -2581,23 +2592,8 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
 			goto querty_exit;
 		}
 
-		if (plen < 8) {
-			cifs_dbg(VFS, "reparse buffer is too small. Must be "
-				 "at least 8 bytes but was %d\n", plen);
-			rc = -EIO;
-			goto querty_exit;
-		}
-
-		if (plen < le16_to_cpu(reparse_buf->ReparseDataLength) + 8) {
-			cifs_dbg(VFS, "srv returned invalid reparse buf "
-				 "length: %d\n", plen);
-			rc = -EIO;
-			goto querty_exit;
-		}
-
-		rc = parse_reparse_point(
-			(struct reparse_symlink_data_buffer *)reparse_buf,
-			plen, target_path, cifs_sb);
+		rc = parse_reparse_point(reparse_buf, plen, target_path,
+					 cifs_sb);
 		goto querty_exit;
 	}
 
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cifs: refactor and clean up arguments in the reparse point parsing
  2019-07-06 21:45 [PATCH] cifs: refactor and clean up arguments in the reparse point parsing Ronnie Sahlberg
@ 2019-07-06 22:50 ` Steve French
  0 siblings, 0 replies; 2+ messages in thread
From: Steve French @ 2019-07-06 22:50 UTC (permalink / raw)
  To: Ronnie Sahlberg; +Cc: linux-cifs

tentatively merged to cifs-2.6.git for-next pending testing and
additional review/cleanup of the reparse point handling code

On Sat, Jul 6, 2019 at 4:45 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2ops.c | 66 ++++++++++++++++++++++++++-----------------------------
>  1 file changed, 31 insertions(+), 35 deletions(-)
>
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index c4047ad7b43f..4b0b14946343 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -2383,11 +2383,6 @@ parse_reparse_posix(struct reparse_posix_data *symlink_buf,
>         /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
>         len = le16_to_cpu(symlink_buf->ReparseDataLength);
>
> -       if (len + sizeof(struct reparse_data_buffer) > plen) {
> -               cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
> -               return -EINVAL;
> -       }
> -
>         if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
>                 cifs_dbg(VFS, "%lld not a supported symlink type\n",
>                         le64_to_cpu(symlink_buf->InodeType));
> @@ -2437,22 +2432,38 @@ parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
>  }
>
>  static int
> -parse_reparse_point(struct reparse_symlink_data_buffer *buf,
> -                     u32 plen, char **target_path,
> -                     struct cifs_sb_info *cifs_sb)
> +parse_reparse_point(struct reparse_data_buffer *buf,
> +                   u32 plen, char **target_path,
> +                   struct cifs_sb_info *cifs_sb)
>  {
> -       /* See MS-FSCC 2.1.2 */
> -       if (le32_to_cpu(buf->ReparseTag) == IO_REPARSE_TAG_NFS)
> -               return parse_reparse_posix((struct reparse_posix_data *)buf,
> -                       plen, target_path, cifs_sb);
> -       else if (le32_to_cpu(buf->ReparseTag) == IO_REPARSE_TAG_SYMLINK)
> -               return parse_reparse_symlink(buf, plen, target_path,
> -                                       cifs_sb);
> +       if (plen < sizeof(struct reparse_data_buffer)) {
> +               cifs_dbg(VFS, "reparse buffer is too small. Must be "
> +                        "at least 8 bytes but was %d\n", plen);
> +               return -EIO;
> +       }
>
> -       cifs_dbg(VFS, "srv returned invalid symlink buffer tag:%d\n",
> -               le32_to_cpu(buf->ReparseTag));
> +       if (plen < le16_to_cpu(buf->ReparseDataLength) +
> +           sizeof(struct reparse_data_buffer)) {
> +               cifs_dbg(VFS, "srv returned invalid reparse buf "
> +                        "length: %d\n", plen);
> +               return -EIO;
> +       }
>
> -       return -EIO;
> +       /* See MS-FSCC 2.1.2 */
> +       switch (le32_to_cpu(buf->ReparseTag)) {
> +       case IO_REPARSE_TAG_NFS:
> +               return parse_reparse_posix(
> +                       (struct reparse_posix_data *)buf,
> +                       plen, target_path, cifs_sb);
> +       case IO_REPARSE_TAG_SYMLINK:
> +               return parse_reparse_symlink(
> +                       (struct reparse_symlink_data_buffer *)buf,
> +                       plen, target_path, cifs_sb);
> +       default:
> +               cifs_dbg(VFS, "srv returned unknown symlink buffer "
> +                        "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag));
> +               return -EOPNOTSUPP;
> +       }
>  }
>
>  #define SMB2_SYMLINK_STRUCT_SIZE \
> @@ -2581,23 +2592,8 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
>                         goto querty_exit;
>                 }
>
> -               if (plen < 8) {
> -                       cifs_dbg(VFS, "reparse buffer is too small. Must be "
> -                                "at least 8 bytes but was %d\n", plen);
> -                       rc = -EIO;
> -                       goto querty_exit;
> -               }
> -
> -               if (plen < le16_to_cpu(reparse_buf->ReparseDataLength) + 8) {
> -                       cifs_dbg(VFS, "srv returned invalid reparse buf "
> -                                "length: %d\n", plen);
> -                       rc = -EIO;
> -                       goto querty_exit;
> -               }
> -
> -               rc = parse_reparse_point(
> -                       (struct reparse_symlink_data_buffer *)reparse_buf,
> -                       plen, target_path, cifs_sb);
> +               rc = parse_reparse_point(reparse_buf, plen, target_path,
> +                                        cifs_sb);
>                 goto querty_exit;
>         }
>
> --
> 2.13.6
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-06 22:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-06 21:45 [PATCH] cifs: refactor and clean up arguments in the reparse point parsing Ronnie Sahlberg
2019-07-06 22:50 ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).