Skip to content

Commit 5c54a55

Browse files
namjaejeongregkh
authored andcommitted
ksmbd: fix stream write failure
[ Upstream commit 1f4bbed ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 544ff7f commit 5c54a55

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
@@ -426,10 +426,15 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
426426
ksmbd_debug(VFS, "write stream data pos : %llu, count : %zd\n",
427427
*pos, count);
428428

429+
if (*pos >= XATTR_SIZE_MAX) {
430+
pr_err("stream write position %lld is out of bounds\n", *pos);
431+
return -EINVAL;
432+
}
433+
429434
size = *pos + count;
430435
if (size > XATTR_SIZE_MAX) {
431436
size = XATTR_SIZE_MAX;
432-
count = (*pos + count) - XATTR_SIZE_MAX;
437+
count = XATTR_SIZE_MAX - *pos;
433438
}
434439

435440
v_len = ksmbd_vfs_getcasexattr(idmap,
@@ -443,13 +448,6 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
443448
goto out;
444449
}
445450

446-
if (v_len <= *pos) {
447-
pr_err("stream write position %lld is out of bounds (stream length: %zd)\n",
448-
*pos, v_len);
449-
err = -EINVAL;
450-
goto out;
451-
}
452-
453451
if (v_len < size) {
454452
wbuf = kvzalloc(size, KSMBD_DEFAULT_GFP);
455453
if (!wbuf) {

0 commit comments

Comments
 (0)