Skip to content

Commit 732f306

Browse files
committed
Merge tag '5.19-rc4-ksmbd-server-fixes' of git://git.samba.org/ksmbd
Pull ksmbd server fixes from Steve French: - seek null check (don't use f_seek op directly and blindly) - offset validation in FSCTL_SET_ZERO_DATA - fallocate fix (relates e.g. to xfstests generic/091 and 263) - two cleanup fixes - fix socket settings on some arch * tag '5.19-rc4-ksmbd-server-fixes' of git://git.samba.org/ksmbd: ksmbd: use vfs_llseek instead of dereferencing NULL ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA ksmbd: set the range of bytes to zero without extending file size in FSCTL_ZERO_DATA ksmbd: remove duplicate flag set in smb2_write ksmbd: smbd: Remove useless license text when SPDX-License-Identifier is already used ksmbd: use SOCK_NONBLOCK type for kernel_accept()
2 parents 941e3e7 + 067baa9 commit 732f306

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6490,6 +6490,7 @@ int smb2_write(struct ksmbd_work *work)
64906490
goto out;
64916491
}
64926492

6493+
ksmbd_debug(SMB, "flags %u\n", le32_to_cpu(req->Flags));
64936494
if (le32_to_cpu(req->Flags) & SMB2_WRITEFLAG_WRITE_THROUGH)
64946495
writethrough = true;
64956496

@@ -6505,10 +6506,6 @@ int smb2_write(struct ksmbd_work *work)
65056506
data_buf = (char *)(((char *)&req->hdr.ProtocolId) +
65066507
le16_to_cpu(req->DataOffset));
65076508

6508-
ksmbd_debug(SMB, "flags %u\n", le32_to_cpu(req->Flags));
6509-
if (le32_to_cpu(req->Flags) & SMB2_WRITEFLAG_WRITE_THROUGH)
6510-
writethrough = true;
6511-
65126509
ksmbd_debug(SMB, "filename %pd, offset %lld, len %zu\n",
65136510
fp->filp->f_path.dentry, offset, length);
65146511
err = ksmbd_vfs_write(work, fp, data_buf, length, &offset,
@@ -7703,7 +7700,7 @@ int smb2_ioctl(struct ksmbd_work *work)
77037700
{
77047701
struct file_zero_data_information *zero_data;
77057702
struct ksmbd_file *fp;
7706-
loff_t off, len;
7703+
loff_t off, len, bfz;
77077704

77087705
if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
77097706
ksmbd_debug(SMB,
@@ -7720,19 +7717,26 @@ int smb2_ioctl(struct ksmbd_work *work)
77207717
zero_data =
77217718
(struct file_zero_data_information *)&req->Buffer[0];
77227719

7723-
fp = ksmbd_lookup_fd_fast(work, id);
7724-
if (!fp) {
7725-
ret = -ENOENT;
7720+
off = le64_to_cpu(zero_data->FileOffset);
7721+
bfz = le64_to_cpu(zero_data->BeyondFinalZero);
7722+
if (off > bfz) {
7723+
ret = -EINVAL;
77267724
goto out;
77277725
}
77287726

7729-
off = le64_to_cpu(zero_data->FileOffset);
7730-
len = le64_to_cpu(zero_data->BeyondFinalZero) - off;
7727+
len = bfz - off;
7728+
if (len) {
7729+
fp = ksmbd_lookup_fd_fast(work, id);
7730+
if (!fp) {
7731+
ret = -ENOENT;
7732+
goto out;
7733+
}
77317734

7732-
ret = ksmbd_vfs_zero_data(work, fp, off, len);
7733-
ksmbd_fd_put(work, fp);
7734-
if (ret < 0)
7735-
goto out;
7735+
ret = ksmbd_vfs_zero_data(work, fp, off, len);
7736+
ksmbd_fd_put(work, fp);
7737+
if (ret < 0)
7738+
goto out;
7739+
}
77367740
break;
77377741
}
77387742
case FSCTL_QUERY_ALLOCATED_RANGES:

fs/ksmbd/transport_rdma.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
*
66
* Author(s): Long Li <[email protected]>,
77
* Hyunchul Lee <[email protected]>
8-
*
9-
* This program is free software; you can redistribute it and/or modify
10-
* it under the terms of the GNU General Public License as published by
11-
* the Free Software Foundation; either version 2 of the License, or
12-
* (at your option) any later version.
13-
*
14-
* This program is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17-
* the GNU General Public License for more details.
188
*/
199

2010
#define SUBMOD_NAME "smb_direct"

fs/ksmbd/transport_tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int ksmbd_kthread_fn(void *p)
230230
break;
231231
}
232232
ret = kernel_accept(iface->ksmbd_socket, &client_sk,
233-
O_NONBLOCK);
233+
SOCK_NONBLOCK);
234234
mutex_unlock(&iface->sock_release_lock);
235235
if (ret) {
236236
if (ret == -EAGAIN)

fs/ksmbd/vfs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,9 @@ int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
10151015
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
10161016
off, len);
10171017

1018-
return vfs_fallocate(fp->filp, FALLOC_FL_ZERO_RANGE, off, len);
1018+
return vfs_fallocate(fp->filp,
1019+
FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE,
1020+
off, len);
10191021
}
10201022

10211023
int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
@@ -1046,7 +1048,7 @@ int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
10461048
*out_count = 0;
10471049
end = start + length;
10481050
while (start < end && *out_count < in_count) {
1049-
extent_start = f->f_op->llseek(f, start, SEEK_DATA);
1051+
extent_start = vfs_llseek(f, start, SEEK_DATA);
10501052
if (extent_start < 0) {
10511053
if (extent_start != -ENXIO)
10521054
ret = (int)extent_start;
@@ -1056,7 +1058,7 @@ int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
10561058
if (extent_start >= end)
10571059
break;
10581060

1059-
extent_end = f->f_op->llseek(f, extent_start, SEEK_HOLE);
1061+
extent_end = vfs_llseek(f, extent_start, SEEK_HOLE);
10601062
if (extent_end < 0) {
10611063
if (extent_end != -ENXIO)
10621064
ret = (int)extent_end;

0 commit comments

Comments
 (0)