All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA
@ 2022-06-19 14:11 Namjae Jeon
  2022-06-19 14:11 ` [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero " Namjae Jeon
  2022-06-20  0:09 ` [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size " Hyunchul Lee
  0 siblings, 2 replies; 4+ messages in thread
From: Namjae Jeon @ 2022-06-19 14:11 UTC (permalink / raw)
  To: linux-cifs; +Cc: smfrench, hyc.lee, senozhatsky, Namjae Jeon, stable

generic/091, 263 test failed since commit f66f8b94e7f2 ("cifs: when
extending a file with falloc we should make files not-sparse").
FSCTL_ZERO_DATA sets the range of bytes to zero without extending file
size. The VFS_FALLOCATE_FL_KEEP_SIZE flag should be used even on
non-sparse files.

Cc: stable@vger.kernel.org
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/ksmbd/vfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ksmbd/vfs.c b/fs/ksmbd/vfs.c
index dcdd07c6efff..f194bf764f9f 100644
--- a/fs/ksmbd/vfs.c
+++ b/fs/ksmbd/vfs.c
@@ -1015,7 +1015,9 @@ int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
 				     FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
 				     off, len);
 
-	return vfs_fallocate(fp->filp, FALLOC_FL_ZERO_RANGE, off, len);
+	return vfs_fallocate(fp->filp,
+			     FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE,
+			     off, len);
 }
 
 int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
-- 
2.25.1


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

* [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA
  2022-06-19 14:11 [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA Namjae Jeon
@ 2022-06-19 14:11 ` Namjae Jeon
  2022-06-20  0:10   ` Hyunchul Lee
  2022-06-20  0:09 ` [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size " Hyunchul Lee
  1 sibling, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2022-06-19 14:11 UTC (permalink / raw)
  To: linux-cifs; +Cc: smfrench, hyc.lee, senozhatsky, Namjae Jeon, stable

FileOffset should not be greater than BeyondFinalZero in FSCTL_ZERO_DATA.
And don't call ksmbd_vfs_zero_data() if length is zero.

Cc: stable@vger.kernel.org
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/ksmbd/smb2pdu.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index e35930867893..94ab1dcd80e7 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -7700,7 +7700,7 @@ int smb2_ioctl(struct ksmbd_work *work)
 	{
 		struct file_zero_data_information *zero_data;
 		struct ksmbd_file *fp;
-		loff_t off, len;
+		loff_t off, len, bfz;
 
 		if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
 			ksmbd_debug(SMB,
@@ -7717,19 +7717,26 @@ int smb2_ioctl(struct ksmbd_work *work)
 		zero_data =
 			(struct file_zero_data_information *)&req->Buffer[0];
 
-		fp = ksmbd_lookup_fd_fast(work, id);
-		if (!fp) {
-			ret = -ENOENT;
+		off = le64_to_cpu(zero_data->FileOffset);
+		bfz = le64_to_cpu(zero_data->BeyondFinalZero);
+		if (off > bfz) {
+			ret = -EINVAL;
 			goto out;
 		}
 
-		off = le64_to_cpu(zero_data->FileOffset);
-		len = le64_to_cpu(zero_data->BeyondFinalZero) - off;
+		len = bfz - off;
+		if (len) {
+			fp = ksmbd_lookup_fd_fast(work, id);
+			if (!fp) {
+				ret = -ENOENT;
+				goto out;
+			}
 
-		ret = ksmbd_vfs_zero_data(work, fp, off, len);
-		ksmbd_fd_put(work, fp);
-		if (ret < 0)
-			goto out;
+			ret = ksmbd_vfs_zero_data(work, fp, off, len);
+			ksmbd_fd_put(work, fp);
+			if (ret < 0)
+				goto out;
+		}
 		break;
 	}
 	case FSCTL_QUERY_ALLOCATED_RANGES:
-- 
2.25.1


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

* Re: [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA
  2022-06-19 14:11 [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA Namjae Jeon
  2022-06-19 14:11 ` [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero " Namjae Jeon
@ 2022-06-20  0:09 ` Hyunchul Lee
  1 sibling, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2022-06-20  0:09 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: linux-cifs, Steve French, Sergey Senozhatsky, stable

2022년 6월 19일 (일) 오후 11:11, Namjae Jeon <linkinjeon@kernel.org>님이 작성:
>
> generic/091, 263 test failed since commit f66f8b94e7f2 ("cifs: when
> extending a file with falloc we should make files not-sparse").
> FSCTL_ZERO_DATA sets the range of bytes to zero without extending file
> size. The VFS_FALLOCATE_FL_KEEP_SIZE flag should be used even on
> non-sparse files.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> ---

Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>

>  fs/ksmbd/vfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ksmbd/vfs.c b/fs/ksmbd/vfs.c
> index dcdd07c6efff..f194bf764f9f 100644
> --- a/fs/ksmbd/vfs.c
> +++ b/fs/ksmbd/vfs.c
> @@ -1015,7 +1015,9 @@ int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
>                                      FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
>                                      off, len);
>
> -       return vfs_fallocate(fp->filp, FALLOC_FL_ZERO_RANGE, off, len);
> +       return vfs_fallocate(fp->filp,
> +                            FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE,
> +                            off, len);
>  }
>
>  int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
> --
> 2.25.1
>


-- 
Thanks,
Hyunchul

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

* Re: [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA
  2022-06-19 14:11 ` [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero " Namjae Jeon
@ 2022-06-20  0:10   ` Hyunchul Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2022-06-20  0:10 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: linux-cifs, Steve French, Sergey Senozhatsky, stable

2022년 6월 19일 (일) 오후 11:11, Namjae Jeon <linkinjeon@kernel.org>님이 작성:
>
> FileOffset should not be greater than BeyondFinalZero in FSCTL_ZERO_DATA.
> And don't call ksmbd_vfs_zero_data() if length is zero.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> ---

Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>

>  fs/ksmbd/smb2pdu.c | 27 +++++++++++++++++----------
>  1 file changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index e35930867893..94ab1dcd80e7 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -7700,7 +7700,7 @@ int smb2_ioctl(struct ksmbd_work *work)
>         {
>                 struct file_zero_data_information *zero_data;
>                 struct ksmbd_file *fp;
> -               loff_t off, len;
> +               loff_t off, len, bfz;
>
>                 if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
>                         ksmbd_debug(SMB,
> @@ -7717,19 +7717,26 @@ int smb2_ioctl(struct ksmbd_work *work)
>                 zero_data =
>                         (struct file_zero_data_information *)&req->Buffer[0];
>
> -               fp = ksmbd_lookup_fd_fast(work, id);
> -               if (!fp) {
> -                       ret = -ENOENT;
> +               off = le64_to_cpu(zero_data->FileOffset);
> +               bfz = le64_to_cpu(zero_data->BeyondFinalZero);
> +               if (off > bfz) {
> +                       ret = -EINVAL;
>                         goto out;
>                 }
>
> -               off = le64_to_cpu(zero_data->FileOffset);
> -               len = le64_to_cpu(zero_data->BeyondFinalZero) - off;
> +               len = bfz - off;
> +               if (len) {
> +                       fp = ksmbd_lookup_fd_fast(work, id);
> +                       if (!fp) {
> +                               ret = -ENOENT;
> +                               goto out;
> +                       }
>
> -               ret = ksmbd_vfs_zero_data(work, fp, off, len);
> -               ksmbd_fd_put(work, fp);
> -               if (ret < 0)
> -                       goto out;
> +                       ret = ksmbd_vfs_zero_data(work, fp, off, len);
> +                       ksmbd_fd_put(work, fp);
> +                       if (ret < 0)
> +                               goto out;
> +               }
>                 break;
>         }
>         case FSCTL_QUERY_ALLOCATED_RANGES:
> --
> 2.25.1
>


-- 
Thanks,
Hyunchul

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

end of thread, other threads:[~2022-06-20  0:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-19 14:11 [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA Namjae Jeon
2022-06-19 14:11 ` [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero " Namjae Jeon
2022-06-20  0:10   ` Hyunchul Lee
2022-06-20  0:09 ` [PATCH 1/2] ksmbd: set the range of bytes to zero without extending file size " Hyunchul Lee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.