ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA
Subsystems (3)
Namjae Jeon
maintainerPATCH 1/2 ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA
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.
--- fs/ksmbd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ksmbd/vfs.c +3 -1
@@ -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,
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/2 ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA
FileOffset should not be greater than BeyondFinalZero in FSCTL_ZERO_DATA. And don't call ksmbd_vfs_zero_data() if length is zero.
--- fs/ksmbd/smb2pdu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ksmbd/smb2pdu.c +17 -10
@@ -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 :
Signature · 1 line
2.25.1
Re: [PATCH 2/2] ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA
2022년 6월 19일 (일) 오후 11:11, Namjae Jeon <[email protected]>님이 작성:
Quoted 7 lines
FileOffset should not be greater than BeyondFinalZero in
FSCTL_ZERO_DATA. And don't callksmbd_vfs_zero_data()if length is zero.Signed-off-by Namjae Jeon <[email protected]>---
Quoted 55 lines
fs/ksmbd/smb2pdu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)fs/ksmbd/smb2pdu.c +17
-11@@ -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
Signature · 2 lines
Thanks, Hyunchul
2022년 6월 19일 (일) 오후 11:11, Namjae Jeon <[email protected]>님이 작성:
Quoted 10 lines
generic/091, 263 test failed since commit
f66f8b94e7f2("cifs: when extending a file with falloc we should make files not-sparse").FSCTL_ZERO_DATAsets the range of bytes to zero without extending file size. TheVFS_FALLOCATE_FL_KEEP_SIZEflag should be used even on non-sparse files.Signed-off-by Namjae Jeon <[email protected]>---
Quoted 21 lines
fs/ksmbd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/ksmbd/vfs.c +3
-2@@ -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
Signature · 2 lines
Thanks, Hyunchul