ksmbd: honor byte-range locks for zero data

FSCTL_SET_ZERO_DATA changes file allocation state and must respect
byte-range locks over the affected part of the file. Check the requested
range, clipped to EOF, before issuing the fallocate operation.

Return STATUS_FILE_LOCK_CONFLICT when the range conflicts with an
existing lock. Ranges starting past EOF are left untouched by the lock
check so they continue to succeed.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
Namjae Jeon 2026-07-12 00:03:34 +09:00
parent 3c707d4b3f
commit 8b57448a14
2 changed files with 18 additions and 1 deletions

View File

@ -9781,8 +9781,13 @@ int smb2_ioctl(struct ksmbd_work *work)
ret = ksmbd_vfs_zero_data(work, fp, off, len);
ksmbd_fd_put(work, fp);
if (ret < 0)
if (ret == -EAGAIN) {
rsp->hdr.Status = STATUS_FILE_LOCK_CONFLICT;
ret = 0;
goto out;
} else if (ret < 0) {
goto out;
}
}
break;
}

View File

@ -928,6 +928,18 @@ int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
int err;
smb_break_all_levII_oplock(work, fp, 1);
if (!work->tcon->posix_extensions) {
loff_t size = i_size_read(file_inode(fp->filp));
if (off < size) {
err = check_lock_range(fp->filp, off,
min(off + len, size) - 1,
WRITE);
if (err)
return -EAGAIN;
}
}
saved_cred = override_creds(fp->filp->f_cred);
if (fp->f_ci->m_fattr & FILE_ATTRIBUTE_SPARSE_FILE_LE)
err = vfs_fallocate(fp->filp,