Skip to content

Commit 1f4bbed

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix stream write failure
If there is no stream data in file, v_len is zero. So, If position(*pos) is zero, stream write will fail due to stream write position validation check. This patch reorganize stream write position validation. Fixes: 0ca6df4 ("ksmbd: prevent out-of-bounds stream writes by validating *pos") Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent a5806cd commit 1f4bbed

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

fs/smb/server/vfs.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,15 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
409409
ksmbd_debug(VFS, "write stream data pos : %llu, count : %zd\n",
410410
*pos, count);
411411

412+
if (*pos >= XATTR_SIZE_MAX) {
413+
pr_err("stream write position %lld is out of bounds\n", *pos);
414+
return -EINVAL;
415+
}
416+
412417
size = *pos + count;
413418
if (size > XATTR_SIZE_MAX) {
414419
size = XATTR_SIZE_MAX;
415-
count = (*pos + count) - XATTR_SIZE_MAX;
420+
count = XATTR_SIZE_MAX - *pos;
416421
}
417422

418423
v_len = ksmbd_vfs_getcasexattr(idmap,
@@ -426,13 +431,6 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
426431
goto out;
427432
}
428433

429-
if (v_len <= *pos) {
430-
pr_err("stream write position %lld is out of bounds (stream length: %zd)\n",
431-
*pos, v_len);
432-
err = -EINVAL;
433-
goto out;
434-
}
435-
436434
if (v_len < size) {
437435
wbuf = kvzalloc(size, KSMBD_DEFAULT_GFP);
438436
if (!wbuf) {

0 commit comments

Comments
 (0)