Skip to contentSkip to conversation

cifs: fix pcchunk length type in smb2_copychunk_range

PATCH In review Pawel Witek 2 participants 6 messages May 5, 2023 – May 6, 2023 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix pcchunk length type in smb2_copychunk_range

Change type of pcchunk->Length from u32 to u64 to match smb2_copychunk_range arguments type. Fixes the problem where performing server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete copy of large files while returning -EINVAL.

---
 fs/cifs/smb2ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2ops.c +1 -1
index a81758225fcd..35c7c35882c9 100644
@@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
 		pcchunk->SourceOffset = cpu_to_le64(src_off);
 		pcchunk->TargetOffset = cpu_to_le64(dest_off);
 		pcchunk->Length =
-			cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+			cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));
 
 		/* Request server copy to target from src identified by key */
 		kfree(retbuf);
Signature · 1 line
2.40.1

A message that is not in the archive (sent off-list or not yet received): CAH2r5mszw6sayQfJqiYwTjPCqKDB7Dk-Hmtr0-Z3fXf=e3t0aQ@mail.gmail.com

#2 lore raw

PATCH 1/1 cifs: fix pcchunk length type in smb2_copychunk_range

---------- Forwarded message ---------
From: Steve French <[email protected]>
Date: Fri, May 5, 2023 at 11:47 AM
Subject: Re: [PATCH] cifs: fix pcchunk length type in smb2_copychunk_range
To: Pawel Witek <[email protected]>
Cc: <[email protected]>

since pcchunk->Length is a 32 bit field doing cpu_to_le64 seems wrong.

Perhaps one option is to split this into two lines do the minimum(u64, len, tcon->max_bytes_chunk) on one line and the cpu_to_le32 of the result on the next

What is "len" in the example you see failing?

Quoted 28 lines · Pawel Witek

Change type of pcchunk->Length from u32 to u64 to match smb2_copychunk_range arguments type. Fixes the problem where performing server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete copy of large files while returning -EINVAL.

---
 fs/cifs/smb2ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2ops.c +1 -2
index a81758225fcd..35c7c35882c9 100644
@@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
                pcchunk->SourceOffset = cpu_to_le64(src_off);
                pcchunk->TargetOffset = cpu_to_le64(dest_off);
                pcchunk->Length =
-                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+                       cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));
 
                /* Request server copy to target from src identified by key */
                kfree(retbuf);
--

2.40.1

Signature · 9 lines
Thanks,

Steve


-- 
Thanks,

Steve
#3 lore raw
In reply to a message not in the archive

I've tried to copy a 5 GB file which resulted in -EINVAL (same for larger files). After wiresharking the protocol I've observed that one packet requests ioctl with 'Transfer Length: 0', to which the server responded with an error. Some investigation showed, that this happens when len=4294967296.

Quoted 41 lines · Steve French

since pcchunk->Length is a 32 bit field doing cpu_to_le64 seems wrong.

Perhaps one option is to split this into two lines do the minimum(u64, len, tcon->max_bytes_chunk) on one line and the cpu_to_le32 of the result on the next

What is "len" in the example you see failing?

On Fri, May 5, 2023 at 10:15 AM Pawel Witek <[email protected] <mailto:[email protected]>> wrote:

    Change type of pcchunk->Length from u32 to u64 to match
    smb2_copychunk_range arguments type. Fixes the problem where performing
    server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete
    copy of large files while returning -EINVAL.

    Signed-off-by: Pawel Witek <[email protected] <mailto:[email protected]>>
    ---
     fs/cifs/smb2ops.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
    index a81758225fcd..35c7c35882c9 100644
    --- a/fs/cifs/smb2ops.c
    +++ b/fs/cifs/smb2ops.c
    @@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
                    pcchunk->SourceOffset = cpu_to_le64(src_off);
                    pcchunk->TargetOffset = cpu_to_le64(dest_off);
                    pcchunk->Length =
    -                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
    +                       cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));

                    /* Request server copy to target from src identified by key */
                    kfree(retbuf);
    -- 
    2.40.1
Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): CAH2r5mvCCY=VT9ZUkjz4c+QGZ0MjR4ggdG56QUa-apZ7eoeo0A@mail.gmail.com

#5 lore raw

Wouldn't it be safer (since pcchunk->Length is a u32 to do the following minor change to your patch

                pcchunk->Length =

- cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+ cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));

Also added Cc: stable and Fixes: tags. See attached.

Quoted 53 lines · Steve French

Good catch

Quoted 49 lines · On Fri, May 5, 2023, 14:31 Pawel Witek <[email protected]> wrote:

I've tried to copy a 5 GB file which resulted in -EINVAL (same for larger files). After wiresharking the protocol I've observed that one packet requests ioctl with 'Transfer Length: 0', to which the server responded with an error. Some investigation showed, that this happens when len=4294967296.

Quoted 41 lines · Steve French

since pcchunk->Length is a 32 bit field doing cpu_to_le64 seems wrong.

Perhaps one option is to split this into two lines do the minimum(u64, len, tcon->max_bytes_chunk) on one line and the cpu_to_le32 of the result on the next

What is "len" in the example you see failing?

On Fri, May 5, 2023 at 10:15 AM Pawel Witek <[email protected] <mailto:[email protected]>> wrote:

    Change type of pcchunk->Length from u32 to u64 to match
    smb2_copychunk_range arguments type. Fixes the problem where performing
    server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete
    copy of large files while returning -EINVAL.

    Signed-off-by: Pawel Witek <[email protected] <mailto:[email protected]>>
    ---
     fs/cifs/smb2ops.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
    index a81758225fcd..35c7c35882c9 100644
    --- a/fs/cifs/smb2ops.c
    +++ b/fs/cifs/smb2ops.c
    @@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
                    pcchunk->SourceOffset = cpu_to_le64(src_off);
                    pcchunk->TargetOffset = cpu_to_le64(dest_off);
                    pcchunk->Length =
    -                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
    +                       cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));

                    /* Request server copy to target from src identified by key */
                    kfree(retbuf);
    --
    2.40.1

--
Thanks,

Steve

Signature · 3 lines
Thanks,

Steve

From 431bbb480d05cdf5d7457c2ae417af72e5cebc82 Mon Sep 17 00:00:00 2001
From: Pawel Witek <[email protected]>
Date: Fri, 5 May 2023 17:14:59 +0200
Subject: [PATCH] cifs: fix pcchunk length type in smb2_copychunk_range

Change type of pcchunk->Length from u32 to u64 to match smb2_copychunk_range arguments type. Fixes the problem where performing server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete copy of large files while returning -EINVAL.

Fixes 9bf0c9cd4314 ("CIFS: Fix SMB2/SMB3 Copy offload support (refcopy) for large files")
---
 fs/cifs/smb2ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2ops.c +1 -1
index a81758225fcd..a295e4c2d54e 100644
@@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
 		pcchunk->SourceOffset = cpu_to_le64(src_off);
 		pcchunk->TargetOffset = cpu_to_le64(dest_off);
 		pcchunk->Length =
-			cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+			cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
 
 		/* Request server copy to target from src identified by key */
 		kfree(retbuf);
Signature · 1 line
2.34.1
#6 lore raw

I was also able to reproduce it by using xfs_io to execute copy_range on a file of exactly 4GB and verified that the patches (both versions) fix it.

Quoted 71 lines · Steve French

Wouldn't it be safer (since pcchunk->Length is a u32 to do the following minor change to your patch

                pcchunk->Length =
fs/cifs/smb2ops.c +1 -1
-                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+                       cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));

Also added Cc: stable and Fixes: tags. See attached.

Quoted 53 lines · Steve French

Good catch

Quoted 49 lines · On Fri, May 5, 2023, 14:31 Pawel Witek <[email protected]> wrote:

I've tried to copy a 5 GB file which resulted in -EINVAL (same for larger files). After wiresharking the protocol I've observed that one packet requests ioctl with 'Transfer Length: 0', to which the server responded with an error. Some investigation showed, that this happens when len=4294967296.

Quoted 41 lines · Steve French

since pcchunk->Length is a 32 bit field doing cpu_to_le64 seems wrong.

Perhaps one option is to split this into two lines do the minimum(u64, len, tcon->max_bytes_chunk) on one line and the cpu_to_le32 of the result on the next

What is "len" in the example you see failing?

On Fri, May 5, 2023 at 10:15 AM Pawel Witek <[email protected] <mailto:[email protected]>> wrote:

    Change type of pcchunk->Length from u32 to u64 to match
    smb2_copychunk_range arguments type. Fixes the problem where performing
    server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete
    copy of large files while returning -EINVAL.

    Signed-off-by: Pawel Witek <[email protected] <mailto:[email protected]>>
    ---
     fs/cifs/smb2ops.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
    index a81758225fcd..35c7c35882c9 100644
    --- a/fs/cifs/smb2ops.c
    +++ b/fs/cifs/smb2ops.c
    @@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
                    pcchunk->SourceOffset = cpu_to_le64(src_off);
                    pcchunk->TargetOffset = cpu_to_le64(dest_off);
                    pcchunk->Length =
    -                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
    +                       cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));

                    /* Request server copy to target from src identified by key */
                    kfree(retbuf);
    --
    2.40.1

--
Thanks,

Steve

--
Thanks,

Steve

Signature · 3 lines
Thanks,

Steve
#7 lore raw

You're right, that does look better and safer :)

Quoted 79 lines · Steve French

I was also able to reproduce it by using xfs_io to execute copy_range on a file of exactly 4GB and verified that the patches (both versions) fix it.

Quoted 71 lines · Steve French

Wouldn't it be safer (since pcchunk->Length is a u32 to do the following minor change to your patch

                pcchunk->Length =
fs/cifs/smb2ops.c +1 -1
-                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
+                       cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));

Also added Cc: stable and Fixes: tags. See attached.

Quoted 53 lines · Steve French

Good catch

Quoted 49 lines · On Fri, May 5, 2023, 14:31 Pawel Witek <[email protected]> wrote:

I've tried to copy a 5 GB file which resulted in -EINVAL (same for larger files). After wiresharking the protocol I've observed that one packet requests ioctl with 'Transfer Length: 0', to which the server responded with an error. Some investigation showed, that this happens when len=4294967296.

Quoted 41 lines · Steve French

since pcchunk->Length is a 32 bit field doing cpu_to_le64 seems wrong.

Perhaps one option is to split this into two lines do the minimum(u64, len, tcon->max_bytes_chunk) on one line and the cpu_to_le32 of the result on the next

What is "len" in the example you see failing?

On Fri, May 5, 2023 at 10:15 AM Pawel Witek <[email protected] <mailto:[email protected]>> wrote:

    Change type of pcchunk->Length from u32 to u64 to match
    smb2_copychunk_range arguments type. Fixes the problem where performing
    server-side copy with CIFS_IOC_COPYCHUNK_FILE ioctl resulted in incomplete
    copy of large files while returning -EINVAL.

    Signed-off-by: Pawel Witek <[email protected] <mailto:[email protected]>>
    ---
     fs/cifs/smb2ops.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
    index a81758225fcd..35c7c35882c9 100644
    --- a/fs/cifs/smb2ops.c
    +++ b/fs/cifs/smb2ops.c
    @@ -1682,7 +1682,7 @@ smb2_copychunk_range(const unsigned int xid,
                    pcchunk->SourceOffset = cpu_to_le64(src_off);
                    pcchunk->TargetOffset = cpu_to_le64(dest_off);
                    pcchunk->Length =
    -                       cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
    +                       cpu_to_le64(min_t(u64, len, tcon->max_bytes_chunk));

                    /* Request server copy to target from src identified by key */
                    kfree(retbuf);
    --
    2.40.1

--
Thanks,

Steve

--
Thanks,

Steve